0

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

1 Answer 1

0

i had to update args to *args in my console method -

def console(msg, *args, **kwargs): 
   if logging.getLogger().isEnabledFor(CONSOLE): 
      logging.log(CONSOLE, msg, *args, **kwargs)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.