https://github.com/badbye/timelog
Split python logger by time for multiple processings.
https://github.com/badbye/timelog
log python
Last synced: about 2 months ago
JSON representation
Split python logger by time for multiple processings.
- Host: GitHub
- URL: https://github.com/badbye/timelog
- Owner: badbye
- Created: 2017-08-15T15:42:07.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-10-18T09:41:33.000Z (over 7 years ago)
- Last Synced: 2025-03-17T07:48:08.329Z (2 months ago)
- Topics: log, python
- Language: Python
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
cotimelog
=========|image0| |PyPI|
**cotimelog**, inspired from [ConcurrentLogHandler](https://pypi.python.org/pypi/ConcurrentLogHandler/0.9.1).
To be honest, it is almost the same code. Just edit to make the log file rotated by time.Installation
============pip install cotimelog
ConcurrentTimeRotatingFileHandler
---------------------------------This class is a log handler which is a drop-in replacement for the python standard log handler
``TimedRotatingFileHandler``.
The TimedRotatingFileHandler will failed to rotate when multiple processes are trying to
write into the same file. You will meet this issue when you use uwsgi.
This ``ConcurrentTimeRotatingFileHandler`` class is mainly developed to fix this issue.Usage
`````Using ``ConcurrentTimeRotatingFileHandler`` ::
import os
import time
from logging import getLogger, INFO
from cotimelog import ConcurrentTimeRotatingFileHandler# Use an absolute path to prevent file rotation trouble.
log = getLogger()
logfile = os.path.abspath("mylogfile.log")
# Rotate log after 1 second
rotateHandler = ConcurrentTimeRotatingFileHandler(logfile, mode="a", when="S", backupCount=5)
log.addHandler(rotateHandler)
log.setLevel(INFO)[log.info(str(i)) for i in range(10)]
time.sleep(1)
[log.info(str(i)) for i in range(10, 100)]License
^^^^^^^`Apache License, Version 2.0 `_
.. |image0| image:: https://travis-ci.org/badbye/timelog.svg?branch=master
.. |PyPI| image:: https://img.shields.io/pypi/pyversions/cotimelog.svg?style=flat-square