hossein
hossein

Reputation: 71

extra information in log4j log

I have a simple log sample.

Log4jExample:

package com.mobin.pack1;
import java.io.IOException;
import java.sql.SQLException;
import org.apache.log4j.Logger;
import org.apache.log4j.MDC;

public class Log4jExample {
     /* Get actual class name to be printed on */
     static Logger log = Logger.getLogger(Log4jExample.class);

     public static void main(String[] args) throws IOException, SQLException {

     MDC.put("user", "1");      
     log.info("Info");
    }
}

log4j.properties:

# Root logger option
log4j.rootLogger=INFO, stdout

# Direct log messages to stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%x{user} - %d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

when i run it , this is printed in console :

{user} - 2015-05-06 12:25:31 INFO  Log4jExample:17 - Info

but i want to print "1" instead of "{user}".

what is problem?

Upvotes: 1

Views: 191

Answers (1)

traveh
traveh

Reputation: 2884

I think you just got the case wrong - try uppercase X: %X{user}

Upvotes: 3

Related Questions