01: /*
02: $Id: CustomLogger.java,v 1.4 2005/02/14 12:06:22 vauclair Exp $
03:
04: Copyright (C) 2002-2005 Sebastien Vauclair
05:
06: This file is part of Extensible Java Profiler.
07:
08: Extensible Java Profiler is free software; you can redistribute it and/or
09: modify it under the terms of the GNU General Public License as published by
10: the Free Software Foundation; either version 2 of the License, or
11: (at your option) any later version.
12:
13: Extensible Java Profiler is distributed in the hope that it will be useful,
14: but WITHOUT ANY WARRANTY; without even the implied warranty of
15: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16: GNU General Public License for more details.
17:
18: You should have received a copy of the GNU General Public License
19: along with Extensible Java Profiler; if not, write to the Free Software
20: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21: */
22:
23: package ejp.presenter.api.util;
24:
25: import java.util.logging.Handler;
26: import java.util.logging.Level;
27: import java.util.logging.LogManager;
28: import java.util.logging.Logger;
29:
30: /**
31: * Logger configured to display messages to the software's Log frame.
32: *
33: * To use it, make methods calls to instance <code>CustomLogger.INSTANCE</code>.
34: *
35: * @author Sebastien Vauclair
36: * @version <code>$Revision: 1.4 $<br>$Date: 2005/02/14 12:06:22 $</code>
37: */
38: public abstract class CustomLogger {
39: /**
40: * Single <code>Logger</code> instance.
41: */
42: public static final Logger INSTANCE = Logger.getLogger("profiler");
43:
44: static {
45: System.setProperty("java.util.logging.config.file",
46: "../etc/logging.properties");
47: try {
48: LogManager.getLogManager().readConfiguration();
49: } catch (Exception e) {
50: // set logger level
51: INSTANCE.setLevel(Level.ALL);
52:
53: // find root logger
54: Logger rootLogger;
55: Logger currentLogger = INSTANCE;
56: do {
57: rootLogger = currentLogger;
58: currentLogger = currentLogger.getParent();
59: } while (currentLogger != null);
60:
61: // set level of all root's handlers
62: final Handler[] handlers = rootLogger.getHandlers();
63: for (int i = 0; i < handlers.length; i++)
64: handlers[i].setLevel(Level.ALL);
65:
66: INSTANCE
67: .warning("Unable to read log manager configuration - "
68: + e);
69: }
70: }
71: }
|