question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

[Question] Configuring loguru in a library that pre-configure main logger

See original GitHub issue

I have a use case of deploying many microservices on multiple cloud provider environments (gcp, aws, azure)

Some of those Cloud Providers requires your applications to format logs in such a way so that it can be parsed automatically by other services. For example, Error Reporting in GCP requires a dedicated structure of logs to group exceptions and stacktraces.

I was wondering how to configure loguruā€™s logger in that case.

  1. Should I create a library that contains only format functions and let each microservice configure itā€™s own instance of loguru.logger?

  2. Should I preconfigure inside the library itself loguru.logger and import it directly in the apps? If so, were do I import it? In the root module __init__?

I am more likely to go for solution 2. but advices would be awesome!

I read both the README and the docs but I couldnā€™t find an answer for this. If you find this use case interesting, I am more than happy to add it to the docs afterwards!

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Delgancommented, May 21, 2022

Great! As it seems solved Iā€™m closing this issue then. šŸ˜‰

0reactions
MadJlzzcommented, May 21, 2022

Perfect! Super clear now. šŸ‘

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Complete Guide to Logging in Python with Loguru
The most basic way to use Loguru is by importing the logger object from the loguru package. This logger is pre-configured with a...
Read more >
Logger - loguru documentation - Read the Docs
An object to dispatch logging messages to configured handlers. The Logger is the core object of loguru , every logging configuration and usage...
Read more >
What's the best way to use Loguru in a library? #349 - GitHub
Hiya, i'm making a Python library and would like to use Loguru instead ... This allows to configure the logger from command line...
Read more >
A quick guide to using Loguru - Medium
Logging is essential in the field of software development. It helps programmers and system administrators understand the state of an applicationĀ ...
Read more >
loguru Documentation - Read the Docs
Also, this library is intended to make Python logging less ... Using the logger in your scripts is easy, and you can configure()...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found