New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Question] How to use Loguru defaults + and extra information? #586
Comments
Hi @antusystem. I think you simply need to logger_format = (
"<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | "
"<level>{level: <8}</level> | "
"<cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> | "
"{extra[ip]} {extra[user]} - <level>{message}</level>"
)
logger.configure(extra={"ip": "", "user": ""}) # Default values
logger.remove()
logger.add(sys.stderr, format=logger_format) |
Thanks I believe that works for me, I just need to configure the IP and USER for every run, think that with bind or opt I can change that easily, I believe I see it in the tutorial, I will check it later. Another question I just remember (and try it but I want to be sure). To log at TRACE level I would do this: EDIT: I saw the code in my first post and yes, with |
Indeed, you need to specify You can use |
Hi @Delgan, I added one extra parameter with
Regular logging with |
@rmaruseve Hi. Usually, arguments passed to a log function are intended to be used to format the message: logger.info("Return code: {code}", code=200)
# => "Return code: 200" In your case, the You can use logger.bind(ex="ex").info({'status': 200, 'json': 'json'}) Later I will provide a way to optionally disable message formatting, but it's not yet implemented. |
@Delgan hello, thanks for any reply in advance.
I did a practice, finding if |
@Ericwonne Not sure what you mean, the values are actually displayed as Please open a new ticket with a fully reproducible example so I can better help you. 👍 |
Each process now writes to its own log file. Documentation is in https://loguru.readthedocs.io/en/stable/overview.html For hints on how to format log message, see Delgan/loguru#586
Hi, I'm still researching about Loguru, but I can't find an easy way to do this. I want to use the default options from Loguru, I believe they are great, but I want to add information to it, I want to add the IP of a request that will be logged.
If I tried this:
That logs this:
I know that with logger.remove(0) I will remove the default logs, but I want to use it to obtain something like this:
2022-02-03 15:16:54.920 | INFO | __main__:<module>:79 - XXX.XXX.XX.X - Use kwargs to add context during formatting: anybody
, with XXX.XXX.XX.X being the IP. Using the default config (for color and the rest of thing) and adding a little thing to the format.I'm trying to access the default configs, but I haven't been able to import them and use them with logger.add. I think I will have to configure everything from scratch.
Hope someone can help me, thanks.
The text was updated successfully, but these errors were encountered: