Skip to main content

k3logcollector

Action-CI Documentation Status Package

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

Metadata

Release files for k3logcollector 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for k3logcollector 0.1.6
File Size Uploaded
k3logcollector-0.1.6.tar.gz 7.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for k3logcollector 0.1.6
File Interpreter ABI Platform
k3logcollector-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 16.5 kB

Release files / k3logcollector-0.1.6.tar.gz

Download URL k3logcollector-0.1.6.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
383c568da9300dd402dccbc863b8656e0d830cecd6f65a5316ef7c9f45ad85c0
BLAKE2b-256 checksum
How to use checksums
9b8013d6da73beaa4b3b7a1f66e11d8cd5c8edb05efb3de10e4fd27ee81254ba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / k3logcollector-0.1.6-py3-none-any.whl

Download URL k3logcollector-0.1.6-py3-none-any.whl
Size 8.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4971e148407b22f068251f1db45778b1f43c25b0d52d06d3187ed197f3b85733
BLAKE2b-256 checksum
How to use checksums
96a0f2e32ca7263c311928281c520c0091799c7300d40e5e91704f70b0780c0e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release history Release notifications | RSS feed

0.1.8

2 release files

0.1.7

2 release files

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page