增加log4j日志的两种方法

一种是如下配置,但这种较为复杂,我配置的时候出现过内部类的日志没有写入的问题,尚未搞清楚原因,即在原有配置文件中追加:

#CentralizedReceivedServer
log4j.logger.org.apache.hama.bsp.message.CentralizedMessageReceiveServer=INFO,centralLogger
log4j.appender.centralLogger=org.apache.log4j.FileAppender
log4j.appender.centralLogger.File=/opt/hama-0.7.1/logs/Central.log
log4j.appender.centralLogger.layout=org.apache.log4j.PatternLayout
log4j.appender.centralLogger.layout.ConversionPattern=%d %p [%c] - %m%n
log4j.additivity.centralLogger=false  //表明本输入日志中不加入rootLogger中的日志数据,而是单独的一个输出

#RPC Server
log4j.logger.org.apache.hama.ipc.Server=INFO,centralLogger
log4j.logger.org.apache.hama.ipc.Server.Listener=INFO,centralLogger
</pre><pre code_snippet_id="1701345" snippet_file_name="blog_20160530_6_1542532" name="code" class="java">
</pre>另外一种则是直接在该进程的启动进程脚本中写入日志对应文件:<p></p><p></p><pre code_snippet_id="1701345" snippet_file_name="blog_20160530_5_2240643" name="code" class="java">#!/usr/bin/env bash

/home/liuqiang2/jdk/jdk1.7.0_79/bin/java -Xmx2048m -Dhama.log.dir=/opt/hama-0.7.1/bin/../logs 
-Dhama.log.file=centralLogger.log
-Dhama.home.dir=/opt/hama-0.7.1/bin/.. -Dhama.id.str=liuqiang2 -Dhama.root.logger=INFO,DRFA -Dhama.policy.file=hama-policy.xml 


