Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 24, 2018 9:45 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed Apr 27, 2011 9:49 pm 
Offline
Oldbie
User avatar

Joined: Fri Jul 20, 2007 9:25 am
Posts: 410
Location: Croatia
Hello.

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:
Code:
Log.setLogSystem(new Log4jLogSystem());


and the implementation is rather simple:

Code:
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);

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

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

    @Override
    public void error(String message) {
        _log.error(message);
    }

    @Override
    public void warn(String message) {
        _log.warn(message);
    }

    @Override
    public  void info(String message) {
        _log.info(message);
    }

    @Override
    public void debug(String message) {
        _log.debug(message);
    }

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


Hope someone will find this useful.


Top
 Profile  
 
PostPosted: Sat Apr 07, 2012 6:38 pm 
Offline

Joined: Sun Nov 20, 2011 9:21 pm
Posts: 25
Thanks! Worked like a charm.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group