Slick Forums

Log4j LogSystem implementation in slick
Page 1 of 1

Author:  Kova [ Wed Apr 27, 2011 9:49 pm ]
Post subject:  Log4j LogSystem implementation in slick


I setup log4j logging (most known Java logging system) in my game so I wanted to share with you the implementation of Slick's LogSystem with it. Slick uses Log class for logging where you can define what the system does with the log messages.

In order to route Slicks internal calls to Log to my log4j loggers, I wrote an implementation for the LogSystem.
Use it by placing in your main this line of code:
Log.setLogSystem(new Log4jLogSystem());

and the implementation is rather simple:

package com.threelines.afterdeath.utilities;

import org.apache.log4j.Logger;
import org.newdawn.slick.util.LogSystem;

 * Impelentation to route internal slick log calls to our log4j system.
 * I don't recommend using org.newdawn.slick.util.Log for logging in your game
 * as wou will lose log4j information such as class name, context and such.
 * Use this just LogSystem implentation just for routing Slick's internal
 * Log calls that we can't control.
 * @author Kova
public class Log4jLogSystem implements LogSystem {
    private static final Logger _log = Logger.getLogger(Log4jLogSystem.class);

    public void error(String message, Throwable e) {
        _log.error(message, e);

    public void error(Throwable e) {
        _log.error("", e);

    public void error(String message) {

    public void warn(String message) {

    public  void info(String message) {;

    public void debug(String message) {

    public void warn(String message, Throwable e) {
        _log.warn(message, e);

Hope someone will find this useful.

Author:  kibertoad [ Sat Apr 07, 2012 6:38 pm ]
Post subject:  Re: Log4j LogSystem implementation in slick

Thanks! Worked like a charm.

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group