Home | About | Sematext search-lucene.com search-hadoop.com
 Search Hadoop and all its subprojects:

Switch to Plain View
MapReduce >> mail # user >> Print logs in MapReduce example

Copy link to this message
Print logs in MapReduce example
I created my mapreduce example for hadoop 2.0.4, and how I print the logs
in the console output? The System.out.println(), Logger.getRootLogger(),
and Logger.getLogge(MyClass.class) don't      print nothing.

Here is my code.

public class WordCountAggregator extends Configured implements Tool {

    public static Logger LOG = Logger.getLogger(WordCountAggregator.class);
    public static Logger LOG2 = Logger.getRootLogger();
     * Counts the words in each line.
     * For each line of input, break the line into words and emit them as
     * (<b>word</b>, <b>1</b>).
    public static class MapClass extends MapReduceBase
    implements Mapper<LongWritable, Text, Text, IntWritable> {
        private Text word = new Text();

        public void map(LongWritable key, Text value,
                OutputCollector<Text, IntWritable> output,
                Reporter reporter) throws IOException {
            LOG.addAppender(new ConsoleAppender());
            String line = value.toString();
            System.out.println("LLLLLLLLLL " + line);
            LOG.debug("LLLLLLLLLL " + line);
            LOG2.debug("LLLLLLLLLL " + line);
            StringTokenizer itr = new StringTokenizer(line);
            while (itr.hasMoreTokens()) {
                String l = itr.nextToken();
                LOG.info("ABC " + l);
                String[] splits = l.split(" ");
                output.collect(word, new

     * A reducer class that just emits the sum of the input values.
    public static class Reduce extends MapReduceBase
    implements Reducer<Text, IntWritable, Text, IntWritable> {

        public void reduce(Text key, Iterator<IntWritable> values,
                OutputCollector<Text, IntWritable> output,
                Reporter reporter) throws IOException {
            int sum = 0;
            while (values.hasNext()) {
                sum += values.next().get();
            output.collect(key, new IntWritable(sum));
Best regards,