Hadoop has its own path and configuration method for logging.
Print Log method: LOG4J,SLF4J, such as logging methods, system logs and so on.
Definition of the path and file name of the log record: There are related settings in Mapred-site.xml.
- <? XML version="1.0"?>
- <? Xml-stylesheet type="text/xsl" href="configuration.xsl"?>
- <!--Put Site-specific property overrides in this file.--
- < Configuration >
- <!--Jobtracker's master address--
- < Property >
- < name >mapred.job.tracker</name>
- < value >192.168.75.130:9001</value>
- </ Property >
- < Property >
- <!--Hadoop log output specified directory--
- < name > mapred.local.dir </ name >
- < value >/root/hadoop1.2/mylogs</value>
- </ Property >
- </ Configuration >
Configuration of log content
Modify the Log4j.properties file. At the end of the file, add the following:
#为写日志的操作取个名字, Mydfsclient. Used to get an instance of the log in Dfsclient. and specify the output mode as a custom out
Log4j.logger.mydfsclient=debug,out
#设置OUT的输出方式为输出到文件
Log4j.appender.out=org.apache.log4j.fileappender
#设置文件路径
Log4j.appender.out.file=${hadoop.log.dir}/dfsclient.log
#设置文件的布局
Log4j.appender.out.layout=org.apache.log4j.patternlayout
#设置文件的格式
log4j.appender.out.layout.conversionpattern=%d{iso8601}%p%c:%m%n
#设置该日志操作不与父类日志操作重叠
Log4j.additivity.mydfsclient=false
Log Output
Modifying the Dfsclient class
This is simply to verify the correctness of the process and to add more meaningful log content later.
First declare a log instance in the Dfsclient class:
public static final Logger mylog = Logger.getlogger (Enstsas.class);
In the read (byte buf[], int off, int len) function, add the following code:
Mylog.info ("Read Block!!!!");
if (currentblock!=null)
Mylog.info ("Read Block:" +currentblock.getblockid ());
Hadoop log Output