i have the following ColoeredFormatter in my Module.
But The Formatter does not get called. I expect "hi" on the console, but i get "This is an info of the root logger".
i've already deleted all .pyc files, but it did not help.
MyModule/__init__.py
from MyModule.ColoredFormatter import ColoredFormatter
__all__ = ('ColoredFormatter')
MyModule/ColoredFormatter.py
import logging
class ColoredFormatter(logging.Formatter):
def __init__(self, default):
self.default = default
def format(self, record):
print("hi")
record.msg = "hi"
return self.default.format(record)
My Script
import logging, logging.config, yaml
conf="""
logging:
version: 1
disable_existing_loggers: true
root:
level: !!python/name:logging.NOTSET
handlers: [console]
handlers:
console:
class: logging.StreamHandler
stream: ext://sys.stdout
formatter: myFormatter
level: !!python/name:logging.NOTSET
formatters:
myFormatter:
class: !!python/name:MyModule.ColoredFormatter
"""
dict = yaml.parse(conf)
logging.config.dictConfig(dict["logging"])
logging.info("This is an info of the root logger")
in the formatter section i had to replace class
by ()
import logging, logging.config, yaml
conf="""
logging:
version: 1
disable_existing_loggers: true
root:
level: !!python/name:logging.NOTSET
handlers: [console]
handlers:
console:
class: logging.StreamHandler
stream: ext://sys.stdout
formatter: myFormatter
level: !!python/name:logging.NOTSET
formatters:
myFormatter:
'()': MyModule.ColoredFormatter
"""
dict = yaml.parse(conf)
logging.config.dictConfig(dict["logging"])
logging.info("This is an info of the root logger")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With