Scan log files on local machine, collector all interested logs, and send to somewhere for display.
Project description
k3logcollector
Scan log files on local machine, collector all interested logs, and send to somewhere for display.
k3logcollector is a component of pykit3 project: a python3 toolkit set.
Name
logcollector
Scan log files on local machine, collector all interested logs, and send to somewhere for display.
Description
We may want to see all error logs on all machines, so we need to collector logs, and save it in somewhere. This module is used to collector logs on one machine.
Normally, same error info will be loged repeatedly, we do not want to save duplicated log info, so logs produced by same source file at same line number in one second will be combined.
Conf
configuration for log files. It is a dict, the key is the log name, the value is the configuration for the log.
file_path
the path of the log file.
is_first_line
is a callback function.
The argument to this function is a line in log file, if the line is the
first line of a log, then return True
, otherwise return False
.
get_level
is a callback function. The argument to this function is the complete log string, which may contains multiple lines. It should return the level of the log, which is a string.
parse
is a callback function. The argument to this function is the complete log string, which may contains multiple lines. It should return a dict contains following fields.
-
log_ts: the timestamp of this log, such as
1523936052
, is a integer. -
level: the level of this log, such as 'info'.
-
source_file: the source file in which the log was produced.
-
line_number: the number of the line at which the log was produced.
level
is a list, used to specify the interested log levels.
Install
pip install k3logcollector
Synopsis
import k3logcollector
def send_log(log_entry):
print("send the log entry to database or other place.")
def is_first_line(line):
print("return True if the line is the first line of a log,")
print("otherwise return False.")
def get_level(log_str):
print("return the level of the log.")
def parse(log_str):
print("parse the log.")
conf = {
'front_error_log': {
'file_path': 'path/to/log/file/xxx.error.log',
'level': ['warn', 'error'],
'is_first_line': is_first_line,
'get_level': get_level,
'parse': parse,
},
}
kwargs = {
'node_id': '123abc',
'node_ip': '1.2.3.4',
'send_log': send_log,
'conf': conf,
}
k3logcollector.run(**kwargs)
Author
Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Copyright and License
The MIT License (MIT)
Copyright (c) 2015 Zhang Yanpo (张炎泼) drdr.xp@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file k3logcollector-0.1.0.tar.gz
.
File metadata
- Download URL: k3logcollector-0.1.0.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5b4b15cecb8ceb713e748d7acb6542b64e9325552927ab69ca78bb586c667eb |
|
MD5 | eee68e513a5d4c6b3863de89adb42e54 |
|
BLAKE2b-256 | fad118514682695c8123f6d91d6fec944806ca8f8bdf51417aa8cf3ef755be2e |
File details
Details for the file k3logcollector-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: k3logcollector-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29535e4f7f9d9b0a752f8a1afa56f309dd94b857eccf409878dc9e210d8e594c |
|
MD5 | ec6a0659158feb49d94a27487294f6f5 |
|
BLAKE2b-256 | ff8cfc168c886d17a365301f52f95332216195aec90ca68c98070bfc16a2776c |