How to pickle loggers?

后端 未结 5 1935
粉色の甜心
粉色の甜心 2021-02-14 22:17

Working on a project that requires that I am able to pickle the container object at any point, since we expect it to fail on external conditions quite frequently and be able to

5条回答
  •  忘了有多久
    2021-02-14 22:36

    New in Python 3.7 (bpo30520)

    Logger can now be pickled like many other objects.

    import pickle
    import logging
    log = logging.getLogger(__name__)
    logger_pickle = pickle.dumps(log)
    
    # and of coarse, to load:
    log = pickle.loads(logger_pickle)
    

提交回复
热议问题