Skip to content

Latest commit

 

History

History
61 lines (44 loc) · 2.08 KB

log_configuration.md

File metadata and controls

61 lines (44 loc) · 2.08 KB

Customizing logging

Simple log level modification

Configuration file (xmlcli.config) for this tool consists dedicated section [LOG_SETTINGS]

Using Logging with advanced customization

Importing module:

from xmlcli.common import logger

settings = logger.Setup(  # All setup arguments are optional/ if not specified default value will be overridden
        log_level="DEBUG",  # default level would be utils.LOG_LEVEL
        log_title="XmlCli",  # default to utils.LOGGER_TITLE (Avoid overriding this!!!)
        sub_module="XmlCliLib",  # To allow printing submodule name to logging, for better lookup to filter
        log_dir="absolute/path/to/log/directory/",  # defaults to utils.LOG_DIR
        log_file_name="name_of_log_file.log",  # defaults to title and timestamp
        write_in_file=True,  # Specifies whether to write the log in file or not defaults to utils.FILE_LOG
        print_on_console=True,  # Specifies whether to write log on console or not defaults to utils.CONSOLE_STREAM_LOG
    )

# To display config of system run below function:
settings.display_system_configs()

# Detailed logging for function entry point:
settings.display_system_configs()

# To log whether your script enters and exit to function along with the arguments feed to the function, add below line overridden any function/method:
@settings.log_function_entry_and_exit
def my_function(param1, param2):
    pass

This will log the details on when your script enters to function: my_function, lists the parameters and also logs when the script exits from the function scope.

Example:

from xmlcli.common.logger import settings

@settings.log_function_entry_and_exit
def process_ucode(Operation='READ', BiosBinaryFile=0, UcodeFile=0, ReqCpuId=0, outPath='', BiosBinListBuff=0, ReqCpuFlags=0xFFFF, PrintEn=True):
  # rest of the function definition..
  # calculation, etc.
  pass

logging individually as:

from xmlcli.common.logger import settings

log = settings.logger
log.debug("log message")
log.info("log message")
log.error("error message")