问题描述
我想关闭弹簧3.1的log4j记录,而在调试我自己的代码的情况下进行调试.
我尝试将此线粘在我的log4j.properties:
log4j.category.org.springframework = WARN
得到这个:
# Root Logger Setup: Includes the level of reporting and appenders -> where # log messages get sent log4j.rootLogger = DEBUG,ca,fa log4j.category.org.springframework = WARN #ca - Console Appender - Send messages to the console log4j.appender.ca = org.apache.log4j.ConsoleAppender log4j.appender.ca.layout = org.apache.log4j.PatternLayout log4j.appender.ca.layout.ConversionPattern = [acme]: [%-5p] - %d{yyyy-MMM-dd HH:mm:ss} - %c{1}:%M(): %m%n #fa - File Appender - Send messages to a log file log4j.appender.fa = org.apache.log4j.RollingFileAppender log4j.appender.fa.File = acme.log log4j.appender.fa.MaxFileSize = 100KB log4j.appender.fa.MaxBackupIndex = 10 log4j.appender.fa.Threshold = DEBUG log4j.appender.fa.layout = org.apache.log4j.PatternLayout log4j.appender.fa.layout.ConversionPattern = [%-5p] - %d{yyyy-MMM-dd HH:mm:ss} - %c{2}:%M(): %m%n
不运气关闭春季的调试输出.
事先感谢您的任何帮助
史蒂夫
推荐答案
我弄清楚了.
在我的班级路径中,我有一个目录C:\ class,为了方便我进行实验.我还有另一个log4.properties文件,它取代了我战争中包装的那个文件,使它看起来像下面的技术不起作用.我重命名为log4. c:\ class中的properties,一切都很好.
感谢所有观看的人,并感谢Spring Source的人们做到了这一点.很高兴知道,当我想要时,我很容易获得大量调试,而不仅仅是黑匣子.
其他推荐答案
您的所有依赖都到位了吗?
1.3.2.3使用log4j
许多人将log4j用作配置和管理目的的记录框架.这是有效且建立良好的,实际上,这是我们在建造和测试弹簧时在运行时使用的. Spring还提供了一些用于配置和初始化log4j的实用程序,因此它在某些模块中具有可选的编译时间依赖性.
使log4j与默认的jcl依赖关系(Commons-Logging)一起使用,您需要做的就是将log4j放在classPath上,并在class path的根中提供配置文件(log4j.properties或log4j.xml) ).因此,对于Maven用户,这是您的依赖性声明:
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.0.0.RELEASE</version> <scope>runtime</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> <scope>runtime</scope> </dependency> </dependencies>
这是用于登录控制台的示例log4j.properties:
log4j.rootCategory=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n log4j.category.org.springframework.beans.factory=DEBUG
问题描述
I would like to turn off log4j logging for Spring 3.1 while leaving things on debug for my own code.
I tried sticking this line into my log4j.properties:
log4j.category.org.springframework = WARN
To get this:
# Root Logger Setup: Includes the level of reporting and appenders -> where # log messages get sent log4j.rootLogger = DEBUG,ca,fa log4j.category.org.springframework = WARN #ca - Console Appender - Send messages to the console log4j.appender.ca = org.apache.log4j.ConsoleAppender log4j.appender.ca.layout = org.apache.log4j.PatternLayout log4j.appender.ca.layout.ConversionPattern = [acme]: [%-5p] - %d{yyyy-MMM-dd HH:mm:ss} - %c{1}:%M(): %m%n #fa - File Appender - Send messages to a log file log4j.appender.fa = org.apache.log4j.RollingFileAppender log4j.appender.fa.File = acme.log log4j.appender.fa.MaxFileSize = 100KB log4j.appender.fa.MaxBackupIndex = 10 log4j.appender.fa.Threshold = DEBUG log4j.appender.fa.layout = org.apache.log4j.PatternLayout log4j.appender.fa.layout.ConversionPattern = [%-5p] - %d{yyyy-MMM-dd HH:mm:ss} - %c{2}:%M(): %m%n
No luck in shutting off the debug output from Spring though.
Thanks in advance for any help
Steve
推荐答案
I figured this out.
In my classpath I have a directory C:\Classes for convenience when I am experimenting with things. I had another log4.properties file there, which was superseding the one packaged in my WAR making it look like the technique below wasn't working. I renamed the log4.properties in my C:\Classes and all is well.
Thanks to everyone who took a look and thanks to the people at Spring Source who made doing this necessary. It is good to know that an extensive level of debugging is easily available to me when I want it instead of just getting a black box.
其他推荐答案
Are all your dependencies in place?
1.3.2.3 Using Log4J
Many people use Log4j as a logging framework for configuration and management purposes. It's efficient and well-established, and in fact it's what we use at runtime when we build and test Spring. Spring also provides some utilities for configuring and initializing Log4j, so it has an optional compile-time dependency on Log4j in some modules.
To make Log4j work with the default JCL dependency (commons-logging) all you need to do is put Log4j on the classpath, and provide it with a configuration file (log4j.properties or log4j.xml in the root of the classpath). So for Maven users this is your dependency declaration:
<dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>3.0.0.RELEASE</version> <scope>runtime</scope> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.14</version> <scope>runtime</scope> </dependency> </dependencies>
And here's a sample log4j.properties for logging to the console:
log4j.rootCategory=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n log4j.category.org.springframework.beans.factory=DEBUG