logging.yaml

Der Core von SmartHomeNG und jedes Modul/Plugin ist in der Lage Logging Informationen auszugeben. Das Logging kann so konfiguriert werden, das für Debugging viele Detailinformationen geloggt werden, oder für den normalen Betrieb so, dass nur wichtige bzw. kritische Informationen geloggt werden.

Es existiert eine separate Seite, auf der erklärt wird wie das Logging im einzelnen konfiguriert werden kann. Zum Start reicht es die Einstellungen zu verwenden, wie si in der Datei logging.yaml.default vorgegeben sind. Einfach diese Datei zu logging.yaml kopieren und nach den eigenen Bedürfnissen anpassen. Die Konfiguration sollte in etwa so aussehen:

logging.yaml
%YAML 1.1
---
version: 1
disable_existing_loggers: false

formatters:

    # The following sections define the output formats to be used in the different logs
    #
    shng_simple:
        format: '%(asctime)s %(levelname)-8s %(name)-19s %(message)s'
        datefmt: '%Y-%m-%d  %H:%M:%S'

    shng_detail1:
        format: '%(asctime)s %(levelname)-8s %(module)-17s %(threadName)-12s %(message)s  --  (%(filename)s:%(funcName)s:%(lineno)d)'
        datefmt: '%Y-%m-%d %H:%M:%S %Z'

    shng_detail2:
        format: '%(asctime)s %(levelname)-8s %(name)-19s %(module)-19s %(funcName)-12s ln:%(lineno)-3d %(message)s  ----  %(threadName)-12s '
        datefmt: '%Y-%m-%d %H:%M:%S %Z'

    shng_items:
        format: '%(asctime)s %(levelname)-8s %(module)-12s %(message)s'
        datefmt: '%Y-%m-%d %H:%M:%S'

    shng_busmonitor:
        # This formatter must be enabled when busmonitor logging from the knx plugin should be used.
        format: '%(asctime)s;%(message)s;'
        datefmt: '%Y-%m-%d;%H:%M:%S'


filters:

    # The following sections define filters that can be used for different logs
    #
    knx_filter:
        # This filter must be enabled when busmonitor logging from the knx plugin should be used.
        # It filters all log entries coming from the logger named knx_busmonitor (that is initialized in the KNX plugin)
        (): lib.logutils.Filter
        name: knx_busmonitor

    filter_example:
        # This filter hides all messages from logger module "item" with messages containing "This is a very nice filter"
        (): lib.logutils.Filter
        module: item
        msg: "This is a very nice filter"
        # The next invert: True parameter would ONLY show messages matching both module and msg parameters and nothing else
        #invert: True


handlers:

    shng_warnings_file:
        # This handler writes only entries with level NOTICE/WARNING and above
        # to the file. This allows for a quick check if all is running smooth.
        #
        # To keep the warnings file easy readable, the level should always be NOTICE!
        #
        # The TimedRotatingFileHandler seperates the logentries by day and
        # keeps the entries of the last seven days in seperate files.
        #
        #class: logging.handlers.TimedRotatingFileHandler
        (): lib.log.ShngTimedRotatingFileHandler
        formatter: shng_simple
        level: NOTICE
        utc: false
        when: midnight
        backupCount: 7
        filename: ./var/log/smarthome-warnings.log
        encoding: utf8

    shng_details_file:
        # This handler writes all entries to the details-file. Log entries with level WARNING
        # and above are additionally written to the warnings-file (through the root logger).
        #
        # The TimedRotatingFileHandler seperates the logentries by day and
        # keeps the entries of the last seven days in seperate files.
        #
        (): lib.log.ShngTimedRotatingFileHandler
        formatter: shng_simple
        level: DEBUG
        utc: false
        when: midnight
        backupCount: 7
        filename: ./var/log/smarthome-details.log
        encoding: utf8
        filters: [knx_filter]

    #develop_file:
    #    # This handler should be used for development purposes. It writes all entries to
    #    # the develop-file. Log entries with level WARNING and above are additionally written
    #    # to the warnings-file (through the root logger).
    #    #
    #    # The TimedRotatingFileHandler seperates the logentries by day and
    #    # keeps the entries of the last seven days in seperate files.
    #    #
    #    (): lib.log.ShngTimedRotatingFileHandler
    #    formatter: shng_detail
    #    level: DEBUG
    #    utc: false
    #    when: midnight
    #    backupCount: 7
    #    filename: ./var/log/smarthome-develop.log
    #    encoding: utf8
    #    filters: [filter_example]

    #shng_busmonitor_file:
    #    # This handler must be enabled when busmonitor logging from the knx plugin should be used.
    #    #
    #    (): lib.log.ShngTimedRotatingFileHandler
    #    formatter: shng_busmonitor
    #    level: DEBUG
    #    when: midnight
    #    backupCount: 7
    #    encoding: utf8
    #    filename: ./var/log/knx_busmonitor.log

    #shng_items_file:
    #    # This handler is an example for logging item-value changes to a seperate log file
    #    #
    #    (): lib.log.ShngTimedRotatingFileHandler
    #    formatter: shng_items
    #    when: midnight
    #    backupCount: 7
    #    filename: ./var/log/item-value-change.log
    #    encoding: utf8

    #console:
    #    class: logging.StreamHandler
    #    formatter: shng_simple
    #    stream: ext://sys.stdout

