Suppressing entire log statements from "stdout", "stderr" or specific log category in JBoss EAP 6.x, 7.x, or 8.x
Environment
- Red Hat JBoss Enterprise Application Platform (EAP)
- 6.x
- 7.x
- 8.x
Issue
-
How to disable entire log statements from the
stdoutlog category (System.out) and thestderrlog category (System.err) in the JBoss EAP 6/7/8? -
How to suppress the
stdoutlog messages from server.log, but still output it to console output. -
We are dealing with vendor java software that is logging too much like the following stdout and filling up disk space. We needs to suppress these lines.
2018-09-05 15:08:41,777 INFO [stdout] (default task-47) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMetho 2018-09-05 15:08:41,777 INFO [stdout] (default task-47) Building the inner query ... 2018-09-05 15:08:41,808 INFO [stdout] (default task-47) No Filter Criterias, no where clause !! No need to fire inner query, as everything will be selected anyways ...dAccessorImpl.java:43) 2018-09-05 15:08:41,808 INFO [stdout] (default task-47) at java.lang.reflect.Method.invoke(Method.java:497) 2018-09-05 15:08:41,808 INFO [stdout] (default task-47) at org.apache.cxf.service.invoker.AbstractInvoker.performInvocation(AbstractInvoker.java:180) 2018-09-05 15:08:41,808 INFO [stdout] (default task-47) at org.apache.cxf.service.invoker.AbstractInvoker.invoke(AbstractInvoker.java:96) 2018-09-05 15:08:41,808 INFO [stdout] (default task-47) at org.apache.cxf.jaxws.AbstractJAXWSMethodInvoker.invoke(AbstractJAXWSMethodInvoker.java:178) 2018-09-05 15:08:41,808 INFO [stdout] (default task-47) at org.apache.cxf.jaxws.JAXWSMethodInvoker.invoke(JAXWSMethodInvoker.java:68) -
How to disable entire log statements from the specific
com.example.xyzlog category in the JBoss EAP 6/7/8?
Resolution
The stdout log category is output by System.out (e.g. System.out.println("foobar")), and the stderr log category is output by System.err (e.g. System.err.println("foobar")).
Given the large number of possible lines, filtering would not be practical. It is also not possible to suppress stack traces because , by that point, they are all just text to stdout. Anything other than simply suppressing all stdout and stderr requires the application's internal logging to be fixed.
At the JBoss EAP level, the only option is to disable the whole stdout and stderr log categories by using the following configurations:
-
To disable the
stdoutlog category in the logging subsystem:<logger category="stdout"> <level name="OFF"/> </logger>the above configuration can be done by the following CLI command when the
stdoutlog category is not yet configured in the logging subsystem:/subsystem=logging/logger=stdout:add(level=OFF)if the
stdoutlog category has already been configured in the logging subsystem, use the following CLI instead to change the log level toOFF:subsystem=logging/logger=stdout:write-attribute(name=level,value=OFF) -
To disable the
stderrlog category:<logger category="stderr"> <level name="OFF"/> </logger>the above configuration can be done by the following CLI command when the
stderrlog category is not yet configured in the logging subsystem:/subsystem=logging/logger=stderr:add(level=OFF)if the
stderrlog category has already been configured in the logging subsystem, use the following CLI instead to change the log level toOFF:subsystem=logging/logger=stderr:write-attribute(name=level,value=OFF)
To suppress the stdout and stderr log messages in server.log while still outputting them to the console output, specify use-parent-handlers="false" to disable the inheritance of the default logging handlers. Then configure a specific name for the ConsoleHandler logging handler (CONSOLE by default), as shown below:
<logger category="stdout" use-parent-handlers="false">
<handlers>
<handler name="CONSOLE"/> <!-- which is default name of logging handler for ConsoleHandler -->
</handlers>
</logger>"
<logger category="stderr" use-parent-handlers="false">
<handlers>
<handler name="CONSOLE"/> <!-- which is default name of logging handler for ConsoleHandler -->
</handlers>
</logger>"
the above configuration can be done by the following CLI command when the stderr log category is not yet configured in the logging subsystem:
/subsystem=logging/logger=stdout:add(use-parent-handlers=false,handlers=[CONSOLE])
/subsystem=logging/logger=stderr:add(use-parent-handlers=false,handlers=[CONSOLE])
if the stdout and stderr log categories has already been configured in the logging subsystem, use the following CLI instead:
/subsystem=logging/logger=stdout:write-attribute(name=use-parent-handlers,value=false)
/subsystem=logging/logger=stdout:write-attribute(name=handlers,value=[CONSOLE])
/subsystem=logging/logger=stdout:undefine-attribute(name=level)
/subsystem=logging/logger=stderr:write-attribute(name=use-parent-handlers,value=false)
/subsystem=logging/logger=stderr:write-attribute(name=handlers,value=[CONSOLE])
/subsystem=logging/logger=stderr:undefine-attribute(name=level)
The same configuration can be used for a specific log category (e.g. com.example.xyz in the following example) as well as stdout and stderr.
-
Disable the entire log messages from the specific log category
com.example.xyz:<logger category="com.example.xyz"> <level name="OFF"/> </logger>the above configuration can be done by the following CLI command when the log category is not yet configured in the logging subsystem:
/subsystem=logging/logger=com.example.xyz:add(level=OFF)if the log category has already been configured in the logging subsystem, use the following CLI instead to change the log level to
OFF:subsystem=logging/logger=com.example.xyz:write-attribute(name=level,value=OFF) -
To suppress the log messages from the
com.example.xyzlog category in server.log while still outputting them to the console output, specifyuse-parent-handlers="false"to disable the inheritance of the default logging handlers. Then configure a specific name for the ConsoleHandler logging handler (CONSOLEby default), as shown below:<logger category="com.example.xyz" use-parent-handlers="false"> <handlers> <handler name="CONSOLE"/> <!-- which is logging handler for ConsoleHandler --> </handlers> </logger>"
the above configuration can be done by the following CLI command when the log category is not yet configured in the logging subsystem:
/subsystem=logging/logger=com.example.xyz:add(use-parent-handlers=false,handlers=[CONSOLE])
if the log category has already been configured in the logging subsystem, use the following CLI instead:
/subsystem=logging/logger=com.example.xyz:write-attribute(name=use-parent-handlers,value=false)
/subsystem=logging/logger=com.example.xyz:write-attribute(name=handlers,value=[CONSOLE])
/subsystem=logging/logger=com.example.xyz:undefine-attribute(name=level)
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.