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.tar.gz (9.4 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-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: template_log_parser-0.9.tar.gz
  • Upload date:
  • Size: 9.4 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.tar.gz
Algorithm Hash digest
SHA256 ca56a44a987b6ab9c45f12b9a3d8141f8e9ba092723a231f09da86fe667689a2
MD5 1c19647466b597a29980c10c5fc1f5d1
BLAKE2b-256 6147653bd4c3ce2cca76ae8441038a642e9d8f5f84ff87aced0133d7578a0c4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for template_log_parser-0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 44c3a149a7c070638523bb2fe9e81189b4ddd01d39e5135f8d6cc99aae235e07
MD5 879c3202acba03d6b8a06846cc7b7bd7
BLAKE2b-256 011ff1189abde186dd25cfa59f6483da8f62bf6d4eba33fbe09ba96ddfef375b

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