loggers:
    # The following default loggers should not be changed. If additional logging
    # is required, a logger for the specific lib, module or plugin shoud be added.
    #
    functions:
        handlers: [shng_details_file]
        level: NOTICE

    lib:
        # Default logger for SmartHomeNG libraries
        handlers: [shng_details_file]
        level: NOTICE

    lib.smarthome:
        # Add all logging handlers that should receive the initial log lines after a startup
        # (example below) but leave out the logging handlers that are defined in the root-logger
        # (otherwise log entries will be doubled).
        #
        # 2020-12-29  11:35:34 NOTICE  lib.smarthome   --------------------   Init SmartHomeNG 1.8.0   --------------------
        # 2020-12-29  11:35:34 NOTICE  lib.smarthome   Running in Python interpreter 'v3.8.3 final' in virtual environment
        # 2020-12-29  11:35:34 NOTICE  lib.smarthome    - on Linux-4.9.0-6-amd64-x86_64-with-glibc2.17 (pid=24407)
        # 2020-12-29  11:35:35 NOTICE  lib.smarthome    - Nutze Feiertage für Land 'DE', Provinz 'HH', 1 benutzerdefinierte(r) Feiertag(e) definiert
        # 2020-12-29  11:36:54 NOTICE  lib.smarthome   --------------------   SmartHomeNG initialization finished   --------------------
        #
        # logging to shng_details_file is already enabled in logger lib:
        #handlers: [shng_develop_file]

        # set to WARNING LEVEL to prevent unwanted log entries and add ONLY start and stop log-messages to further logfiles
        level: NOTICE

    modules:
        # Default logger for SmartHomeNG modules
        handlers: [shng_details_file]
        level: NOTICE

    plugins:
        # Default logger for SmartHomeNG plugins
        handlers: [shng_details_file]
        level: NOTICE

    logics:
        # Default logger for SmartHomeNG logics
        handlers: [shng_details_file]
        level: NOTICE

    # ------------------------------------------

    items:
        # Default logger for SmartHomeNG logics
        handlers: [shng_details_file]
        level: NOTICE

    # items.temperatures:
    #     # Logging items with configuration: log_change: temperatures
    #     #
    #     # handlers: [shng_develop_file]   # Hier keinen ererbten Handler (aus items: logger oder root: logger) erneut eintragen
    #     level: INFO

    # items.new_device:
    #     # Logging items with configuration: log_change: new_device
    #     # to a different file
    #     #
    #     handlers: [shng_items_file]
    #     level: DEBUG

    # ------------------------------------------

    # plugins.avm:
    #     # handlers: [shng_develop_file]   # Hier keinen ererbten Handler (aus plugins: logger oder root: logger) erneut eintragen
    #     level: INFO

    # ------------------------------------------

    # knx_busmonitor:
    #     # This logger must be enabled when busmonitor logging from the knx plugin should be used.
    #     level: INFO
    #     handlers: [shng_busmonitor_file]

    # ------------------------------------------

    # Some Python packages log to loggers defined by the package itself. Such
    # loggers could be configured analog to the other loggers described above.
    # Some Examples are listed below.
    #

    # cherrypy.error:
    #     # Error logging for the cherrypy package
    #     handlers: [shng_details_file]
    #     level: INFO

    # jinja2:
    #     # Logger for the Jinja2 template engine
    #
    #     handlers: [shng_details_file]
    #     level: INFO


    # ================
    # special loggers
    # ----------------


root:
    # This is the configuration of the root logger. Additionally to be written to other logs,
    # ALL entries are handed to this logger. To keep the warnings file easy readable,
    # the level should always be WARNING!
    #
    # Logging of details (level INFO and DEBUG) should be handled by other loggers and written
    # to other log files than the warnings file.
    #
    level: WARNING
    handlers: [shng_warnings_file]

Weitere Details sind unter logging zu finden.