...
<mbeancode="org.jboss.logging.Log4jService"name="jboss.system:type=Log4jService,service=Logging"xmbean-dd="resource:xmdesc/Log4jService-xmbean.xml"><attributename="ConfigurationURL">resource:jboss-log4j.xml</attribute><!-- Set the org.apache.log4j.helpers.LogLog.setQuiteMode. As of log4j1.2.8
this needs to be set to avoid a possible deadlock on exception at the
appender level. See bug#696819.
--><attributename="Log4jQuietMode">true</attribute><!-- How frequently in seconds the ConfigurationURL is checked for changes --><attributename="RefreshPeriod">60</attribute><attributename="CatchSystemOut">false</attribute></mbean>
...
以下不重要
现象
项目有几个在用 jboss 作服务器;
A 项目,在 log4j.xml 中 没有配置控制台输出日志,鉴于项目非常大且非常复杂,没有调整过日志配置。但是无论如何 在使用 logger.info("XXX") 时是不能输出到控制台的,另一个现象是使用 System.out.println("XXXX") 时,控制台会自己添加时间戳和 [STOUT],例如:13:15:01,525 INFO [STDOUT]
/***************************************
* *
* JBoss: The OpenSource J2EE WebOS *
* *
* Distributable under LGPL license. *
* See terms of license at gnu.org. *
* *
***************************************/package org.jboss.logging.util;import java.io.IOException;import java.io.PrintStream;import org.apache.log4j.Logger;import org.apache.log4j.Level;import org.jboss.logging.XLevel;/**
* A subclass of PrintStream that redirects its output to a log4j Logger.
*
* <p>This class is used to map PrintStream/PrintWriter oriented logging onto
* the log4j Categories. Examples include capturing System.out/System.err
*
* @version <tt>$Revision: 1.3 $</tt>
* @author <a href="mailto:Scott.Stark@jboss.org">Scott Stark</a>.
* @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
*/publicclassLoggerStreamextendsPrintStream{/**
* Default flag to enable/disable tracing println calls.
* from the system property <tt>org.jboss.logging.util.LoggerStream.trace</tt>
* or if not set defaults to <tt>false</tt>.
*/publicstaticfinalboolean TRACE =getBoolean(LoggerStream.class.getName()+".trace",false);/** Helper to get boolean value from system property or use default if not set. */privatestaticbooleangetBoolean(String name,boolean defaultValue){
String value = System.getProperty(name, null);if(value == null)return defaultValue;returnnewBoolean(value).booleanValue();}private Logger logger;private Level level;privateboolean inWrite;privateboolean issuedWarning;/**
* Redirect logging to the indicated logger using Level.INFO
*/publicLoggerStream(final Logger logger){this(logger, Level.INFO, System.out);}/**
* Redirect logging to the indicated logger using the given
* level. The ps is simply passed to super but is not used.
*/publicLoggerStream(final Logger logger,final Level level,final PrintStream ps){super(ps);this.logger = logger;this.level = level;}publicvoidprintln(String msg){if( msg == null )
msg ="null";byte[] bytes = msg.getBytes();write(bytes,0, bytes.length);}publicvoidprintln(Object msg){if( msg == null )
msg ="null";byte[] bytes = msg.toString().getBytes();write(bytes,0, bytes.length);}publicvoidwrite(byte b){byte[] bytes ={b};write(bytes,0,1);}private ThreadLocal recursiveCheck =newThreadLocal();publicvoidwrite(byte[] b,int off,int len){
Boolean recursed =(Boolean)recursiveCheck.get();if(recursed != null && recursed.equals(Boolean.TRUE)){/* There is a configuration error that is causing looping. Most
likely there are two console appenders so just return to prevent
spinning.
*/if( issuedWarning ==false){
String msg ="ERROR: invalid console appender config detected, console stream is looping";try{
out.write(msg.getBytes());}catch(IOException ignore){}
issuedWarning =true;}return;}// Remove the end of line charswhile( len >0&&(b[len-1]=='\n'|| b[len-1]=='\r')&& len > off )
len --;// HACK, something is logging exceptions line by line (including// blanks), but I can't seem to find it, so for now just ignore// empty lines... they aren't very useful.if(len !=0){
String msg =newString(b, off, len);
recursiveCheck.set(Boolean.TRUE);if(TRACE){
logger.log(level, msg,newThrowable());}else{
logger.log(level, msg);}
recursiveCheck.set(Boolean.FALSE);}}}