Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Storm logback appender for Topology

I have a storm topology and I would like to log certain events that occur within the topology into a separate log file. I am trying to create a custom appender in the storm/logback/cluster.xml which will be used to log these events. Here is my cluster.xml snippet that is setting everything up:

<appender name="A2" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>${storm.home}/logs/custom-logger/cl-log.log</file>
    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <fileNamePattern>${storm.home}/logs/${logfile.name}.%i</fileNamePattern>
      <minIndex>1</minIndex>
      <maxIndex>9</maxIndex>
    </rollingPolicy>

    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <maxFileSize>100MB</maxFileSize>
    </triggeringPolicy>

    <encoder>
      <pattern>%d{yyyy-MM-dd_HH:mm:ss} %c{1} [%p] %m$n</pattern>
    </encoder>
</appender>

<logger name="custom-logger" additivity="false">
   <level value="INFO" />
   <appender-ref ref="A2"/>
</logger>

I am using the basic WordCountTopology to just test the example. Here is the snippet of code where I am trying to write to the log file

public static class WordCount extends BaseBasicBolt {

    private static final org.slf4j.Logger CUSTOM_LOGGER = 
           LoggerFactory.getLogger("custom-logger");
    Map<String, Integer> counts = new HashMap<String, Integer>();

    public void execute(Tuple tuple, BasicOutputCollector collector) {
      String word = tuple.getString(0);
      Integer count = counts.get(word);
      if (count == null)
        count = 0;
      count++;
      counts.put(word, count);

      CUSTOM_LOGGER.info("Emitting word[" + word + "] count["+ count + "]");
      collector.emit(new Values(word, count));
    }

    public void declareOutputFields(OutputFieldsDeclarer declarer) {
      declarer.declare(new Fields("word", "count"));
    }
}

No matter what I do, I can't seem to get these logs to show up in the custom-logger cl-log.log file. Is this even possible within Storm to log specific events to a specific file using logback? Any help would be appreciated.

like image 562
medium Avatar asked Apr 13 '15 16:04

medium


1 Answers

Just for completeness, I did get this to work. I was deploying my topologies locally and therefore the logging was not occurring. Once I deployed my topologies to the cluster the logging functionality above started working.

like image 116
medium Avatar answered Sep 30 '22 23:09

medium