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.

how to pickle logger

See original GitHub issue
from sklearn.base import BaseEstimator, TransformerMixin

class LoggerMixin():
    @property
    def logger(self):
        return logging.getLogger()
    
class TestClass(BaseEstimator,TransformerMixin,LoggerMixin):
    def __init__(self, datatype_dict):
        self.datatype_dict = datatype_dict

    def fit(self, X, y=None):
        return self

    def transform(self, X, y=None):
        print(self.datatype_dict)
        self.logger.info("transforming datatypes....")
        return X.astype(self.datatype_dict)

How do i start with this functionality in loguru? Im sorry if this is an easy quiestion, but im trying to learn logging in python. Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
Delgancommented, Jun 17, 2019

Maybe can you use logger.remove()?

for fruit in ["apple", "orange", "banana"]:
    handler_id = logger.add("%s.log" % fruit)
    peel_the_fruit(fruit)
    logger.remove(handler_id)

That way, logs emitted by peel_the_fruit() will only appear on the corresponding log file.

0reactions
Delgancommented, Jul 24, 2019

Hey!

What do you mean by “keeping the flow of the log consistent”?

Adding enqueue=True will prevent your logs to be corrupted when using the logger from multiple processes. Otherwise, logging "ABC" and "DEF" at the same time could result in "ABDEFC" in your log file for example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pickle loggers? - python - Stack Overflow
Logger can now be pickled like many other objects. import pickle import logging log = logging.getLogger(__name__) logger_pickle = pickle.dumps(log) # and of ...
Read more >
Issue 30520: loggers can't be pickled - Python tracker
You pickle an object that happens to hold (directly or indirectly) a reference to a logger (it's quite common to have `self.logger =...
Read more >
Python Pickle Module for saving Objects by serialization
First, import pickle to use it, then we define an example dictionary, which is a Python object. Next, we open a file (note...
Read more >
The ultimate guide to Python pickle - Snyk
This article will teach you how to safely use Python's built-in pickle library to maintain persistence within complex data structures.
Read more >
Python Pickle Example - DigitalOcean
Python Pickle is used to serialize and deserialize a python object structure. Any object on python can be pickled so that it can...
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