logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Xin Zhang <danis_zh...@yahoo.com.cn>
Subject Wrapping Logger
Date Mon, 24 Dec 2007 10:42:37 GMT

Forgive me if similar question has been answered before. I searched the forum
but could not find exact answer. 

My intention is to generate some system running report in text format
(something like the windows startup log for troubleshooting), and my idea is
to make use of log4j by wrapping Logger class into a new class, say

I wrote codes as below: 

public class RunningReport
    public RunningReport(File file) throws IOException
        logger = Logger.getLogger(this.toString()); // Question 1)
        // PropertiesUtil to get the pattern property from properties file
        layout = new
        appender = null;

        FileOutputStream output = new FileOutputStream(file);
        appender = new WriterAppender(layout, output);


    public void log(String message)
    // Question 2)

My questions are:

1)  Apparently here I could not retrieve the Logger by given a static name
in String, or a class. Each time when the RunningReport instantiated, a new
Logger shall be retrieved. So I wrote the code like that. Not sure whether
the approach correct or not. I got some hints that for such case, it's
better to code my own Appender. If that's true, how shall I do?

2) Is there any method like flush() in Logger that I can call to make sure
all the messages are written into file? 

Thanks in advance and with you all a Merry X'mas!

View this message in context: http://www.nabble.com/Wrapping-Logger-tp14486449p14486449.html
Sent from the Log4j - Users mailing list archive at Nabble.com.

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message