Skip to main content

monitoring log files and sending parsed logs to a specified URL

Project description

watchlog

watchlog is a Python package for monitoring log files and sending parsed logs to a specified URL using HTTP POST requests.

Installation

You can install watchlog using pip:

pip install watchlog

Usage

To use watchlog, you need to create a configuration file in JSON format. Here is an example configuration file:

{
  "check_interval": 5,
  "check": true,
  "files": [
    {
      "path": "/path/to/log/file.log",
      "reg": "^(?P<time>[^ ]*) (?P<level>[^ ]*) (?P<module>[^ ]*) (?P<line>[^ ]*) (?P<message>.*)$",
      "url": "http://example.com/api/logs",
      "latest": true,
      "enable": true,
      "headers": {
        "Content-Type": "application/json"
      },
      "auth": {
        "username": "user",
        "password": "pass"
      }
    }
  ]
}
  • path: The path of the log file to monitor.
  • reg: A regular expression used to parse the log file.
  • url: The URL to send the parsed logs to.
  • latest: Start monitoring from the latest logs.
  • enable: Indicates that this configuration will be enabled, which defaults to true.
  • headers: A dictionary of headers to include in the HTTP POST request.
  • auth: A dictionary with username and password keys for basic authentication.
  • check: if open check ,it will loop check the config file
  • check_interval: circle check interval time(s)

Once you have created the configuration file, you can start monitoring the log file by calling the start() function from the watchlog module:

import asyncio
from watchlog import start

loop = asyncio.get_event_loop()
loop.run_until_complete(start('path/to/config.json'))

You can also use we provide small scripts

watchlog path/to/config/file

This will start monitoring the log file specified in the configuration file and sending parsed logs to the specified URL using HTTP POST requests.

example

example use zinc_observe as log search_engine,Illustrates the use of the process

.                     
├── __init__.py       
├── config.json             config file
├── docker-compose.yml      log search engine service
├── log.log                 log file
└── main.py                 main python file to monitor log file

License

watchlog is licensed under the MIT license.

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

watchlog-0.1.2.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

watchlog-0.1.2-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file watchlog-0.1.2.tar.gz.

File metadata

  • Download URL: watchlog-0.1.2.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.8.10 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for watchlog-0.1.2.tar.gz
Algorithm Hash digest
SHA256 e5865f45e981d82555c3e1d790d7d760c9b07264126eb3295c5b3578f9ddb233
MD5 a081401e518beaa2658dabe5efe1d5cf
BLAKE2b-256 3585fe110fe762897d1a35a0d2d7d625e2be00c6b33aa6b4331532d44a52aee1

See more details on using hashes here.

File details

Details for the file watchlog-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: watchlog-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.8.10 Linux/5.15.90.1-microsoft-standard-WSL2

File hashes

Hashes for watchlog-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d0412214b35abfb89bcaf89e8d156e880bf874eb2af481dd5000c0e849fb10f4
MD5 f4643523d019b2fb6c4671858dff60df
BLAKE2b-256 2adf2a104435eda6a0136944bee788e1503e2acff18024fb9eee3c5361d567c2

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