How-To: Implement Logging¶
When implementing a new feature, make sure to implement logging. This can be
done by utilizing the nessy logging package. The package provides a
LoggingMixin class, that
new classes can inherit from. This way, the logging configuration is inherited
and the new class can log messages.
The LoggingMixin differentiates between two types of loggers:
- get_console_logger(): This logger is used for logging messages to the console. It is useful for debugging and informational purposes.
- get_tabular_logger(): This logger is used for logging messages in a tabular format. It is useful for logging structured data and persisting it.
Check the Reference!
Details on how to use the LoggingMixin can be found in the Code
Reference.
Configuration of Loggers¶
The configuration details can be found in the User Guides Logging Section.
Examples¶
Here are some examples on how to use the LoggingMixin:
from cloe_nessy.logging import LoggingMixin
class MyNewClass(LoggingMixin):
    def __init__(self):
        # This will add a regular logger that prints to the console.
        self._console_logger = self.get_console_logger()
        # This will add a tabular logging, where the log messages
        # persisted in a tabular format. The target can be defined
        # via environment variables or when calling the method.
        self._tabular_logger = self.get_tabular_logger(
            add_log_analytics_logger = True,
            log_type = "MyNewClass"
        )
        # use the loggers as you would use any other logger
        self.console_logger.info("MyNewClass was initialized.")
        # keep in mind that the tabular logger logs in a tabular format
        # the key and value separators can be defined
        self.tabular_logger.info("COL1 : VALUE | COL2 : VALUE2")