English 中文(简体)
未能在使用日志4j 日志记录仪的记录中获取信息记录。
原标题:Not getting INFO logs in log file using log4j logger
  • 时间:2011-10-23 14:15:09
  •  标签:
  • java
  • log4j

我开始于java和log4j。 我需要帮助我的测试方案。

$pwd

/家庭/家庭/家庭/家庭/家庭/家庭

$ls

log4j. 试验室log4j.java记录_filelogger.xml 运行。

$cat Log4jTest.java 
  import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

public class Log4jTest
{
public static void main(String args[])
{
Logger _log;
String loggerConfig = System.getenv ("logger_config");
 if (loggerConfig != null && !loggerConfig.trim ().equals (""))
  {   
    DOMConfigurator.configureAndWatch (loggerConfig);
  }   
else
{

System.out.println("no logger_config found");
    System.exit (-1);
}
 System.out.println("Logger is " + Log4jTest.class.getName ());
   _log = Logger.getLogger (Log4jTest.class.getName ());

 _log.info("logging to logger. Good!");
}
}

页: 1

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE log4j:configuration SYSTEM "http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
            <param name="Target" value="System.out" />
            <param name="threshold" value="OFF" />
            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern"
                            value="%d{yyyy-MM-dd HH:mm:ss,SSS}{GMT+0} [%t] %-5p %c{1} - %m%n" />
            </layout>
    </appender>

    <appender name="log4j_test" class="org.apache.log4j.RollingFileAppender">
            <param name="File" value="/家庭/家庭/家庭/家庭/家庭/家庭/log_file" />
            <param name="append" value="true" />
            <layout class="org.apache.log4j.PatternLayout">
                    <param name="ConversionPattern"
                            value="%d{yyyy-MM-dd HH:mm:ss,SSS}{GMT+0} [%t] %-5p %c{1} - %m%n" />
            </layout>
    </appender>

    <logger name="Log4jTest"
            additivity="false">
            <level value="INFO" />
            <appender-ref ref="log4j_test" />
    </logger>

    <root>
            <level value="INFO" />
            <appender-ref ref="log4j_test" />
    </root>

$export logger_config=/家庭/家庭/家庭/家庭/家庭/家庭/log_file

jac-cp 途径log4j 试验.java

j-Cp 途径为4j__log4j.jar: 记录 试验

Logger公司 试验

目录记录——档案

Question:

(1) Is it necessary to specify console appender? (2) what goes in root? (3) What does level_value in root as well as loggers do? (4) I was expecting to see: logging to logger. Good!

缩略语

What is going wrong?

最佳回答

至少需要一名申请人。 否则,Log4J就不知道在什么地方印刷你的标识。 有各种信使:康索尔、档案、JMS、JDBC。 每个人都知道向不同目的地发送信息。

我们不能看到有关青少年的标志,因为青少年的 app子是:

<param name=“threshold” Value=“OFF”/>

Change OFF to INFO and I hope you will see your log.

Log4J具有等级结构。 等级的每一层都可能阻碍你的信息。 还在电离层进行额外的过滤。 页: 1

But pay attention: log4j is deprecated by its creator. Take a look on logback and slf4j.

问题回答

No, you don t need to define a console logger if you re not using it.

海事组织几乎总是对没有独角记录仪的坏想法,不过,大多数电算中心预计违约记录会进入ole,而许多服务器也这样做。 当然,这完全取决于你们的需要。

In general you ll want to have a per-class logger, which is just Logger.getLogger(Log4jTest.class). Set the threshold of that logger in the config file.

还指出,你只能拥有一个<代码>log4j.xml的班次档案,而组合将自动取而代之,避免采取手工组合步骤。

最后,使用特定伐木执行的“native”接口的这些日子相对不寻常,更常见的是围绕实际执行使用 s4j、 log或 common。 不用说can t,我不敢肯定你should。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签