Setting up (or turning off) Jetty 7 Logging programmatically

Jetty, for all of its words of wisdom, namely “Don’t deploy your application in Jetty, deploy Jetty in your application.”, it seems to want to basically become a new Tomcat server. For instructions on how to do anything in Jetty, it will regale you with how you put it in some xml configuration file and all will be well.

Except, all is not well!

That is not embedding Jetty in your application, that is deploying your application with Jetty – very upsetting.

Not only that, to figure out how to turn off logging is quite a chore. So, here you go.

BEFORE you create a new server, you need to register your logging class using the cryptic sounding:


org.eclipse.jetty.util.log.Log.setLog(new CmsLogger());
this.server = new Server(port);

So, you need to create a new Logger that implements org.eclipse.jetty.util.log.Logger.

So I created a simple class that just does nothing:


package synapticloop.resistcms.logger;

/*
* Copyright (c) 2011 synapticloop.
* All rights reserved.
*
* This source code and any derived binaries are covered by the terms and
* conditions of the Licence agreement ("the Licence"). You may not use this
* source code or any derived binaries except in compliance with the Licence.
* A copy of the Licence is available in the file named LICENCE shipped with
* this source code or binaries.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the Licence is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* Licence for the specific language governing permissions and limitations
* under the Licence.
*/

import org.eclipse.jetty.util.log.Logger;

public class CmsLogger implements Logger {
public void debug(Throwable arg0) {
}

public void debug(String arg0, Object... arg1) {
}

public void debug(String arg0, Throwable arg1) {
}

public Logger getLogger(String arg0) {
// TODO Auto-generated method stub
return null;
}

public String getName() {
return null;
}

public void ignore(Throwable arg0) {
}

public void info(Throwable arg0) {
}
public void info(String arg0, Object... arg1) {
}

public void info(String arg0, Throwable arg1) {
}

public boolean isDebugEnabled() {
return false;
}

public void setDebugEnabled(boolean arg0) {
}

public void warn(Throwable arg0) {
}

public void warn(String arg0, Object... arg1) {
}

public void warn(String arg0, Throwable arg1) {
}
}


Leave a Reply

You must be logged in to post a comment.