</pre><pre code_snippet_id="1701345" snippet_file_name="blog_20160530_7_877440" name="code" class="java">-classpath /opt/hama-0.7.1/bin/../conf:/home/liuqiang2/jdk/jdk1.7.0_79/lib/tools.jar:/opt/hama-0.7.1/bin/../hama-commons-0.7.1.jar:/opt/hama-0.7.1/bin/../hama-core-0.7.1.jar:/opt/hama-0.7.1/bin/../hama-examples-0.7.1.jar:/opt/hama-0.7.1/bin/../hama-graph-0.7.1.jar:/opt/hama-0.7.1/bin/../hama-mesos-0.7.1.jar:/opt/hama-0.7.1/bin/../hama-ml-0.7.1.jar:/opt/hama-0.7.1/bin/../hama-yarn-0.7.1.jar:/opt/hama-0.7.1/bin/../lib/activation-1.1.jar:/opt/hama-0.7.1/bin/../lib/ant-1.6.5.jar:/opt/hama-0.7.1/bin/../lib/ant-1.7.1.jar:/opt/hama-0.7.1/bin/../lib/ant-launcher-1.7.1.jar:/opt/hama-0.7.1/bin/../lib/aopalliance-1.0.jar:/opt/hama-0.7.1/bin/../lib/apacheds-i18n-2.0.0-M15.jar:/opt/hama-0.7.1/bin/../lib/apacheds-kerberos-codec-2.0.0-M15.jar:/opt/hama-0.7.1/bin/../lib/api-asn1-api-1.0.0-M20.jar:/opt/hama-0.7.1/bin/../lib/api-util-1.0.0-M20.jar:/opt/hama-0.7.1/bin/../lib/asm-3.1.jar:/opt/hama-0.7.1/bin/../lib/avro-1.5.3.jar:/opt/hama-0.7.1/bin/../lib/commons-beanutils-1.8.3.jar:/opt/hama-0.7.1/bin/../lib/commons-cli-1.2.jar:/opt/hama-0.7.1/bin/../lib/commons-codec-1.4.jar:/opt/hama-0.7.1/bin/../lib/commons-collections-3.2.1.jar:/opt/hama-0.7.1/bin/../lib/commons-compress-1.9.jar:/opt/hama-0.7.1/bin/../lib/commons-configuration-1.7.jar:/opt/hama-0.7.1/bin/../lib/commons-daemon-1.0.13.jar:/opt/hama-0.7.1/bin/../lib/commons-digester-1.8.1.jar:/opt/hama-0.7.1/bin/../lib/commons-httpclient-3.0.1.jar:/opt/hama-0.7.1/bin/../lib/commons-io-2.4.jar:/opt/hama-0.7.1/bin/../lib/commons-lang-2.6.jar:/opt/hama-0.7.1/bin/../lib/commons-logging-1.1.1.jar:/opt/hama-0.7.1/bin/../lib/commons-math3-3.0.jar:/opt/hama-0.7.1/bin/../lib/commons-net-3.1.jar:/opt/hama-0.7.1/bin/../lib/core-3.1.1.jar:/opt/hama-0.7.1/bin/../lib/curator-client-2.7.1.jar:/opt/hama-0.7.1/bin/../lib/curator-framework-2.7.1.jar:/opt/hama-0.7.1/bin/../lib/curator-recipes-2.7.1.jar:/opt/hama-0.7.1/bin/../lib/geronimo-annotation_1.0_spec-1.0.jar:/opt/hama-0.7.1/bin/../lib/geronimo-spec-jta-1.0.1B-rc4.jar:/opt/hama-0.7.1/bin/../lib/gson-2.2.4.jar:/opt/hama-0.7.1/bin/../lib/guava-13.0.1.jar:/opt/hama-0.7.1/bin/../lib/guice-3.0.jar:/opt/hama-0.7.1/bin/../lib/guice-servlet-3.0.jar:/opt/hama-0.7.1/bin/../lib/hadoop-annotations-2.7.0.jar:/opt/hama-0.7.1/bin/../lib/hadoop-auth-2.7.0.jar:/opt/hama-0.7.1/bin/../lib/hadoop-common-2.7.0.jar:/opt/hama-0.7.1/bin/../lib/hadoop-hdfs-2.7.0.jar:/opt/hama-0.7.1/bin/../lib/hadoop-hdfs-2.7.0-tests.jar:/opt/hama-0.7.1/bin/../lib/hadoop-mapreduce-client-core-2.7.0.jar:/opt/hama-0.7.1/bin/../lib/hadoop-yarn-api-2.7.0.jar:/opt/hama-0.7.1/bin/../lib/hadoop-yarn-client-2.7.0.jar:/opt/hama-0.7.1/bin/../lib/hadoop-yarn-common-2.7.0.jar:/opt/hama-0.7.1/bin/../lib/htrace-core-3.1.0-incubating.jar:/opt/hama-0.7.1/bin/../lib/httpclient-4.2.5.jar:/opt/hama-0.7.1/bin/../lib/httpcore-4.1.2.jar:/opt/hama-0.7.1/bin/../lib/jackson-core-asl-1.9.2.jar:/opt/hama-0.7.1/bin/../lib/jackson-jaxrs-1.8.3.jar:/opt/hama-0.7.1/bin/../lib/jackson-mapper-asl-1.9.2.jar:/opt/hama-0.7.1/bin/../lib/jackson-xc-1.8.3.jar:/opt/hama-0.7.1/bin/../lib/javax.inject-1.jar:/opt/hama-0.7.1/bin/../lib/java-xmlbuilder-0.4.jar:/opt/hama-0.7.1/bin/../lib/jaxb-api-2.2.2.jar:/opt/hama-0.7.1/bin/../lib/jaxb-impl-2.2.3-1.jar:/opt/hama-0.7.1/bin/../lib/jdk.tools-1.7.jar:/opt/hama-0.7.1/bin/../lib/jersey-client-1.9.jar:/opt/hama-0.7.1/bin/../lib/jersey-core-1.9.jar:/opt/hama-0.7.1/bin/../lib/jersey-guice-1.9.jar:/opt/hama-0.7.1/bin/../lib/jersey-json-1.9.jar:/opt/hama-0.7.1/bin/../lib/jersey-server-1.9.jar:/opt/hama-0.7.1/bin/../lib/jets3t-0.9.0.jar:/opt/hama-0.7.1/bin/../lib/jettison-1.1.jar:/opt/hama-0.7.1/bin/../lib/jetty-6.1.14.jar:/opt/hama-0.7.1/bin/../lib/jetty-annotations-6.1.14.jar:/opt/hama-0.7.1/bin/../lib/jetty-plus-6.1.14.jar:/opt/hama-0.7.1/bin/../lib/jetty-util-6.1.14.jar:/opt/hama-0.7.1/bin/../lib/jline-0.9.94.jar:/opt/hama-0.7.1/lib/commons-logging-1.1.1.jar:/opt/hama-0.7.1/lib/slf4j-log4j12-1.5.8.jar:/opt/hama-0.7.1/lib/slf4j-api-1.5.8.jar:/opt/hama-0.7.1/lib/log4j-1.2.16.jar:/opt/hama-0.7.1/lib/leveldbjni-all-1.8.jar:/opt/hama-0.7.1/lib/protobuf-java-2.5.0.jar:/opt/hama-0.7.1/   org.apache.hama.bsp.message.CentralizedMessageReceiveServer &






阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

增加log4j日志的两种方法

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