增加log4j日志的两种方法

原创 2016年05月30日 11:06:45

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

#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 &






相关文章推荐

Guice 快速入门

Guice是谷歌推出的一个轻量级依赖注入框架,帮助我们解决Java项目中的依赖注入问题。如果使用过Spring的话,会了解到依赖注入是个非常方便的功能。不过假如只想在项目中使用依赖注入,那么引入Spr...

Log4j打印日志添加线程ID

目的: 区分每个请求用户,更好的跟踪分析问题(用户登录之后加上userId更佳) 在进行多线程编程时,经常会在调试信息中看到线程的处理流程,需要在日志中体现当前线程信息。因Java中的线程名称采用...

Hadoop 2.6 日志文件和MapReduce的log文件研究心得

学习演练Hadoop 2.6有一段日子了。现在才大致搞清楚了系统里面各个log的位置和功能,在这里总结一下。网上的资料并不丰富,甚至Google出来的结果也不是很满意,或许这个是太简单了,牛人都不屑来...

Eclipse中运行MapReduce程序控制台无调试信息-log4j

在Eclipse中运行MapReduce程序,参数设置都正确的情况下,运行时控制台的输出为: log4j:WARN No appenders could be found for logger (or...

mapreduce在控制台打印log4j日志

log4j.properties配置如下: log4j.rootLogger=INFO, stdout log4j.appender.stdout=org.apache.log4j.Console...

Hadoop log4j日志说明

log4j.propertites # Define some default values that can be overridden by system properties hadoop.r...

Eclipse中运行MapReduce程序控制台无调试信息-log4j

转自:Eclipse中运行MapReduce程序控制台无调试信息-log4j --------------------------------------------------------...

为log4j加上完整的调用者的函数、行号等调试信息

log4j是个必不可少的日志输出工具,在log4j.properties里面配置log4j.appender.RollingAppender.layout.ConversionPattern=%d{y...
  • rocklee
  • rocklee
  • 2016年07月26日 12:04
  • 1542

----log4j----按时间和大小增加新日志文件/输出多个自定义日志文件

 log4j 按时间和大小增加新日志文件        我们开发的B/S结构系统,在服务端一般要有日常运行的日志记录。保存成日志文件形式的时候,大家经常会遇到一个问题:日志文件过大。上百兆的日志文件对...

给定A, B两个整数,不使用除法和取模运算,求A/B的商和余数

给定A, B两个整数,不使用除法和取模运算,求A/B的商和余数。 1.   最基本的算法是,从小到大遍历: for (i = 2 to A -1)          if (i * B > A)...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:增加log4j日志的两种方法
举报原因:
原因补充:

(最多只允许输入30个字)