Comment puis-je configurer log4j pour se connecter à un fichier différent en fonction du nom du package?
par exemple:
com.myname.fred logs to fred.log
com.myname.derek logs to derek.log
J'utilise le format de configuration du fichier de propriétés. À l'heure actuelle, il est configuré pour le serveur, et je veux le laisser seul et y ajouter des éléments pour ma journalisation.
Voici à quoi ressemble le fichier de propriétés:
##
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.Apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
##
## $Rev: 564818 $ $Date: 2007-08-10 22:28:29 -0400 (Fri, 10 Aug 2007) $
##
log4j.rootLogger=INFO, CONSOLE, FILE
log4j.appender.CONSOLE=org.Apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=${org.Apache.geronimo.log.ConsoleLogLevel}
log4j.appender.CONSOLE.Target=System.out
log4j.appender.CONSOLE.layout=org.Apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n
log4j.appender.FILE=org.Apache.log4j.RollingFileAppender
log4j.appender.FILE.Threshold=TRACE
log4j.appender.FILE.layout=org.Apache.log4j.PatternLayout
log4j.appender.FILE.layout.ConversionPattern=%d{ABSOLUTE} %-5p [%c{1}] %m%n
#
# Note, changing log4j.appender.FILE.append=false will result in logs being
# overwritten without archiving the previous version of the log.
#
log4j.appender.FILE.append=true
log4j.appender.FILE.file=${org.Apache.geronimo.server.dir}/var/log/geronimo.log
log4j.appender.FILE.bufferedIO=false
log4j.appender.FILE.maxBackupIndex=3
log4j.appender.FILE.maxFileSize=10MB
#
# Example: enable trace logging from CONSOLE appender
#
#log4j.appender.CONSOLE.Threshold=TRACE#org.Apache.geronimo.system.logging.log4j.XLevel
#
# Example: enable trace messages from foo.bar category
#
#log4j.logger.foo.bar=TRACE#org.Apache.geronimo.system.logging.log4j.XLevel
# Geronimo
#This will help find connection leak problems
#log4j.logger.org.Apache.geronimo.connector.outbound=TRACE#org.Apache.geronimo.system.logging.log4j.XLevel
log4j.logger.org.Apache.geronimo.system.logging.log4j.Log4jService=INFO
#### Eliminate any INFO level output during normal operation -- except the really relevant stuff ####
# We can change the Geronimo code to avoid this, but we have to just adjust the log levels for
# any third-party libraries.
log4j.logger.org.Apache.commons.digester=ERROR
log4j.logger.org.Apache.jasper.compiler.SmapUtil=WARN
# ActiveMQ
log4j.logger.org.Apache.activemq=WARN
log4j.logger.org.Apache.activemq.broker.jmx.ManagementContext=ERROR
# Don't need so much info on every web page that's rendered
log4j.logger.org.mortbay=INFO
log4j.logger.org.Apache.pluto=INFO
log4j.logger.org.Apache.jasper=INFO
# Various Jetty startup/shutdown output
log4j.logger.org.mortbay.http.HttpServer=WARN
log4j.logger.org.mortbay.http.SocketListener=WARN
log4j.logger.org.mortbay.http.ajp.AJP13Listener=WARN
log4j.logger.org.mortbay.util.Container=WARN
log4j.logger.org.mortbay.util.Credential=WARN
log4j.logger.org.mortbay.util.ThreadedServer=WARN
log4j.logger.org.mortbay.jetty.servlet.WebApplicationContext=WARN
log4j.logger.org.mortbay.jetty.context=WARN
# Various Tomcat startup output
log4j.logger.org.Apache.catalina.realm.JAASRealm=WARN
log4j.logger.org.Apache.catalina.realm.RealmBase=WARN
log4j.logger.org.Apache.catalina.loader.WebappLoader=WARN
log4j.logger.org.Apache.catalina.startup.Embedded=WARN
log4j.logger.org.Apache.catalina.core.StandardEngine=WARN
log4j.logger.org.Apache.catalina.core.StandardHost=WARN
log4j.logger.org.Apache.jk.common.ChannelSocket=WARN
log4j.logger.org.Apache.jk.server.JkMain=WARN
log4j.logger.org.Apache.coyote.http11.Http11BaseProtocol=WARN
log4j.logger.org.Apache.coyote.http11.Http11Protocol=WARN
log4j.logger.org.Apache.catalina.core.ContainerBase=WARN
log4j.logger.org.Apache.catalina.core.StandardContext=WARN
log4j.logger.org.Apache.Tomcat.util.net.SSLImplementation=WARN
# myfaces startup output
log4j.logger.org.Apache.myfaces.renderkit.html.HtmlRenderKitImpl=WARN
log4j.logger.org.Apache.myfaces.config.FacesConfigurator=WARN
log4j.logger.org.Apache.myfaces.webapp.StartupServletContextListener=WARN
log4j.logger.org.Apache.myfaces.webapp.StartupServletContextListener=WARN
# emits a spurious warn about null locale during startup of webapps
log4j.logger.org.Apache.myfaces.shared_impl.util.LocaleUtils=ERROR
# Emits a spurious WARN during startup on /some-path/* security mappings
log4j.logger.org.Apache.catalina.deploy.SecurityCollection=ERROR
# Prints the MBean Server ID
log4j.logger.javax.management.MBeanServerFactory=WARN
# Prints the RMI connection URL
log4j.logger.javax.management.remote.rmi.RMIConnectorServer=WARN
log4j.logger.javax.management.remote.JMXServiceURL=WARN
# Prints various stuff during startup
log4j.logger.org.Apache.juddi.registry.RegistryServlet=WARN
# Prints various stuff when the portal is used
log4j.logger.org.Apache.pluto.portalImpl.Servlet=WARN
# Prints stuff for AJAX calls
log4j.logger.uk.ltd.getahead.dwr.impl.DefaultConfiguration=WARN
log4j.logger.uk.ltd.getahead.dwr.impl.ExecuteQuery=WARN
log4j.logger.uk.ltd.getahead.dwr.util.Logger=WARN
Vous devez créer deux nouvelles annexes et définir l'additivité en conséquence.
log4j.appender.FRED=org.Apache.log4j.RollingFileAppender
log4j.appender.FRED.File=/path/to/fred.log
log4j.appender.FRED.layout=org.Apache.log4j.PatternLayout
log4j.appender.DEREK=org.Apache.log4j.RollingFileAppender
log4j.appender.DEREK.File=/path/to/derek.log
log4j.appender.DEREK.layout=org.Apache.log4j.PatternLayout
log4j.additivity.com.myname.fred=false
log4j.additivity.com.myname.derek=false
log4j.logger.com.myname.fred=DEBUG, FRED
log4j.logger.com.myname.derek=DEBUG, DEREK
Mise à jour: Vérifiez simplement si vous devez ajouter la ligne ci-dessous.
log4j.rootLogger=DEBUG, R, FRED, DEREK
Où R
est votre fichier journal normal qui enregistre tout sauf FRED
et DEREK
.
log4j.logger.com.myname.fred=LEVEL, appenderNameForFred
log4j.logger.com.myname.derek=LEVEL, appenderNameForDerek