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

Quick Search    Search Deep

Source code: org/fluidsynth/api/Log.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  /*
22   * Log.java
23   *
24   * Created on July 24, 2003, 1:33 PM
25   */
26  
27  package org.fluidsynth.api;
28  
29  import java.util.logging.*;
30  
31  /** Methods logging output from the application.  Planned use is as follows:<br>
32      <ul>
33      <li>use severe() as appropriate (report unhandled exceptions, etc.)</li>
34      <li>use info() for messages to be displayed in progress bars, status bars, etc.</li>
35      <li>use config(), fine(), finer() and finest() for debug level output.</li>
36      </ul>
37      <br>
38      Example: <tt>Log.fine( this, "debug me");</tt><p>
39      
40      The default config file will set the level at INFO, and the user
41      will only see warn() and severe() messages on the console unless
42      the logging.properties file in our lib directory is modified to
43      set the level lower.  The {@link Status} class registers as a
44      handler of INFO level messages, and this is how the info() level
45      messages get into progress bars, etc.  <p>
46      
47      The logger created by this class uses the resource bundle
48      <tt>org.fluidsynth.gui.i18n.logBundle</tt> to map message keys to
49      internationalized strings.
50   */
51  public class Log
52  {
53  
54      private static Log me = new Log();
55      
56      private Logger logger;
57      
58      /** Return the singleon instance of this class.  Normally only the
59       *  static methods of this class will be called, so this might not
60       *  be of much use. */
61      public static final Log onlyInstance()
62      {
63          return me;
64      }
65  
66      /** Get the logger used by this class. */
67      public final Logger getLogger()
68      {
69          return logger;
70      }
71      
72      /** Creates new Log */
73      private Log() {
74          logger = Logger.getLogger("org.fluidsynth.api.log", "org.fluidsynth.gui.i18n.logBundle");
75      }
76  
77      private static void _log( Level level, Object originator, String message, Throwable thrown)
78      {
79          String className = (originator instanceof Class) ?
80              ((Class)originator).getName() : originator.getClass().getName();
81  
82          Logger l = onlyInstance().getLogger();
83  
84          l.logp(level, className, null, message, thrown);
85      }
86  
87      /** Use this to report serious problems the doesn't handle gracefully. */
88      public static void severe( Object originator, String message, Throwable thrown)
89      {
90          _log( Level.SEVERE, originator, message, thrown);
91      }
92      
93      /** Use this to issue warnings. */
94      public static void warning( Object originator, String message)
95      {
96          _log( Level.WARNING, originator, message, null);
97      }
98      
99      /** Use this one to create messages for status panels, progress bars, etc. */
100     public static void info( Object originator, String message)
101     {
102         _log( Level.INFO, originator, message, null);
103     }
104     
105     /** Use this one to log debug output. */
106     public static void config( Object originator, String message)
107     {
108         _log( Level.CONFIG, originator, message, null);
109     }
110     
111     /** Use this one to log debug output. */
112     public static void fine( Object originator, String message)
113     {
114         _log( Level.FINE, originator, message, null);
115     }
116     
117     /** Use this one to log debug output. */
118     public static void finer( Object originator, String message)
119     {
120         _log( Level.FINER, originator, message, null);
121     }
122     
123     /** Use this one to log debug output. */
124     public static void finest( Object originator, String message)
125     {
126         _log( Level.FINEST, originator, message, null);
127     }
128     
129     /** Test routine. */
130     public static void main( String[] args)
131     {
132         try
133         {
134             finest( Log.class, "finest.test.message");
135             finer( Log.class, "finer.test.message");
136             fine( Log.class, "fine.test.message");
137             config( Log.class, "config.test.message");
138             info( Log.class, "info.test.message");
139             warning( Log.class, "warning.test.message");
140             severe( Log.class, "severe.test.message", null);
141             severe( Log.class, "severe.test.message",
142                     new IllegalArgumentException("This exception is thrown intentionally for the purpose of testing."));
143             
144         }
145         catch (Exception e) {
146             e.printStackTrace();
147         }
148 
149     }
150 }