MILC comes with a robust logging system based on python's
logging module. All you have to worry about are log messages, let MILC worry about presenting those messages to the user in configurable ways.
Writing Log Entries¶
A python Logger Object is available as
cli.log. You can use this to write messages at various log levels:
As is standard for the python logging module you can use
printf-style format string operations with these. Example:
log.info('Hello, %s!', cli.config.general.name)
ANSI color sequences are also available. For more information see the ANSI Color page.
All MILC programs have
--verbose flags by default. When this flag is passed
DEBUG level messages will be printed to the screen.
If you want to use this flag in your program you can check
cli.config.general.verbose. It is True when
--verbose is passed and False otherwise.
Controlling Log Output¶
Users have several CLI arguments they can pass to control the output of logs. These are automatically added to your program, you do not have to do anything to make them available:
- Default date/time format.
- Format string for printed log output
[%(levelname)s] [%(asctime)s] [file:%(pathname)s] [line:%(lineno)d] %(message)s
- Format string for log file.
--log-file, default: None
- File to write log messages to
- Enable or disable ANSI color
- Enable or disable unicode icons