forked from I2P_Developers/i2p.i2p
make jetty use I2P logging
This commit is contained in:
@@ -114,7 +114,7 @@
|
||||
debug="true" source="1.5" target="1.5"
|
||||
destdir="./build/obj"
|
||||
includeAntRuntime="false"
|
||||
classpath="./jettylib/commons-logging.jar:./jettylib/javax.servlet.jar:./jettylib/org.mortbay.jetty.jar:./jettylib/jetty-util.jar" >
|
||||
classpath="../../core/java/build/i2p.jar:./jettylib/commons-logging.jar:./jettylib/javax.servlet.jar:./jettylib/org.mortbay.jetty.jar:./jettylib/jetty-util.jar" >
|
||||
<compilerarg line="${javac.compilerargs}" />
|
||||
</javac>
|
||||
</target>
|
||||
|
168
apps/jetty/java/src/net/i2p/jetty/I2PLogger.java
Normal file
168
apps/jetty/java/src/net/i2p/jetty/I2PLogger.java
Normal file
@@ -0,0 +1,168 @@
|
||||
// ========================================================================
|
||||
// Copyright 2004-2005 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
// ========================================================================
|
||||
|
||||
package net.i2p.jetty;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.util.Log;
|
||||
|
||||
import org.mortbay.jetty.Server;
|
||||
import org.mortbay.log.Logger;
|
||||
|
||||
/**
|
||||
* Modified from Jetty 6.1.26 StdErrLog.java and Slf4jLog.java
|
||||
*
|
||||
* Usage: org.mortbay.log.Log.setLog(new I2PLogger(ctx));
|
||||
*
|
||||
* @since Jetty 6
|
||||
*/
|
||||
public class I2PLogger implements Logger
|
||||
{
|
||||
private final Log _log;
|
||||
|
||||
StringBuilder _buffer = new StringBuilder();
|
||||
|
||||
public I2PLogger(I2PAppContext ctx)
|
||||
{
|
||||
_log = ctx.logManager().getLog(Server.class);
|
||||
if (System.getProperty("DEBUG") != null)
|
||||
setDebugEnabled(true);
|
||||
}
|
||||
|
||||
public boolean isDebugEnabled()
|
||||
{
|
||||
return _log.shouldLog(Log.DEBUG);
|
||||
}
|
||||
|
||||
public void setDebugEnabled(boolean enabled)
|
||||
{
|
||||
if (enabled)
|
||||
_log.setMinimumPriority(Log.DEBUG);
|
||||
else
|
||||
// LogManager.getDefaultLimit() returns a String, not worth it
|
||||
_log.setMinimumPriority(Log.ERROR);
|
||||
}
|
||||
|
||||
public void info(String msg,Object arg0, Object arg1)
|
||||
{
|
||||
if (arg0 == null && arg1 == null) {
|
||||
_log.info(msg);
|
||||
} else if (_log.shouldLog(Log.INFO)) {
|
||||
synchronized(_buffer) {
|
||||
format(msg,arg0,arg1);
|
||||
_log.info(_buffer.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void debug(String msg,Throwable th)
|
||||
{
|
||||
_log.debug(msg,th);
|
||||
}
|
||||
|
||||
public void debug(String msg,Object arg0, Object arg1)
|
||||
{
|
||||
if (arg0 == null && arg1 == null) {
|
||||
_log.debug(msg);
|
||||
} else if (_log.shouldLog(Log.DEBUG)) {
|
||||
synchronized(_buffer) {
|
||||
format(msg,arg0,arg1);
|
||||
_log.debug(_buffer.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void warn(String msg,Object arg0, Object arg1)
|
||||
{
|
||||
if (arg0 == null && arg1 == null) {
|
||||
_log.warn(msg);
|
||||
} else if (_log.shouldLog(Log.WARN)) {
|
||||
synchronized(_buffer) {
|
||||
format(msg,arg0,arg1);
|
||||
_log.warn(_buffer.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void warn(String msg, Throwable th)
|
||||
{
|
||||
if (th instanceof RuntimeException || th instanceof Error)
|
||||
_log.error(msg, th);
|
||||
else
|
||||
_log.warn(msg,th);
|
||||
}
|
||||
|
||||
private void format(String msg, Object arg0, Object arg1)
|
||||
{
|
||||
int i0=msg==null?-1:msg.indexOf("{}");
|
||||
int i1=i0<0?-1:msg.indexOf("{}",i0+2);
|
||||
|
||||
if (i0>=0)
|
||||
{
|
||||
format(msg.substring(0,i0));
|
||||
format(String.valueOf(arg0==null?"null":arg0));
|
||||
|
||||
if (i1>=0)
|
||||
{
|
||||
format(msg.substring(i0+2,i1));
|
||||
format(String.valueOf(arg1==null?"null":arg1));
|
||||
format(msg.substring(i1+2));
|
||||
}
|
||||
else
|
||||
{
|
||||
format(msg.substring(i0+2));
|
||||
if (arg1!=null)
|
||||
{
|
||||
_buffer.append(' ');
|
||||
format(String.valueOf(arg1));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
format(msg);
|
||||
if (arg0!=null)
|
||||
{
|
||||
_buffer.append(' ');
|
||||
format(String.valueOf(arg0));
|
||||
}
|
||||
if (arg1!=null)
|
||||
{
|
||||
_buffer.append(' ');
|
||||
format(String.valueOf(arg1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void format(String msg)
|
||||
{
|
||||
if (msg == null)
|
||||
_buffer.append("null");
|
||||
else
|
||||
_buffer.append(msg);
|
||||
}
|
||||
|
||||
public Logger getLogger(String name)
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "I2PLogger";
|
||||
}
|
||||
|
||||
|
||||
}
|
@@ -26,6 +26,7 @@
|
||||
<pathelement location="../../jetty/jettylib/jetty-threadpool.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jsp-api.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jetty-i2p.jar" />
|
||||
<pathelement location="../../systray/java/build/obj" />
|
||||
<pathelement location="../../systray/java/lib/systray4j.jar" />
|
||||
<pathelement location="../../desktopgui/build" />
|
||||
@@ -62,6 +63,7 @@
|
||||
<pathelement location="../../jetty/jettylib/jetty-threadpool.jar" />
|
||||
<pathelement location="../../jetty/jettylib/javax.servlet.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jsp-api.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jetty-i2p.jar" />
|
||||
<pathelement location="../../systray/java/build/systray.jar" />
|
||||
<pathelement location="../../systray/java/lib/systray4j.jar" />
|
||||
<pathelement location="../../desktopgui/dist/desktopgui.jar" />
|
||||
@@ -243,6 +245,7 @@
|
||||
<pathelement location="../../jetty/jettylib/commons-el.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jsp-api.jar" />
|
||||
<pathelement location="../../jetty/jettylib/ant.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jetty-i2p.jar" />
|
||||
<pathelement location="../../systray/java/build/obj" />
|
||||
<pathelement location="../../systray/java/lib/systray4j.jar" />
|
||||
<pathelement location="../../desktopgui/dist/desktopgui.jar" />
|
||||
@@ -279,6 +282,7 @@
|
||||
<pathelement location="../../jetty/jettylib/jetty-sslengine.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jetty-threadpool.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jsp-api.jar" />
|
||||
<pathelement location="../../jetty/jettylib/jetty-i2p.jar" />
|
||||
<pathelement location="../../systray/java/build/obj" />
|
||||
<pathelement location="../../systray/java/lib/systray4j.jar" />
|
||||
<pathelement location="../../desktopgui/dist/desktopgui.jar" />
|
||||
|
@@ -20,6 +20,7 @@ import net.i2p.apps.systray.SysTray;
|
||||
import net.i2p.data.Base32;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.desktopgui.Main;
|
||||
import net.i2p.jetty.I2PLogger;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.FileUtil;
|
||||
import net.i2p.util.I2PAppThread;
|
||||
@@ -49,6 +50,7 @@ import org.mortbay.jetty.servlet.ServletHandler;
|
||||
import org.mortbay.jetty.servlet.ServletHolder;
|
||||
import org.mortbay.jetty.servlet.SessionHandler;
|
||||
import org.mortbay.jetty.webapp.WebAppContext;
|
||||
import org.mortbay.log.Log;
|
||||
import org.mortbay.thread.QueuedThreadPool;
|
||||
import org.mortbay.thread.concurrent.ThreadPool;
|
||||
|
||||
@@ -219,6 +221,7 @@ public class RouterConsoleRunner {
|
||||
if (!workDirCreated)
|
||||
System.err.println("ERROR: Unable to create Jetty temporary work directory");
|
||||
|
||||
Log.setLog(new I2PLogger(I2PAppContext.getGlobalContext()));
|
||||
// so Jetty can find WebAppConfiguration
|
||||
System.setProperty("jetty.class.path", I2PAppContext.getGlobalContext().getBaseDir() + "/lib/routerconsole.jar");
|
||||
_server = new Server();
|
||||
|
Reference in New Issue
Block a user