KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > phoenix > components > manager > MX4JLoggerAdapter


1 /*
2  * Copyright (C) The Apache Software Foundation. All rights reserved.
3  *
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE.txt file.
7  */

8 package org.apache.avalon.phoenix.components.manager;
9
10 import mx4j.log.Logger;
11
12 /**
13  * A class to pipe MX4J's own logger to the one Phoenix wants to use.
14  */

15 public class MX4JLoggerAdapter extends Logger
16 {
17     private static org.apache.avalon.framework.logger.Logger avalonLogger;
18
19     /**
20      * This is really bad. A static way of introducing a logger to a tool.
21      * @param logger the Avalon logger.
22      */

23     public static void setLogger(org.apache.avalon.framework.logger.Logger logger)
24     {
25         avalonLogger = logger;
26     }
27
28     /**
29      * This overides the method in the super class to actually deliver Avalon
30      * Logging to MX4J
31      *
32      * @param level the debug/warn/error level.
33      * @param message the message to log.
34      * @param throwable a message that may be sent.
35      */

36     protected void log(int level, Object JavaDoc message, Throwable JavaDoc throwable)
37     {
38         switch (level)
39         {
40             case mx4j.log.Logger.DEBUG:
41                 avalonLogger.debug(message.toString(), throwable);
42                 break;
43             case mx4j.log.Logger.ERROR:
44                 avalonLogger.error(message.toString(), throwable);
45                 break;
46             case mx4j.log.Logger.FATAL:
47                 avalonLogger.fatalError(message.toString(), throwable);
48                 break;
49             case mx4j.log.Logger.INFO:
50                 avalonLogger.info(message.toString(), throwable);
51                 break;
52             case mx4j.log.Logger.TRACE:
53                 avalonLogger.debug(message.toString(), throwable);
54                 break;
55             case mx4j.log.Logger.WARN:
56                 avalonLogger.warn(message.toString(), throwable);
57                 break;
58         }
59     }
60 }
61
Popular Tags