Skip to main content

Log collector for scanning and aggregating log files

Project description

k3logcollector

Action-CI Build Status 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

k3logcollector-0.1.3.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

k3logcollector-0.1.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file k3logcollector-0.1.3.tar.gz.

File metadata

  • Download URL: k3logcollector-0.1.3.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3logcollector-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b7e74772cc805b16d16d5d385ab97f163daa234d6904b94812a9d7ebb0039828
MD5 97308ce0d17e3efc1499a31d1205b6af
BLAKE2b-256 0cea4ea2d00166ec08cf0bacf68d6d0010342a9b769a952465e5b7ebc77bfa02

See more details on using hashes here.

File details

Details for the file k3logcollector-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: k3logcollector-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for k3logcollector-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2005c30a60effa048b4cace318a1f3ed3a9060068a02a2f2a3eba04b9c4b7041
MD5 f9c7d0c8ca5948ba89bc4c8ba6a9844c
BLAKE2b-256 7377bd231b2bbe9d233e194f360d71f41f2e6386646bb0c38f7517a025b26c1d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page