简体   繁体   English

Log4j无法正常工作

[英]Log4j is not working

I am trying with logging methods (Log4j) in eclipse and I am getting the following problems 我正在尝试使用eclipse中的日志记录方法(Log4j),但遇到以下问题

And I deployed log4j.properties file in project folder. 我在项目文件夹中部署了log4j.properties文件。 Here below one is the main method of my program: 下面是我程序的主要方法:

 package com.aransys.roughworkout.log4j;

 import org.apache.log4j.Logger;

 import java.io.IOException;
 import java.sql.SQLException;
 import java.util.logging.*;

 public class Log4jExample  {

static Logger log = Logger.getRootLogger();
public static void main(String[] args) throws IOException,SQLException {
    log.debug("Sample debug message");
    log.info("Sample info message");
    log.warn("Sample warn message");
    log.error("Sample error message");
    log.fatal("Sample fatal message");
 }
}

And below one is the code in Log4j.properties in my program: 下面是我程序中Log4j.properties中的代码:

log4j.rootLogger=DEBUG,FILE
log4j.appender.FILE=org.apache.log4j.ConsoleAppender
log4j.appender.FILE.layout=org.apache.log4j.SimpleLayout

But the code is not running properly, and it is the stating the following error. 但是代码无法正常运行,它说明了以下错误。

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
at com.aransys.roughworkout.log4j.Log4jExample.main(Log4jExample.java:8)

Your code not even compile! 您的代码甚至无法编译! Create your logger like this: 像这样创建您的记录器:

private static final Logger log = Logger.getLogger(Log4jExample.class);

and remove 并删除

import java.util.logging.*;

After that, clean and build your project. 之后,清理并构建您的项目。

According to the exception that you get it seams that there is an compilation problem you have at line 8 which is not resolved 根据获得的异常,表明第8行存在编译问题,该问题无法解决

if you are using Eclipse then eclipse must showing the compilation error on same line (ie 8), If not just clean and rebuild the project under the Project tab of Eclipse. 如果您使用的是Eclipse然后蚀一定表示(即8),如果不只是干净的同一行的编译错误和Eclipse的项目选项卡下的重建项目。

I have run the same code in my eclipse and its works fine for me 我在日食中运行了相同的代码,它对我来说很好

hope this will solve your problem....! 希望这能解决您的问题....!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM