Hello, Delgan
I want to use the add () method to keep the log format of the console and output files consistent, as follows:
logger.add(sys.stderr, format="{time:YYYY-MM-dd HH:mm:ss.SSS} [{level}] [{file.name}]: {message}")
logger.add("file.log", format="{time:YYYY-MM-dd HH:mm:ss.SSS} [{level}] [{file.name}]: {message}")
logger.debug("This's a log message")
But when output to the console, there will be two logs, and the first log is loguru by default. Is there any way I can avoid this? Thank you very much!!!
The console log:
2020-12-12 19:17:41.419 | DEBUG | __main__:<module>:7 - This's a log message
2020-12-55 19:17:41.419 [DEBUG] [log_demo.py]: This's a log message
Hey @hege66. You need first to .remove() the default handler. :+1:
logger.remove() # Will remove all handlers added so far, including the default one
logger.add(sys.stderr, format="{time:YYYY-MM-dd HH:mm:ss.SSS} [{level}] [{file.name}]: {message}")
logger.add("file.log", format="{time:YYYY-MM-dd HH:mm:ss.SSS} [{level}] [{file.name}]: {message}")
logger.debug("This's a log message")
@Delgan
Hello, Delgan
Very fast and accurate answer, thank you very much for taking time out of your busy schedule to reply, thanks
Most helpful comment
Hey @hege66. You need first to
.remove()the default handler. :+1: