Skip to main content

A daemon to monitor keywords in any log files specified by glob pattern

Project description

A daemon to monitor keywords in any log files specified by glob pattern.

In the background log files are checked periodically by dogs and user defined handlers are called when error lines are detected according the keyword regex.


  • glob path
  • regex keywords
  • compatible with logrotate
  • custmize handler function or callable object
  • log files don’t have to exist before watch
  • a dog can watch multiple logs and a log can be watched by multiple dogs



pip install logdogs


logdogs -c


kill <pid>

pid file will be removed automatically. is your config file which contains upper case module variables as configuration. Here is an example:

import os
import logging

LOG_FILE = 'logdogs.log'
# you can even call basicConfig to customize the log instead

INTEVAL = 10 # seconds

DIR = os.path.abspath('.')
STDOUT = 'logdogs.out'
STDERR = 'logdogs.err'
# the above 4 configurations only work when DAEMONIZE is True

logger = logging.getLogger(__name__)

class MyHandler(object):
    def __init__(self):
        self.count = 0

    def __call__(self, file, lines):
        self.count += 1'...')
        # Do whatever you want here...

DOGS = {
    "test": {
        "paths": ["a.log", "b.log"],
        "handler": MyHandler(),
        "includes": [r"wrong"],
        "excludes": [r"nothing"]
    "glob": {
        "paths": ["**/*.log"],
        "handler": MyHandler(),
        "includes": [r"(?!)wrong"],

In this case, logdogs will run as a daemon process in current directory and check log files every 10 seconds. a.log and b.log will be watched both by dog test and glob. When a line containing wrong but not nothing is written to a.log, both dogs’ handler will be called.

The effective variables in config file are described as below.



A Dog consists of:

  1. a group of log files specified by glob pattern
  2. a filter defined by includes and excludes
  3. a handler function or a callable object

DOG is a dict in the form of {name: attribute} where name is not important and attribute is a dict containing the following keys:


a handler is a function which has the following signature:

def handler(file, lines):
    file is the absolute path of the log file.
    lines is a list of the lines includes newline characters(\n)

the default handler is a callable object of:

class Handler(object):
    default handler for log event
    def __call__(self, file, lines):

It’s up to you to deal with the log line in this handler such as mailing, send to wechat and etc.

includes & excludes

They are regular expressions and both are optional. The handler is called if any regex in includes is found in the line and any regex in excludes is not found in the line. That is to say, or logic is applied in the includes and and logic is applied in the excludes.


path is a list, it supports the following forms:

  1. single file: ['/var/logs/a.log']
  2. multiple files: ['/var/logs/a.log', '/var/logs/b.log']
  3. glob pattern: ['/var/logs/*.log']
  4. recursive glob (similar as globstar on bash): ['/var/logs/**/*.log']
  • In the last 2 cases, a log file is not required to exist when monitor starts
  • The same log file can overlap in multiple dog block


seconds for sleep between checks


  • LOG_FILE: specify log file. logs are printed to stdout if not specified
  • LOG_LEVEL(WARNING): which log level to use


  • DAEMONIZE(False): whether to start a daemon process running in the backgroup, the following configs only take effect when DAEMONIZE is True
  • DIR: set the working directory, default is /
  • PID_FILE: pid file path
  • STDOUT: where to redirect stdout(print exception traceback for example)
  • STDERR: where to redirect sterr


python develop


python -m unittest -v test_function.TestFunction


  • more handlers
  • threading

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

logdogs-0.2.tar.gz (7.0 kB view hashes)

Uploaded source

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page