Log
elva.log
Module specifying the logger context variable and the default formatter.
When writing an ELVA app, both objects are vital for a seamless integration into the suite.
Example:
import logging
from elva.log import LOGGER_NAME, DefaultFormatter
# Do not set LOGGER_NAME in the module's global scope
# as it would hold the wrong name in other modules
# importing from this one.
if __name__ == "__main__":
LOGGER_NAME.set(__name__)
# setup logging handler
handler = logging.FileHandler("./some.log")
handler.setFormatter(DefaultFormatter())
# add handler to module logger
log = logging.getLogger(__name__)
log.addHandler(handler)
Classes:
-
DefaultFormatter
–Default formatter for ELVA apps.
Attributes:
-
LOGGER_NAME
(ContextVar
) –Context variable supposed to hold the logger name.
LOGGER_NAME = ContextVar('logger_name')
module-attribute
Context variable supposed to hold the logger name.
This variable is read by the Component class on initialization.
DefaultFormatter()
Bases: Formatter
Default formatter for ELVA apps.
It extends log messages with the following scheme:
[<time>] [<log message level>] [<logger name>] <message>
where <time>
follows the ISO 8601 standard with
YYYY-MM-DD hh:mm:ss