I am trying to create a custom logger, where i want to print all the console level messages on stdout. and for remaining i dont want to give any handler in logging.
So i created a console level,
CONSOLE = 60 def console(msg, *args, **kwargs): if logging.getLogger().isEnabledFor(CONSOLE): logging.log(CONSOLE, msg, args, **kwargs)
logging.Logger.console = console
To get a logger which just prints console level log on stdout, I m using something like below code-
` logging.basicConfig(format="%(asctime)s %(name)s %(levelname)s %(message)s",level=logging.INFO, datefmt="%Y-%m-%d %H:%M:%S")
streamhandler = logging.StreamHandler()
streamhandler.setLevel(CONSOLE)
logging.getLogger('').addHandler(streamhandler)
logger = logging.getLogger("ABC")
logging.Logger.console = console`
but my error is -
22:46:55.280 ERROR Failed to log following message properly: This is my message 22:46:55.280 DEBUG TypeError: not all arguments converted during string formatting Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/logging/__init__.py", line 369, in getMessage msg = msg % self.args