Mayil-AI-Sandbox / loguru-Jan2023

MIT License
0 stars 0 forks source link

log is error in stdout. (hashtag626) #90

Closed vikramsubramanian closed 2 months ago

vikramsubramanian commented 2 months ago
loguru: 0.6.0
Python 3.8.12
from loguru import logger
import sys
format_ = '<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{file}</cyan>:<cyan>{' \
          'function}</cyan>:<cyan>Line:{line}</cyan>  - <level>{message}</level> '

logger.add("Log/runtime.log", rotation="00:00", level="DEBUG",
           filter=lambda record: record["extra"].get("name") == "log",
           encoding="utf-8", enqueue=True,
           format=format_)
hashtag logger.add(sys.stdout, format=format_)

logger_x = logger.bind(name="log")
logger_x.info("hello world")

output:

2022-03-28 16:42:59.866 | INFO     | log_utils.py:<module>:Line:13  - hello world 

stdout:

2022-03-28 16:42:59.866 | INFO     | __main__:<module>:13 - hello world

it is as expected in runtime.log. but it is error in stdout, I have no see filename in stdout. Please help check it. Thanks

vikramsubramanian commented 2 months ago

Make sure to [remove()]( the default handler first.

logger.remove()  hashtag Remove 'stderr' handler automatically added by default
logger.add("Log/runtime.log", rotation="00:00", level="DEBUG",
           filter=lambda record: record["extra"].get("name") == "log",
           encoding="utf-8", enqueue=True,
           format=format_)