log4j: package-specific logging

匿名 (未验证) 提交于 2019-12-03 08:36:05

问题:

How can I set log4j to log to a different file according to package name?

for example:

com.myname.fred logs to fred.log com.myname.derek logs to derek.log

I am using the properties file config format. At present it's set up for the server, and I want to leave that alone and add stuff for my logging to it.

Here's what the properties file looks like:

## ## 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        
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!