在WildFly中控制stderr和stdout输出

问题描述:

在我的应用程序中,我习惯了以下调试输出:通常,每个请求向stderr打印几行,但是将很多信息(通过log4j)记录到文件中.通常,对我来说,最重要的是stderr输出(这就是为什么我希望它简洁),但是当某些东西无法按预期工作时,我可以调查日志,每个请求很容易成千上万行.

In my application I got used to the following debug output: normally it prints a few lines per request to stderr, but logs a lot of information (via log4j) to a file. Typically, most important thing for me is the stderr output (that's why I want it concise), but when something doesn't work as expected, I can investigate the log, which can easily be thousands line per request.

现在,我将应用程序迁移到WildFly,我发现服务器通过其日志记录系统将所有stderr输出通过管道传输,因此看起来像这样:

Now that I'm migrating the application to WildFly, I found that the server pipes all stderr output through its logging system, so it looks like this:

14:06:15,464 ERROR [stderr] (default task-13) ACTUAL-DEBUG-OUTPUT

,并另外上色为错误.此外,stdout输出似乎已重定向到/dev/null ...

and is additionally colored as an error. Also, stdout output seems to be redirected to /dev/null...

我可以以某种方式将WildFly配置为仅使stderr输出通过,而不添加无用的(对我来说)噪声和着色吗?如果可能的话,我想对stdout做同样的事情.

Can I somehow configure WildFly to just let stderr output go through as is, without adding useless (for me) noise and coloring? If possible, I'd like to do the same for stdout.

好的,通过谷歌搜索和黑客入侵,我得到了想要的东西:

OK, with some googling and hacking I got what I want:

/subsystem=logging/console-handler=JUST-PRINT:add(formatter="%s%E%n")
/subsystem=logging/logger=stderr:add(use-parent-handlers="false", handlers=[JUST-PRINT])
/subsystem=logging/logger=stdout:add(use-parent-handlers="false", handlers=[JUST-PRINT])