2013年9月13日星期五

Log4j2 application packaged into jar , you can not output in the console

 This post last edited by the jiangguilong2000 on 2013-09-08 22:58:54
Log4j 2 contains a separate library based on the next generation of LMAX asynchronous logging system in a multithreaded environment , the asynchronous logging system than Log4j 1.x and Logback increased by 10 -fold performance increase ( throughput and latency ) .
Log4j2 current version has been out to the beta8 estimated beta9 will be released in the last week , the next trial , I feel pretty good, do the following conclusion !
I am from logback migrate to log4j2
delete the original package log4j-over-slf4j-1.6.4.jar logback-classic-1.0.7.jar logback-core-1.0.7.jar slf4j-api-1.6. 4.jar
add the following packages log4j-over-slf4j-1.7.5.jar log4j-api-2.0-beta8.jar log4j-core-2.0-beta8.jar log4j-slf4j-impl- 2.0-beta8.jar
As the authors recommend , for performance reasons, try not to use slf4j, but I rely on third-party frameworks such as spring has slf4j use , so the JAR package to do the above trade-offs , so the original code to do the following change
before alteration : import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger logger = LoggerFactory.getLogger (OOXX.class);
altered after : iimport org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
private static final Logger logger = LogManager.getLogger (OOXX.class);
configuration file log4j2.xml as follows:
;



/ log / fish

{LOG_HOME} / backup
stat
global







filePattern = "$ {LOG_HOME} / $ {SERVER_NAME}.% d {yyyy-MM-dd -HH}. log ">






fileName = "$ {LOG_HOME} / $ {SERVER_NAME} _ $ {STAT_NAME}"
filePattern = "$ {LOG_HOME} / $ {SERVER_NAME} _ $ {STAT_NAME}.% d { yyyy-MM-dd-HH}. log ">
pattern = "% date {yyyy-MM-dd HH : mm: ss.SSS}% level [% thread] [% file:% line] -% msg% n "/>

modulate = "true" / >


















additivity = "false">










problem : everything works correctly in Eclipse , if the application packaged into a jar package after the release , cmd command line mode , even if the Console open case, it can not output , and no log file output .
------ Solution ---------------------------------------- ----
I'm late , or pick a point to it . Haha , thank you landlord
------ For reference only ---------------------------------- -----
  The reply deleted by an administrator at 2013-09-09 09:08:39

------ For reference only ---------------------------------- -----
problem has been resolved , you need to MANIFEST.MF file class-Path First add a '.' , the purpose is to allow the same level with the jar package configuration file log4j2.xml loaded in.

example

Class-Path:. lib/antlr-2.7.6.jar lib / other.jar
this way, put the path contains log4j2.xml into the classpath, therefore , log4j2 can read the file. Thank foreigners Jacob Kjome reply !
------ For reference only -------------------------------------- -
really naughty , then give you a ~ ~

没有评论:

发表评论