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
    #
    loggerfilter:
        # This filter must be enabled when busmonitor logging from the knx plugin should be used.
        (): lib.logutils.Filter
        name: knx_busmonitor


handlers:

    shng_warnings_file:
        # This handler writes only entries with level 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 WARNING!
        #
        # The TimedRotatingFileHandler seperates the logentries by day and
        # keeps the entries of the last seven days in seperate files.
        #
        class: logging.handlers.TimedRotatingFileHandler
        formatter: shng_simple
        level: WARNING
        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.
        #
        class: logging.handlers.TimedRotatingFileHandler
        formatter: shng_simple
        level: DEBUG
        utc: false
        when: midnight
        backupCount: 7
        filename: ./var/log/smarthome-details.log
        encoding: utf8

    #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.
    #    #
    #    class: logging.handlers.TimedRotatingFileHandler
    #    formatter: shng_detail
    #    level: DEBUG
    #    utc: false
    #    when: midnight
    #    backupCount: 7
    #    filename: ./var/log/smarthome-develop.log
    #    encoding: utf8

    #shng_busmonitor_file:
    #    # This handler must be enabled when busmonitor logging from the knx plugin should be used.
    #    #
    #    class: logging.handlers.TimedRotatingFileHandler
    #    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
    #    #
    #    class: logging.handlers.TimedRotatingFileHandler
    #    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.
    #
    lib:
        # Default logger for SmartHomeNG libraries
        handlers: [shng_details_file]
        level: WARNING

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

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

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

    # plugins.cli:
    #     # Example for changing the loglevel for a specific plugin (cli plugin)
    #     # a handler should only be specified, if logging should be done to
    #     # another destination, otherwise duplicate log entries could be produced.
    #     level: INFO

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

    logics:
        # Default logger for SmartHomeNG logics
        # to change the loglevel for all logics, the level can be changed.
        # Alternatively individual loggers for certain logics can be added.
        handlers: [shng_details_file]
        level: WARNING

    # logics.ex_logging:
    #     # Example of a logger for a specific logic (configured as ex_logging in logics.yaml)
    #     #
    #     level: INFO

    # logics.ex_logging2:
    #     # Example of a logger for a specific logic (configured as ex_logging2 in logics.yaml)
    #     # This logger logs info for the logic to another file (logics_file). (WARNINGs will still be
    #     # logged to shng_details_file.
    #     #
    #     handlers: [logics_file]
    #     level: INFO

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

    # items.temperatures:
    #     # Logging items with configuration: log_change: temperatures
    #     #
    #     handlers: [shng_details_file]
    #     level: INFO

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

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

    # 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
    # ----------------

    __main__:
        # 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).
        #
        # 2019-02-26  22:42:27 WARNING  __main__            --------------------   Init SmartHomeNG 1.5d.5a01c53f.develop   --------------------
        # 2019-02-26  22:42:27 WARNING  __main__            Running in Python interpreter 'v3.6.5 final' (pid=25878) on linux platform
        #
        handlers: [shng_details_file]
        #handlers: [shng_details_file,shng_develop_file]

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


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.