Setting Log Levels for a Specific Class

Setting the log level involves invoking the MBean which controls the logging service.

images/download/attachments/144836408/montest_3-version-1-modificationdate-1645139253000-api-v2.png

Since a One Network Platform Instance may contain many applications, it is critical to be able to make fine-grained choices about how the system and application generated messages are recorded to the logs.

If you look carefully at the logger configuration page of the JMX Console, you may notice it appears the same logger method appears multiple times. It's not uncommon in Java to create overloaded methods which take different numbers of arguments. That's what you're seeing here. The JMX Console is showing you a user interface based on the public methods within a collection of MBeans. The method we just invoked is a very broad setting. It sets the log level for the entire system.

Fortunately, we can. You can affect the log level of individual applications. For example, we can set the logger for the Bookstore Application, built in the Training Guide, by using the setDebugLevel which takes two arguments. In this case we are going to target the log messages generated by the REST resources packages, perhaps in the hopes of finding an issue related to a custom user interface page we might have created.

You can set the log level to any valid setting by typing the setting into the ParamValue box and pressing the Invoke button. The valid settings are listed right column, in this case in increasing order of verbosity:

  • FATAL - show only catastrophic, stop-the-world errors. This is the least verbose setting.

  • ERROR - show only errors, of varying severity.

  • WARN - show only warnings.

  • INFO - shows informational messages. This is the default log level

  • DEBUG_SQL - displays debug messages related to SQL queries. This is very useful for reviewing SqlDefs and generated SQL queries because it displays the SQL as its running along with any parameters used for the query.

  • DEBUG - displays debug messages. This is a common setting for developers and is usually verbose enough for most debugging needs. This should only be enabled at a specific class level, never globally.

When you set a new log level, you will see the new settings take effect immediately. No restart is required. The logger changes are available until you change them back or until you restart the server.

IMPORTANT: Changing base logger level may print excessive amount of information to the log and can actually make it more challenging to debug issues. That's why careful consideration is required. Changing log levels for specific classes or packages may yield better results for developers.

images/download/attachments/144836408/montest_6-version-1-modificationdate-1645139262000-api-v2.png

To invoke a log level on a particular class, fill in the class name in the first box, labeled LoggerName. For example, to target the REST resource classes in the Bookstore Application created in the Training Guide, we could fill in com.mybooks.rest.SampleResource. As before, fill in the log level you wish to invoke based on the values listed in the right-most column (WARN, INFO, etc.) using the box labeled LogLevel. Click the Invoke button and your changes will immediately appear. No restart of the server is required. The logger changes are available until you change them back or until you restart the server.