如何使用Log4j和Storm Framework将日志写入文件? [英] How to write logs to a file using Log4j and Storm Framework?

查看:307
本文介绍了如何使用Log4j和Storm Framework将日志写入文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用log4j在风暴中登录文件时遇到了一些问题。

I am having bit of an issue in logging to a file using log4j in storm .

在提交我的拓扑之前,即在我的main方法中,我写了一些日志语句并使用以下命令配置记录器:

Before submitting my topology , i.e in my main method I wrote some log statements and configured the logger using :

PropertyConfigurator.configure(myLog4jProperties)




  • 现在我在eclipse中使用可执行jar 运行我的拓扑 -
    工作正常和日志文件正在创建假设。



    当我使用java -jar MyJarFile
    someOtherOptions运行我的可执行jar时,我可以看到log4j正在已配置且文件正确形成
    并且在文件和控制台上都进行了日志记录(如我的log4j.properties中定义的

    • Now when I run my topology using my executable jar in eclipse - its working fine and log files are being created as supposed.
      OR
      When i run my executable jar using "java -jar MyJarFile someOtherOptions", i can see log4j being configured and the files are formed correctly and logging is done on both files and console (as defined in my log4j.properties)

      但是当我使用风暴jar MyJarFile MyMainClass someOtherOptions运行相同的jar时,它无法创建并将
      记录到除控制台之外的任何文件中。

      BUT when i run the same jar using "storm jar MyJarFile MyMainClass someOtherOptions" it is not being able to create and log into any of the files except on console.

      我在说ab我正在打印日志之前提交我的拓扑。

      I am talking about the logs I am printing BEFORE submitting my topology.

      在使用storm时,有没有办法在文件中记录我的语句?我约束使用 org.apache.log4j

      Is there any way to log my statements in a file while using storm ? I am not bound to use org.apache.log4j.

      推荐答案

      我建议使用SLF4J进行风暴日志记录。您可能可以使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.

      在你的项目中,包括这些maven依赖项(slf4j-simple用于你的单元测试!) :

      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>
      

      然后,在您的拓扑/ spouts / bolt中,您只需获取Logger:

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

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

      在我的环境中,任何INFO及以上版本都会记录到文件中,更重要的是,可见在风暴UI中。您只需要单击您的喷口/螺栓,然后单击端口号即可转到日志查看器页面。

      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.

      如果你想获得实际文件,那么你可以从每个节点收集它们(我的是 / var / log / storm / )。

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

      这篇关于如何使用Log4j和Storm Framework将日志写入文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