找不到用于logger(log4j)的附加程序?

本文翻译自:No appenders could be found for logger(log4j)?

I have put log4j to my buildpath, but I get the following message when I run my application: 我已经将log4j放到了我的构建路径中,但是在运行应用程序时收到以下消息:

log4j:WARN No appenders could be found for logger (dao.hsqlmanager).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.

What do these warnings mean? 这些警告是什么意思? Whats the appender here? 这里的追加器是什么?


#1楼

参考:https://stackoom.com/question/qaEV/找不到用于logger-log-j-的附加程序


#2楼

You use the Logger in your code to log a message. 您可以在代码中使用Logger来记录消息。 The Appender is a Object appended to a Logger to write the message to a specific target. Appender是附加到Logger的对象,用于将消息写入特定目标。 There are FileAppender to write to text-files or the ConsoleAppender to write to the Console. FileAppender可以写入文本文件,也有ConsoleAppender可以写入控制台。 You need to show your code of the Logger and Appender setup for more help. 您需要显示Logger和Appender设置的代码以获取更多帮助。

please read the tutorial for a better understanding of the interaction of Logger and Appender. 请阅读该教程 ,以更好地了解Logger和Appender的交互。


#3楼

This Short introduction to log4j guide is a little bit old but still valid. 这个log4j指南的简短介绍有些陈旧,但仍然有效。

That guide will give you some information about how to use loggers and appenders. 该指南将为您提供有关如何使用记录器和附加器的信息。


Just to get you going you have two simple approaches you can take. 为了让您步入正轨,您可以采用两种简单的方法。

First one is to just add this line to your main method: 首先是将这一行添加到您的main方法中:

BasicConfigurator.configure();

Second approach is to add this standard log4j.properties (taken from the above mentioned guide) file to your classpath: 第二种方法是将这个标准的log4j.properties (从上述指南中获取)添加到您的类路径中:

# Set root logger level to DEBUG and its only appender to A1.
log4j.rootLogger=DEBUG, A1

# A1 is set to be a ConsoleAppender.
log4j.appender.A1=org.apache.log4j.ConsoleAppender

# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

#4楼

I get the same error. 我犯了同样的错误。 Here the problem which leads to this error message: 这是导致此错误消息的问题:

I create some objects which use the Logger before I configure the log4j: 在配置log4j之前,我创建了一些使用Logger的对象:

Logger.getLogger(Lang.class.getName()).debug("Loading language: " + filename);

Solution: Configure the log4j at the beginning in the main method: 解决方案:在main方法的开头配置log4j:

PropertyConfigurator.configure(xmlLog4JConfigFile); 
// or BasicConfigurator.configure(); if you dont have a config file

#5楼

It looks like you need to add the location of your log4j.properties file to the Classpath in Eclipse. 看来您需要将log4j.properties文件的位置添加到Eclipse中的Classpath中。

Make sure your project is open in Eclipse, then click on the "Run" menu at the top of Eclipse and click on the following: 确保您的项目在Eclipse中打开,然后单击Eclipse顶部的“运行”菜单,然后单击以下内容:

  1. Run
  2. Run Configurations 运行配置
  3. Classpath (tab) 类路径(标签)
  4. User Entries 用户条目
  5. Advanced (button on the right) 高级(右侧按钮)
  6. Add Folders 新增资料夹
  7. then navigate to the folder that contains your log4j.properties file 然后导航到包含log4j.properties文件的文件夹
  8. Apply 应用
  9. Run

The error message should no longer appear. 错误消息应该不再出现。


#6楼

Quick solution: 快速解决方案:

  1. add code to main function : 主要功能添加代码:

     String log4jConfPath = "/path/to/log4j.properties"; PropertyConfigurator.configure(log4jConfPath); 
  2. create a file named log4j.properties at /path/to / path / to创建一个名为log4j.properties的文件

     log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Target=System.out log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{2}: %m%n 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值