Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set log4j version 2.3 encoding

I've used log-4-j version 2.3 in my web application. Everything is good but Unicode character are logged as '?' in destination file. How can I set character encoding as Unicode 8 to prevent this problem? here is my sample code : I've wrote a main method to run my test on eclipse it worked properly.but when is run this jeryey web service from from browser (my app server is weblogic), all persian characters are appeard as '?' in the log file:

public static void main(String[] args ) {
    UserRestServices service = new UserRestServices();
    service.test();
}

@Path("test")
@GET
public String test() {
    String newString;
    try {
        newString = new String("فارسی".getBytes(), "UTF8");
        APLogManager.infoLogger.info(newString);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    return "test compeleted";
}
like image 785
Arnia Avatar asked Dec 10 '25 10:12

Arnia


1 Answers

You can set the charset of the layout. For example:

<PatternLayout
    charset="UTF-8"
    pattern="%d %p %c{1.} [%t] %m%n" />
like image 162
Remko Popma Avatar answered Dec 13 '25 14:12

Remko Popma