Hi,

As the title says,

I have posted the same thing at stack exchange, as their formatting
features are a bit better than an email. Kindly do got hrough the same ad
offer suggestions

http://stackoverflow.com/questions/16795749/log4j-logs-to-one-file-but-not-to-other

ht tp://
stackoverflow.com/questions/16795749/log4j-logs-to-one-file-but-not-to-other

If policy forbids it, I have also copy-pasted the post below

Regards,
Pradeep


I have added a *custom logging level* to java, via this code.

import org.apache.log4j.Level;
public class NarratorLog extends Level {
    public static final String NARRATOR_LOG = "NARRATOR";
    public static final Level NARRATOR_DEBUG_LOGGING = new
NarratorLog(DEBUG_INT+1, NARRATOR_LOG, 7);
        protected NarratorLog(int level, String levelStr, int
syslogEquivalent) {
        super(level, levelStr, syslogEquivalent);
    }}

I have configured my *log4j.properties* file thus

# Set root logger level to ALL and send as FileLog.
log4j.rootLogger=ALL,FileLog# Set  logger level to customlevel and
send as ConsoleLog.
log4j.logger.NarratorLogger=NARRATOR_DEBUG_LOGGING#ex.logging.NarratorLog
, ConsoleLog
# ConsoleLog is set to be a
ConsoleAppender.#log4j.appender.ConsoleLog=org.apache.log4j.ConsoleAppender
log4j.appender.ConsoleLog=org.apache.log4j.RollingFileAppender
log4j.appender.ConsoleLog.File=Narrator.csv

log4j.appender.ConsoleLog.layout=ex.logging.LoggerLayout
log4j.appender.ConsoleLog.layout.ConversionPattern=%p,  %F  ,   %C  ,
 %M  ,   %L  ,   %d  ,   %r  ,   %m  %n
# FileLog is set to be a FileAppender.
log4j.appender.FileLog=org.apache.log4j.RollingFileAppender
log4j.appender.FileLog.File=logfile.csv

log4j.appender.FileLog.layout=ex.logging.LoggerLayout

log4j.appender.FileLog.layout.ConversionPattern=%p, %F  ,   %C  ,   %M
 ,   %L  ,   %d  ,   %r  ,   %m  %n

log4j.appender.FileLog.Append=false

*Calling the function* in a very simple manner

private static Logger k = Logger.getLogger(Main.class);

    public static void main(String[] args) {
        PropertyConfigurator.configure("log4j.properties");



    k.debug("DrawScreen");
    k.log(NarratorLog.NARRATOR_DEBUG_LOGGING, "I am the narattor");

}

It works allright in the *logfile.csv*, with this output

TYPE    ,   FILE    ,   CLASS   ,   FUNCTION    ,   LINE    ,   DATE
 ,   ,   SECFROMCALL ,   COMMENT
DEBUG,  Main.java   ,   GameCore.Main   ,   main    ,   35  ,
2013-05-28 20:39:11,423 ,   0   ,   DrawScreen
NARRATOR,   Main.java   ,   GameCore.Main   ,   main    ,   36  ,
2013-05-28 20:39:11,426 ,   3   ,   I am the narattor

But when i check the narrator.csv, all i get is... well... unprintable
junk. Where am i going wrong?

Reply via email to