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.

Modify logging format from imported module?

See original GitHub issue

Hi there.

I hope you don’t mind me posting another issue I have? I currently import a 3rd party package which produces quite a bit of log outputs. Is it possible to pipe this into Loguru and make it adhere to my defined log formatting? I don’t want to filter or disable it but change appearance…

Here are a couple of lines to illustrate it (last one is from my script and the desired format for all logs):

[2020-09-18 12:43:59,032][wetterdienst.data_collection][INFO] - No files found for precipitation/hourly/recent/station_id_2542. Station will be skipped.
[2020-09-18 12:43:59,065][wetterdienst.api][INFO] - Combination for precipitation/hourly/PeriodType.NOW does not exist and is skipped.
20-09-18 12:43:59.3 | WARNING  | preprocess.py.main:89 - Only using 2 stations for now (target, source): [2290, 2542]

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
cwernercommented, Sep 18, 2020

Excellent! wetterdienst_logger.propagate = False seems to do the trick 👍

Thanks for taking the time to guide me through the depths of python logging 😄

0reactions
Delgancommented, Sep 18, 2020

Maybe by adding wetterdienst_logger.propagate = False. 🤔

Otherwise, just remove all handlers. 😁

for log in [logging.root, wetterdienst_logger]:
    for handler in log.handlers:
        log.removeHandler(handler)
Read more comments on GitHub >

github_iconTop Results From Across the Web

how to modify python logging module name in formatter
1. in your format, you're specifying the logger name [%(name)s] . you can set your logger name to whatever you want, for example...
Read more >
Logging Cookbook — Python 3.11.1 documentation
Here is a slight modification to the previous simple module-based configuration example: import logging logger = logging.getLogger('simple_example') logger.
Read more >
How to Collect, Customize, and Centralize Python Logs
Once you modify your log format to include the logger name ( %(name)s ) ... uppermodule.py import logging import lowermodule logging.
Read more >
A Step-by-Step Guide to Python Logging - Pylenin
In this article, you will learn about python logging module for logging events and why logging is better than print.
Read more >
Python Logging Guide - Best Practices and Hands-on Examples
The specifications for the logging configuration format are found in the Python standard library. ... Line 1: import the logging module.
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