Documentation / LemmeKnow Server

Autologger

Autologger is a small tool that watches log files your programs already write and sends each new entry to LemmeKnow as a log line, so you don't have to change the programs. It ships with LemmeKnow Server and runs on its own, next to the server.

Entries arrive like any line sent with log_client: in the server's Monitor channel, under the source you choose, on the public or private channel, and ready for your rules. Autologger never decides what's important. Each entry goes out at the level its format gives it, and your rules on the phone pick out what matters.

Setting it up

Autologger needs the files that come with LemmeKnow Server: autologger.py, log_client.py, the formats folder, and config.py for the broker address. Open autologger_config.py in the same folder and list your files:

FILES = [
    {"path": r"C:\Backup\backup.log", "source": "backup"},
    {"path": "/var/log/myapp/app.log", "format": "tabbody", "public": True},
    {"path": r"C:\Builds\results", "type": "directory", "glob": "*.xml",
     "format": "junit", "mode": "each", "source": "builds"},
]

Then run it:

python autologger.py

It prints each file it watches and keeps running until you stop it. To start it automatically, set it up the same way as the server in Running at startup, with autologger.py in place of lemmeknow.py. Run only one copy, or every entry is sent twice.

What each entry can set

SettingDefaultMeaning
path(required)The file, or for "directory" the folder. Windows paths need the r prefix, as above.
type"file""file" or "directory".
format"raw"How entries are read: raw, tabbody, lklog, junit, or a custom format. See Log file formats.
sourceThe file name without its extension, or the folder nameSource name on the phone. An lklog line's own source wins.
publicFalseTrue sends to the public channel. See Public and private channels.
glob"*"For a folder: which files count, for example *.log.
mode"latest"For a folder: latest, each, or snapshot (see below).
from_startFalseTrue also sends what a file already holds the first time autologger sees it. Otherwise it starts at the end.
default_body_level"debug"For junit: the level of passing test lines.

Formats

The format setting takes raw, tabbody, lklog, junit, or the name of a custom format in the custom_formats folder next to autologger_config.py. They are the same formats, from the same code, as file feeds on the LemmeSee Hub. See Log file formats for each one's syntax and for writing your own.

For tabbody, lklog, and junit, an entry's detail lines are added under its first line in the same message. A detail line at warning or above keeps its level as a tag, such as [ERROR] 3 files skipped. Entries with a time in the file keep that time on the phone.

Write each entry in one go, so a title and its detail lines land together. Autologger waits until a file has stopped changing for two seconds before reading it, so an entry written in quick pieces still arrives whole.

Folders

With "type": "directory", autologger watches the files in a folder that match glob:

ModeBehaviour
latestFollows the newest file. When a newer one appears, such as a log that starts a new file each day, autologger moves to it and reads it from the start.
eachSends each new file once, whole, when it appears. Files already there when autologger first starts are skipped.
snapshotFollows every matching file at once.

Restarts and rotation

Autologger remembers how far it has read each file in autologger_state.json, next to its config. When it starts again, it sends the entries written while it was stopped. If a file shrinks or is replaced, for example when a log rotates, it reads the new file from the start.

If the broker can't be reached, autologger waits and reads nothing until it's back, so no entries are lost. It sends at most 300 messages a minute, so catching up on a long file doesn't flood the phone.

Other settings

SettingDefaultMeaning
POLL_SECONDS1Seconds between looks at the files.
SETTLE_SECONDS2How long a file must stop changing before new entries are read.
MAX_PER_MINUTE300Most messages sent per minute.
STATE_PATHautologger_state.json next to the configWhere read positions are kept.
FORMATS_PATHcustom_formats next to the configFolder of custom formats.

Set the AUTOLOGGER_CONFIG environment variable to use a config file somewhere else.

With the LemmeSee Hub

On a server relayed through a hub, autologger's sources reach phones through the hub with nothing extra to set up, and appear in the server's Permissions list like any other source. On the hub's own PC, a file feed shows a log file as a feed instead, with its full history kept on the hub. Use autologger there when you'd rather have the file's entries as plain log lines.