What is the Best Logging method in Hadoop MapReduce java classes? What is the Best Logging method in Hadoop MapReduce java classes? hadoop hadoop

What is the Best Logging method in Hadoop MapReduce java classes?


I prefer the java.util.logging.Logger, it will collect the logs in the job tracker.

For debugging java map reduce files you can use the logger for each class( driver, mapper, reducer ).

Logger log = Logger.getLogger(MyClass.class.getName());

To inspect variables just use :

log.info( "varOne: " + varOne );

These log lines with be printed in the administration page for your job.


I had Used slf4j, It is the wrapper around log4j and other logging libraries, If you need to change to some other logging library, you can, without changing actual code.

import org.slf4j.LoggerFactory;private static final org.slf4j.Logger LOG = LoggerFactory.getLogger(WordCountExampleLoggingTest.class);

// Use it as

        LOG.error("Inseide Mapper");        LOG.info("inside reducer ");

// For Logging configuration, add log4j.properies file in resources folder of your application.

ODS.LOG.DIR=/var/log/appLogsODS.LOG.INFO.FILE=application.logODS.LOG.ERROR.FILE=application_error.log# Root logger optionlog4j.rootLogger=ERROR, consolelog4j.logger.com.ournamespace=ERROR, APP_APPENDER, ERROR_APPENDER## console# Add "console" to rootlogger above if you want to use this#log4j.appender.console=org.apache.log4j.ConsoleAppenderlog4j.appender.console.target=System.outlog4j.appender.console.layout=org.apache.log4j.PatternLayoutlog4j.appender.console.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}-%r %p %c{5}: %m%n# Direct log messages to a log filelog4j.appender.APP_APPENDER=org.apache.log4j.RollingFileAppenderlog4j.appender.APP_APPENDER.File=${ODS.LOG.DIR}/${ODS.LOG.INFO.FILE}log4j.appender.APP_APPENDER.MaxFileSize=200MBlog4j.appender.APP_APPENDER.MaxBackupIndex=30log4j.appender.APP_APPENDER.layout=org.apache.log4j.PatternLayoutlog4j.appender.APP_APPENDER.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}-%r %p %c{10}: %m%nlog4j.appender.ERROR_APPENDER=org.apache.log4j.RollingFileAppenderlog4j.appender.ERROR_APPENDER.Threshold=ERRORlog4j.appender.ERROR_APPENDER.File=${ODS.LOG.DIR}/${ODS.LOG.ERROR.FILE}log4j.appender.ERROR_APPENDER.MaxFileSize=200MBlog4j.appender.ERROR_APPENDER.MaxBackupIndex=90log4j.appender.ERROR_APPENDER.layout=org.apache.log4j.PatternLayoutlog4j.appender.ERROR_APPENDER.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}-%r %p %c{10}: %m%n

I can check the logs from ambari job tracker UI .I hope that can help you.