The Logging Extension includes the LoggingLogHandler, and provides log handling based on the standard logging library.

Documentation References:

API References:


  • No external dependencies


Application Configuration Settings

This handler honors the following settings under a [log.logging] section of the configuration:

A sample config section might look like:

file = /path/to/config/file
level = info
to_console = true
rotate = true
max_bytes = 512000
max_files = 4

Toggle Log Level via Command-line

This extension supports an optional feature to add a command-line argument to toggle the log level. This feature is not enabled by default for one specific reason: the log level will not be modified until after argument parsing happens. This can lead to a lot of confusion for developers who might not see their debug logs from a pre_setup hook, or anything that happens before argument parsing completes. For this reason, you should use this feature with caution and thus we disable it by default.

You can enable the log level argument by setting via App.Meta.meta_defaults for the log.logging handler:

from cement import App, init_defaults

META = init_defaults('log.logging')
META['log.logging']['log_level_argument'] = ['-l', '--level']

class MyApp(App):
    class Meta:
        label = 'myapp'
        meta_defaults = META


See the Logging Documentation.

Last updated