Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/fluidsynth/api/CustomLogFormatter.java


1   /*
2    * Copyright (C) 2003 Ken Ellinwood.
3    * 
4    * This file is part of FluidGUI.
5    * 
6    * FluidGUI is free software; you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation; either version 2 of the License, or
9    * (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU General Public License for more details.
15   * 
16   * You should have received a copy of the GNU General Public License
17   * along with this program; if not, write to the Free Software
18   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20  
21  package org.fluidsynth.api;
22  
23  import java.io.*;
24  import java.text.*;
25  import java.util.logging.*;
26  
27  /** Log formatter that produces simple, single line, log entries. */
28  public class CustomLogFormatter extends Formatter
29  {
30      java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss z");
31      
32      public String format( LogRecord rec)
33      {
34          StringBuffer result = new StringBuffer( );
35          result.append( sdf.format( new java.util.Date()));
36          result.append("   ");
37          result.append( rec.getLevel());
38          if (rec.getSourceClassName() != null) {
39              result.append( "   ");
40              result.append( rec.getSourceClassName());
41          }
42          result.append( "   ");
43          result.append( formatMessage( rec));
44          result.append( "\n");
45  
46          if (rec.getThrown() != null) {
47              try {
48                  StringWriter sw = new StringWriter();
49                  PrintWriter pw = new PrintWriter( sw);
50                  rec.getThrown().printStackTrace( pw);
51                  pw.flush();
52                  result.append( sw.getBuffer());
53                  pw.close();
54              }
55              catch( Exception e) {
56                  System.err.println("Exception from org.fluidsynth.api.CustomLogFormatter");
57                  e.printStackTrace( System.err);
58                  rec.getThrown().printStackTrace( System.err);
59              }
60          }
61          return result.toString();
62      }
63  }
64