Coverage Report - org.apache.commons.transaction.util.PrintWriterLogger
 
Classes in this File Line Coverage Branch Coverage Complexity
PrintWriterLogger
48%
16/33
0%
0/6
1.214
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one or more
 3  
  * contributor license agreements.  See the NOTICE file distributed with
 4  
  * this work for additional information regarding copyright ownership.
 5  
  * The ASF licenses this file to You under the Apache License, Version 2.0
 6  
  * (the "License"); you may not use this file except in compliance with
 7  
  * the License.  You may obtain a copy of the License at
 8  
  *
 9  
  *     http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.apache.commons.transaction.util;
 18  
 
 19  
 import java.io.PrintWriter;
 20  
 
 21  
 /**
 22  
  * Logger implementation that logs into a pring writer like the one
 23  
  * passed in JCA.
 24  
  *
 25  
  * @version $Id: PrintWriterLogger.java 493628 2007-01-07 01:42:48Z joerg $
 26  
  */
 27  
 public class PrintWriterLogger implements LoggerFacade {
 28  
 
 29  
     protected PrintWriter printWriter;
 30  
     protected String name;
 31  
     protected boolean debug;
 32  
 
 33  17
     public PrintWriterLogger(PrintWriter printWriter, String name, boolean debug) {
 34  17
         this.printWriter = printWriter;
 35  17
         this.name = name;
 36  17
         this.debug = debug;
 37  17
     }
 38  
 
 39  
     public LoggerFacade createLogger(String newName) {
 40  9
         return new PrintWriterLogger(this.printWriter, newName, this.debug);
 41  
     }
 42  
 
 43  
     public void logInfo(String message) {
 44  10
         log("INFO", message);
 45  10
     }
 46  
 
 47  
     public void logFine(String message) {
 48  0
         if (debug)
 49  0
         log("FINE", message);
 50  0
     }
 51  
 
 52  
     public boolean isFineEnabled() {
 53  1353
         return debug;
 54  
     }
 55  
 
 56  
     public void logFiner(String message) {
 57  0
         if (debug)
 58  0
             log("FINER", message);
 59  0
     }
 60  
 
 61  
     public boolean isFinerEnabled() {
 62  9002
         return debug;
 63  
     }
 64  
 
 65  
     public void logFinest(String message) {
 66  0
         if (debug)
 67  0
             log("FINEST", message);
 68  0
     }
 69  
 
 70  
     public boolean isFinestEnabled() {
 71  3108
         return debug;
 72  
     }
 73  
 
 74  
     public void logWarning(String message) {
 75  29
         log("WARNING", message);
 76  29
     }
 77  
 
 78  
     public void logWarning(String message, Throwable t) {
 79  0
         log("WARNING", message);
 80  0
         t.printStackTrace(printWriter);
 81  0
     }
 82  
 
 83  
     public void logSevere(String message) {
 84  0
         log("SEVERE", message);
 85  0
     }
 86  
 
 87  
     public void logSevere(String message, Throwable t) {
 88  0
         log("SEVERE", message);
 89  0
         t.printStackTrace(printWriter);
 90  0
     }
 91  
 
 92  
     protected void log(String level, String message) {
 93  39
         printWriter.write(name + "(" + level + ":" + message);
 94  39
         printWriter.flush();
 95  39
     }
 96  
 }