2 // ========================================================================
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd.
4 // ------------------------------------------------------------------------
5 // All rights reserved. This program and the accompanying materials
6 // are made available under the terms of the Eclipse Public License v1.0
7 // and Apache License v2.0 which accompanies this distribution.
9 // The Eclipse Public License is available at
10 // http://www.eclipse.org/legal/epl-v10.html
12 // The Apache License v2.0 is available at
13 // http://www.opensource.org/licenses/apache2.0.php
15 // You may elect to redistribute this code under either of these licenses.
16 // ========================================================================
19 package org.eclipse.jetty.util.log;
21 import java.lang.reflect.Method;
26 public class LoggerLog extends AbstractLogger
28 private final Object _logger;
29 private final Method _debugMT;
30 private final Method _debugMAA;
31 private final Method _infoMT;
32 private final Method _infoMAA;
33 private final Method _warnMT;
34 private final Method _warnMAA;
35 private final Method _setDebugEnabledE;
36 private final Method _getLoggerN;
37 private final Method _getName;
38 private volatile boolean _debug;
40 public LoggerLog(Object logger)
45 Class<?> lc = logger.getClass();
46 _debugMT = lc.getMethod("debug", new Class[]{String.class, Throwable.class});
47 _debugMAA = lc.getMethod("debug", new Class[]{String.class, Object[].class});
48 _infoMT = lc.getMethod("info", new Class[]{String.class, Throwable.class});
49 _infoMAA = lc.getMethod("info", new Class[]{String.class, Object[].class});
50 _warnMT = lc.getMethod("warn", new Class[]{String.class, Throwable.class});
51 _warnMAA = lc.getMethod("warn", new Class[]{String.class, Object[].class});
52 Method _isDebugEnabled = lc.getMethod("isDebugEnabled");
53 _setDebugEnabledE = lc.getMethod("setDebugEnabled", new Class[]{Boolean.TYPE});
54 _getLoggerN = lc.getMethod("getLogger", new Class[]{String.class});
55 _getName = lc.getMethod("getName");
57 _debug = (Boolean)_isDebugEnabled.invoke(_logger);
61 throw new IllegalStateException(x);
65 public String getName()
69 return (String)_getName.invoke(_logger);
78 public void warn(String msg, Object... args)
82 _warnMAA.invoke(_logger, args);
90 public void warn(Throwable thrown)
95 public void warn(String msg, Throwable thrown)
99 _warnMT.invoke(_logger, msg, thrown);
107 public void info(String msg, Object... args)
111 _infoMAA.invoke(_logger, args);
119 public void info(Throwable thrown)
124 public void info(String msg, Throwable thrown)
128 _infoMT.invoke(_logger, msg, thrown);
136 public boolean isDebugEnabled()
141 public void setDebugEnabled(boolean enabled)
145 _setDebugEnabledE.invoke(_logger, enabled);
155 public void debug(String msg, Object... args)
162 _debugMAA.invoke(_logger, args);
170 public void debug(Throwable thrown)
175 public void debug(String msg, Throwable th)
182 _debugMT.invoke(_logger, msg, th);
190 public void debug(String msg, long value)
197 _debugMAA.invoke(_logger, new Object[]{new Long(value)});
205 public void ignore(Throwable ignored)
209 warn(Log.IGNORED, ignored);
214 * Create a Child Logger of this Logger.
216 protected Logger newLogger(String fullname)
220 Object logger=_getLoggerN.invoke(_logger, fullname);
221 return new LoggerLog(logger);