Skip to content

Logging

Few words about logging

There is a total of 4 logger included in the Phaistos package:

  1. PHAISTOS (T): This logger is used by the Transpiler class to log messages related to the transpilation process.
  2. PHAISTOS (M): This logger is used by the Manager class to log messages related to the schema management.
  3. PHAISTOS (C): This logger is used by the Compiler class to log messages related to the compilation process.
  4. PHAISTOS (V): This logger is used by the Manager class to log messages related to the validation process i.e. things that happen inside custom validators.

The logging level for all the loggers is set to INFO by default.

Do You want to create a custom logger for Phaistos? You can do it by using the phaistos.utils.setup_logger function:

from phaistos import utils

logger = utils.setup_logger('MyLogger', level='DEBUG')

This will create a logger named MyLogger with the logging level set to DEBUG. You can use this logger to log messages in your custom code.

phaistos.utils.setup_logger

Source code in phaistos/utils.py
18
19
20
21
22
23
24
25
26
27
28
29
30
31
def setup_logger(logger_name: str) -> logging.Logger:
    logging.basicConfig(level=logging.INFO)
    new_logger = logging.getLogger(logger_name)
    new_logger.propagate = False
    new_logger.handlers.clear()
    log_formatter = logging.Formatter(
        fmt='%(asctime)s - %(levelname)s - %(name)s - %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S'
    )
    log_handler = logging.StreamHandler()
    log_handler.setFormatter(log_formatter)
    new_logger.addHandler(log_handler)
    new_logger.setLevel(logging.DEBUG)
    return new_logger