Customizing the log file

You can customize the logging process to track the Wazi Deploy execution messages and errors, and write them to the log file.

To do so, you must specify a --logConfigFile argument in The Wazi Deploy packager command and The Wazi Deploy generation command. If you do not, then the default logging process applies when you run Wazi Deploy.

By default, the messages are written to the message.log file. The logging process is managed in a logging.yml file.

You cannot modify the default Wazi Deploy logging.yml file. So, if you want to customize the logging process, you must create your own logging.yml file, copy and paste the following code, and adapt it to your needs.
version: 1

formatters:
   default:
      format: '%(asctime)s - %(levelname)-5s - %(message)s'
      datefmt: '%Y-%m-%d %H:%M:%S'
      
handlers:
   console:
      class: logging.StreamHandler
      level: INFO
      formatter: default
      stream: ext://sys.stdout
   file:
      class : logging.handlers.RotatingFileHandler
      formatter: default
      filename: message.log
      maxBytes: 1024000
      backupCount: 3
      
root:
   level: NOTSET
   handlers: [console]
   propagate: yes
   
loggers:
   log-deploy:
      level: INFO
      handlers: [file]
      propagate: no

To understand this file, you must read it from the end. Only the Wazi Deploy specific information is explained. The other information is standard logging information.

The loggers block contains the following information:
  • log-deploy is the required logger name. If you enter another name, the log information is displayed in the console only, and not in the log file.
  • level is the level of the log that is written to the log file. The levels that can be output by Wazi Deploy are INFO (default) and DEBUG. The DEBUG level is more verbose than the INFO level, as it gives troubleshooting information.
    Note: The level does not apply to the messages that are displayed in the console.
  • handlers: [file] refers to the file handler that is defined in the handlers block.

The handlers block contains the file handler, which is defined with a logging.handlers.RotatingFileHandler class. It means that when the size of the log file (filename: message.log) exceeds the maxBytes number, it creates a second log file (message2.log). When the size of the second log also exceeds the maxBytes number, it creates a third log file (message3.log). Such is the purpose of backupCount: 3. When the third log file exceeds the maxBytes number, it reuses the first log file. This rotating file handler prevents the creation of too many files in your execution directory.

The formatters block contains the format of the messages that are written to the log file. By default, the messages are constituted of the following elements, separated by a dash (-):
  • %(asctime)s for the data and time of the message creation.
  • %(levelname)-5s for the message level. The possible levels are specified in the loggers block.
  • %(message)s for the message that explains the origin of the error. This message is constituted of the following parts:
    1. The element, line and file where the error was detected.
    2. The message itself.
The following line is an example of a standard message:
2023-05-15 15:44:07 - INFO - deployment_method_manager.py, line 31, in load_deployment_method_from_yaml_file : \* Read the deployment method from: xxxxxx

The logging process is a Python process. You can refer to the Python documentation for general and exhaustive information about the logging process.