Skip to main content

Parsing Log Files With User Defined Templates

Project description

template-log-parser : Log Files into Tabular Data


template-log-parser is designed to pull relevant information into DataFrame columns by way of user designed templates. parse and pandas perform the heavy lifting.

You can utilize the included workflows (Kodi, Omada Controller, Open Media Vault, PFSense, PiHole, Synology DSM, and Ubuntu) or build your own.

Getting Started


pip install template-log-parser

The foundational principle in this project is designing templates that fit repetitive log file formats.

my_log_line = "2024-06-13T15:09:35 server_15 login_authentication[12345] rejected login from user[user_1]."

my_template = "{time} {server_name} {service_process}[{service_id}] {result} login from user[{username}]."

The words within the braces will eventually become column names in a DataFrame.
Note that templates will be looking for an exact match.


After creating a list of templates, they should be compiled:

  • 'search_string' is text expected to be found in the log file line. The parsing function will only check the template against the line if the text is present.
  • 'template' is the user defined template.
  • 'event_type' is an arbitrary string name assigned to this type of occurrence.
from template_log_parser import compile_templates

uncompiled_templates = [
# [template, event_type, search_string ]
  [my_template, "login_attempt", "login from"],
  [my_template2, "reboot", "Host Restarting"],
  ...
]

my_templates = compile_templates(uncompiled_templates)


Parse an entire log file and return a Pandas DataFrame:

from template_log_parser import process_log

df = process_log('log_file.log', my_templates)

print(df.columns)
Index(['time', 'server_name', 'service_process', 'service_id', 'result', 'username', 'event_type', 'event_data'])

This is just a tabular data form of many single parsed events.

  • event_type column value is determined based on the matching template
  • event_data column holds the raw string data for each log line

Note: Events that do not match a template will be evaluated as event_type ('Other') with column: ('Unparsed_text').


DISCLAIMER

This project is in no way affiliated with the products mentioned (Debian, Kodi, Omada, Open Media Vault, PFSense, PiHole, Synology, or Ubuntu). Any usage of their services is subject to their respective terms of use.

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

template_log_parser-0.9.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

template_log_parser-0.9.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file template_log_parser-0.9.1.tar.gz.

File metadata

  • Download URL: template_log_parser-0.9.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for template_log_parser-0.9.1.tar.gz
Algorithm Hash digest
SHA256 afd47e2f907cf71e0ec88ec7fb244e3db90c118b5d9c5fb932d1a3e53afce812
MD5 3d6d1dc9755f206a185b946e95207ea6
BLAKE2b-256 bd2b8c28a275819e49382f4a8592c1c59390f0c5414c55b3785e8c5b4837def3

See more details on using hashes here.

File details

Details for the file template_log_parser-0.9.1-py3-none-any.whl.

File metadata

File hashes

Hashes for template_log_parser-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dd513379f790e28fd5d00bc49f61a12f9d0a5757af2f9f6d7c062d540d4e4891
MD5 3667371e48edc792f340868dd3118eb1
BLAKE2b-256 6804ecad29f72cae620a90a4b59cbabfa8469d3e761ea67182aa5133cbc8e01c

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