Java 如何禁用/关闭 Storm 的日志记录功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18206821/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to disable/turn off the logging feature from Storm
提问by Amol M Kulkarni
I want to turn off the logging feature offered by default when we run from local cluster. Currently its logging so many information on the console.
当我们从本地集群运行时,我想关闭默认提供的日志记录功能。目前它在控制台上记录了这么多信息。
Below is the example of log:
下面是日志的例子:
261 [main] INFO backtype.storm.daemon.task - Shut down task Getting-Started-Toplogie-1-1376388324:2
2261 [main] INFO backtype.storm.daemon.task - Shutting down task Getting-Started-Toplogie-1-1376388324:1
2262 [Thread-24] INFO backtype.storm.util - Async loop interrupted!
2276 [main] INFO backtype.storm.daemon.task - Shut down task Getting-Started-Toplogie-1-1376388324:1
2278 [main] INFO backtype.storm.daemon.worker - Terminating zmq context
2279 [main] INFO backtype.storm.daemon.worker - Disconnecting from storm cluster state context
2279 [main] INFO backtype.storm.daemon.worker - Waiting for heartbeat thread to die
2279 [Thread-27] INFO backtype.storm.util - Async loop interrupted!
2308 [main] INFO backtype.storm.testing - Shutting down in process zookeeper
2309 [main] INFO backtype.storm.testing - Done shutting down in process zookeeper
2309 [main] INFO backtype.storm.testing - Deleting temporary path /tmp/255fe7c8-1407-4f43-8771-2217905232ab
After going through many docs, I ended up with the below code, I am able to turn off the logging from within class.
在浏览了许多文档后,我最终得到了以下代码,我可以从课堂内关闭日志记录。
static Logger logger = Logger.getLogger(TopologyMain.class);
public static void main(String[] args) throws InterruptedException, AlreadyAliveException, InvalidTopologyException {
logger.setLevel((Level) Level.FATAL);
logger.debug("Here is some DEBUG");
logger.info("Here is some INFO");
logger.warn("Here is some WARN");
logger.error("Here is some ERROR");
logger.fatal("Here is some FATAL");
}
}
Output (correct) : 0 [main] FATAL TopologyMain - Here is some FATAL
输出(正确): 0 [main] FATAL TopologyMain - Here is some FATAL
But I require to change the logging configure of storm/zookeper,etc..
但是我需要更改storm/zookeper等的日志配置。
Could anyone please help on this?
有人可以帮忙吗?
Update更新:以下是我尝试过的代码,但它不起作用。我尝试了 0.7.1、0.8.2 和 0.9.0-wip*
//Configuration
Config conf = new Config();
conf.put(Config.TOPOLOGY_DEBUG, false); //Tried this alone
conf.setDebug(false); //Tried this alone & tried both together as well.. No change :-(
采纳答案by Chiron
Storm is really chatty and tells a lot of information but if you want to silence it, you can set Config.TOPOLOGY_DEBUGto false.
Storm 真的很健谈并且会告诉很多信息,但是如果你想让它静音,你可以将Config.TOPOLOGY_DEBUG设置为 false。
When you set Config.TOPOLOGY_DEBUG to true, you are telling Storm to log a message every time a tuple is emitted from any spout or bolt.
当您将 Config.TOPOLOGY_DEBUG 设置为 true 时,您是在告诉 Storm 每次从任何 spout 或 bolt 发出元组时都记录一条消息。
回答by user2435082
Add below code in log4j.xml.It will just print your intended logs and console outputs :-
在 log4j.xml 中添加以下代码。它只会打印您想要的日志和控制台输出:-
<logger name="org.apache.zookeeper">
<level value="warn"/>
</logger>
<logger name="backtype.storm">
<level value="warn"/>
</logger>
<logger name="com.netflix">
<level value="warn"/>
</logger>
And use Logger.getLogger(Class) in your classes.
并在您的课程中使用 Logger.getLogger(Class)。
回答by Jirka
This works for me (storm version 0.9.0.1):
这对我有用(风暴版本 0.9.0.1):
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout(..);
builder.setBolt(..);
:
Config conf = new Config();
conf.put(Config.TOPOLOGY_DEBUG, false);
LocalCluster cluster = new LocalCluster();
cluster.submitTopology("topologyName", conf, builder.createTopology());
回答by user2720864
There is a nice documentation on setting up the log level dynamically. It can be done through the UI as well as using the CLI. The later looks better to me. Once you start the topology you can simply use the following command (from inside Storm's installation directory):
关于动态设置日志级别有一个很好的文档。它可以通过 UI 以及使用 CLI 来完成。后者在我看来更好。启动拓扑后,您只需使用以下命令(从 Storm 的安装目录中):
./bin/storm set_log_level [topology name] -l [logger name]=[LEVEL]:[TIMEOUT]
For more details please check this link
有关更多详细信息,请查看此链接
回答by mephicide
I found this question when attempting to evaluate Storm using a local testing environment. I created a project depending on storm-core
version 1.1.0
, which is the latest stable release at the time of this writing, so I don't know if this applies for anyone else.
我在尝试使用本地测试环境评估 Storm 时发现了这个问题。我根据storm-core
version创建了一个项目1.1.0
,这是撰写本文时最新的稳定版本,所以我不知道这是否适用于其他任何人。
Inspecting the Maven dependencies, and expanding the contents of the storm-core-1.1.0.jar
revealed that the configuration file for the library's log4j logging dependency was called log4j2.xml
. With the realization that the logging mechanism was log4j 2, I consulted the documentation here: https://logging.apache.org/log4j/2.x/manual/index.htmlI created a new log4j2.xml
file under src/main/resources
(my project is Maven-configured, so this is at the classpath root). I started by copying the contents of the existing file, and changing the log levels for the specified loggers to "OFF":
检查 Maven 依赖项,并展开其中的内容,storm-core-1.1.0.jar
发现库的 log4j 日志记录依赖项的配置文件被调用log4j2.xml
。意识到日志记录机制是 log4j 2,我查阅了这里的文档:https: //logging.apache.org/log4j/2.x/manual/index.html我在下面创建了一个新log4j2.xml
文件src/main/resources
(我的项目是 Maven-配置,所以这是在类路径根)。我首先复制现有文件的内容,并将指定记录器的日志级别更改为“OFF”:
<?xml version="1.0" encoding="UTF-8"?>
<configuration monitorInterval="60">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%-4r [%t] %-5p %c{1.} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.zookeeper" level="OFF"/>
<Root level="OFF">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</configuration>
Running a "hello world" example, regardless of the setting of conf.debug()
indicates that - since there is now no mechanism by which logging should be possible at all - the logs (most usefully System.out) are now dead silent, except for the invocations of System.out.println()
I placed in my test spouts / bolts. This is exactly what I wanted! Hopefully this helps someone other than me!
运行“hello world”示例,无论 的设置如何conf.debug()
表示 - 由于现在根本没有可以进行日志记录的机制 - 日志(最有用的是 System.out)现在是死寂的,除了调用System.out.println()
我放入了我的测试喷口/螺栓。这正是我想要的!希望这对我以外的人有所帮助!
回答by dan Zhang
Creat a file "log4j2.xml" in src/main/resources (Maven project) works for me!
在 src/main/resources(Maven 项目)中创建一个文件“log4j2.xml”对我有用!
<Loggers>
<Logger name="org.apache.storm" level="OFF"/>
<Logger name="org.apache.zookeeper" level="OFF"/>
<Root level="OFF">
<AppenderRef ref="Console"/>
</Root>
</Loggers>