https://github.com/artyom/logfeed
https://github.com/artyom/logfeed
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/artyom/logfeed
- Owner: artyom
- Created: 2013-08-12T05:57:22.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2013-08-30T12:18:34.000Z (almost 13 years ago)
- Last Synced: 2025-02-14T09:49:30.280Z (over 1 year ago)
- Language: Python
- Size: 164 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LogFeed: read log messages from rotated files
`LogFeed` can read messages from rotated log. Consider the usual setup for
`messages` logfile in standard linux system:
/var/log/messages.4.gz
/var/log/messages.3.gz
/var/log/messages.2.gz
/var/log/messages.1
/var/log/messages
`LogFeed` can abstract this separation, so you can iterate over log messages
from oldest to newest.
## Features
* uncompressed, gzipped (`.gz`) or bzipped (`.bz2`) files support;
* stores log position, so on successive run only new messages would be read;
* correctly handles log rotation (even while reading file);
* locks on state file;
* can be used in *follow mode* to continuously yield new messages as they're
become available.
## Usage
from logfeed import LogFeed
system_logs = LogFeed('/var/log/syslog*')
for line in system_logs:
process(line)
If you need to be sure that log position is advanced only if line was
successfully processed, you can use the following syntax:
from logfeed import LogFeed
system_logs = LogFeed('/var/log/syslog*', consumer=process)
for line in system_logs:
pass
If `process` function raises an exception, log position won't be advanced
(though you can have some duplicate lines on successive run).