Coverage Report - org.jaudiotagger.logging.LogFormatter
 
Classes in this File Line Coverage Branch Coverage Complexity
LogFormatter
73%
22/30
50%
3/6
3
 
 1  
 package org.jaudiotagger.logging;
 2  
 
 3  
 import java.io.PrintWriter;
 4  
 import java.io.StringWriter;
 5  
 import java.text.SimpleDateFormat;
 6  
 import java.util.Date;
 7  
 import java.util.logging.Formatter;
 8  
 import java.util.logging.LogRecord;
 9  
 
 10  
 /**
 11  
  * For Formatting log output
 12  
  * <p/>
 13  
  * <p>This is not required by jaudiotagger, but its advantage over the default formatter is that all the format for a log
 14  
  * entry is on one line, making it much easier to read. To use this formatter with your code edit loggin.properties
 15  
  * within your jre/lib folder and  modify as follows
 16  
  * e.g java.util.logging.ConsoleHandler.formatter = org.jaudiotagger.logging.LogFormatter </p>
 17  
  */
 18  
 public final class LogFormatter extends Formatter
 19  
 {
 20  156
     private boolean isObsfucated = false;
 21  
     public static final String ACTION_PERFORMED = "actionPerformed";
 22  
 
 23  
     // Line separator string.  This is the value of the line.separator
 24  
     // property at the moment that the SimpleFormatter was created.
 25  156
     private final String lineSeparator = (String) java.security.AccessController.doPrivileged(new sun.security.action.
 26  
             GetPropertyAction("line.separator"));
 27  
 
 28  156
     private final SimpleDateFormat sfDateOut = new SimpleDateFormat("dd/MM/yyyy HH.mm.ss:");
 29  156
     private final Date date = new Date();
 30  
 
 31  
     public LogFormatter()
 32  156
     {
 33  
 
 34  156
     }
 35  
 
 36  
     public final String format(final LogRecord record)
 37  
     {
 38  34552
         final StringBuffer sb = new StringBuffer();
 39  
 
 40  34552
         date.setTime(record.getMillis());
 41  
 
 42  34552
         sb.append(sfDateOut.format(date));
 43  
 
 44  34552
         String recordName = null;
 45  
 
 46  34552
         if (record.getSourceClassName() != null)
 47  
         {
 48  34552
             recordName = record.getSourceClassName() + ":" + record.getSourceMethodName();
 49  
         }
 50  
         else
 51  
         {
 52  0
             recordName = record.getLoggerName() + ":";
 53  
         }
 54  34552
         if (recordName != null)
 55  
         {
 56  34552
             sb.append(recordName);
 57  34552
             sb.append(":");
 58  
         }
 59  34552
         final String message = formatMessage(record);
 60  34552
         sb.append(record.getLevel().getLocalizedName());
 61  34552
         sb.append(": ");
 62  34552
         sb.append(message);
 63  34552
         sb.append(lineSeparator);
 64  
 
 65  34552
         if (record.getThrown() != null)
 66  
         {
 67  
             try
 68  
             {
 69  0
                 final StringWriter sw = new StringWriter();
 70  0
                 final PrintWriter pw = new PrintWriter(sw);
 71  0
                 record.getThrown().printStackTrace(pw);
 72  0
                 pw.close();
 73  0
                 sb.append(sw.toString());
 74  
             }
 75  0
             catch (Exception ex)
 76  
             {
 77  0
             }
 78  
         }
 79  34552
         return sb.toString();
 80  
     }
 81  
 
 82  
     public static final String IDENT = "$Id: LogFormatter.java,v 1.11 2008/07/21 10:46:14 paultaylor Exp $";
 83  
 }
 84