How to write logs to a file using Log4j and Storm Framework?

筅森魡賤 提交于 2019-12-03 13:49:51

The storm framework uses its own logging. Your logs most likely will end up in the logs dir where storm is installed({Storm DIR}/logs). You can find the storm log properties in {Storm DIR}/logback/cluster.xml. It uses logback not log4j

I would recommend using SLF4J for your logging within storm. You probably could get LOG4J working but you will have additional setup to do on each node in the cluster. Since storm does this for you already, I don't really see the point.

In your project, include these maven dependencies (slf4j-simple for your unit tests!):

<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-api</artifactId>
  <version>1.7.5</version>
</dependency>
<dependency>
  <groupId>org.slf4j</groupId>
  <artifactId>slf4j-simple</artifactId>
  <version>1.7.5</version>
  <scope>test</scope>
</dependency>

Then, inside your topologies/spouts/bolts you just get the Logger:

private static final Logger LOG = LoggerFactory.getLogger(MySpout.class);

In my environment, anything INFO and above is logged to file and, more importantly, visible in the Storm UI. You just need to click on your spout/bolt and then click on the port number to go to the log viewer page.

If you want to get to the actual files then you can gather them off of each node (mine are in /var/log/storm/).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!