| | |
| | | package org.opends.server.loggers.debug; |
| | | |
| | | import org.opends.server.api.ProtocolElement; |
| | | import org.opends.server.api.LogPublisher; |
| | | import org.opends.server.loggers.Logger; |
| | | import org.opends.server.loggers.LogLevel; |
| | | import org.opends.server.loggers.LogRecord; |
| | | |
| | | import java.util.Map; |
| | | import java.util.HashMap; |
| | |
| | | */ |
| | | public class DebugLogger extends Logger |
| | | { |
| | | /** |
| | | * Whether the debug logger is enabled or disabled. |
| | | */ |
| | | static boolean enabled = false; |
| | | private static DebugLogger logger = null; |
| | | static boolean staticEnabled = false; |
| | | |
| | | private Map<String, Tracer> classTracers; |
| | | private TraceConfiguration config; |
| | | |
| | | private DebugLogger() |
| | | private DebugConfiguration configuration; |
| | | |
| | | private DebugLogger(DebugConfiguration config) |
| | | { |
| | | super(new DebugErrorHandler()); |
| | | |
| | | super(config); |
| | | configuration = config; |
| | | classTracers = new HashMap<String, Tracer>(); |
| | | config = new TraceConfiguration(); |
| | | staticEnabled = enabled; |
| | | } |
| | | |
| | | /** |
| | | * Publish a record to all the registered publishers. |
| | | * |
| | | * @param record The log record to publish. |
| | | */ |
| | | protected void publishRecord(LogRecord record) |
| | | { |
| | | for(LogPublisher p : publishers) |
| | | { |
| | | p.publish(record, handler); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Obtain the trace logger singleton. |
| | |
| | | public static synchronized DebugLogger getLogger() |
| | | { |
| | | if (logger == null) { |
| | | logger= new DebugLogger(); |
| | | /** |
| | | * The debug logger is being intialized for the first time. |
| | | * Bootstrap the debug logger when the server first starts up so |
| | | * all debug messages are log from the first initialization of a |
| | | * server class. |
| | | */ |
| | | logger= new DebugLogger(DebugConfiguration.getStartupConfiguration()); |
| | | } |
| | | |
| | | return logger; |
| | | } |
| | | |
| | | /** |
| | | * Enable or disable the debug logger. |
| | | * |
| | | * @param enable if the debug logger should be enabled. |
| | | */ |
| | | public static void enabled(boolean enable) |
| | | { |
| | | enabled = enable; |
| | | } |
| | | |
| | | /** |
| | | * Obtain the status of this logger singleton. |
| | | * |
| | | * @return the status of this logger. |
| | | */ |
| | | public static boolean debugEnabled() |
| | | { |
| | | return enabled; |
| | | return staticEnabled; |
| | | } |
| | | |
| | | /** |
| | |
| | | Tracer traceLogger = classTracers.get(className); |
| | | if (traceLogger == null) { |
| | | classTracers.put(className, tracer); |
| | | tracer.updateSettings(this.configuration); |
| | | } |
| | | else |
| | | { |
| | | //TODO: handle dup case! |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Retrives the current tracing configuration of the debug logger. |
| | | * |
| | | * @return the current tracing configuration of the debug logger. |
| | | */ |
| | | protected TraceConfiguration getConfiguration() |
| | | { |
| | | return config; |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * @param config the new configuration to apply. |
| | | */ |
| | | public void updateConfiguration(TraceConfiguration config) |
| | | public synchronized void updateConfiguration(DebugConfiguration config) |
| | | { |
| | | this.config = config; |
| | | super.updateConfiguration(config); |
| | | staticEnabled = enabled; |
| | | |
| | | for(Tracer tracer : classTracers.values()) |
| | | { |
| | | tracer.updateSettings(); |
| | | tracer.updateSettings(config); |
| | | } |
| | | |
| | | this.configuration = config; |
| | | } |
| | | |
| | | /** |