Skip to content

Instantly share code, notes, and snippets.

@geofferyzh
Created October 2, 2012 15:47
Show Gist options
  • Save geofferyzh/3820300 to your computer and use it in GitHub Desktop.
Save geofferyzh/3820300 to your computer and use it in GitHub Desktop.
Hadoop 101 - Debug using Log4J.Logger
// Get a handle on a Logger by putting something like this in your class
import org.apache.log4j.Logger;
...
public class Foo {
private static final Logger sLogger = Logger.getLogger(Foo.class);
...
}
// After you get a handle on the logger, within your class you can make logging calls at different levels.
sLogger.debug("Debug message");
sLogger.info("Info message");
sLogger.warn("Warn message");
sLogger.error("Error message");
sLogger.fatal("Fatal message");
import java.io.IOException;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;
import org.apache.log4j.Logger;
//public class SpreadActivatorMapper extends Mapper<LongWritable, Text, Text, Text> {
public class SAMapper extends Mapper<Text, VertexInfo, Text, VertexInfo> {
private static final Logger sLogger = Logger.getLogger(SAMapper.class);
// Map Task ---------------------------------------------------------------------------
public void map(Text key, VertexInfo value, Context context) throws IOException, InterruptedException {
// map task details omitted
sLogger.info("Emitting network pair: [" + key + ", " + value + "]");
context.write(key, value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment