Skip to main content

A Python library for working with CLEF log files

Project description

pyclef

pyclef is a Python library designed to simplify the process of working with CLEF (Compact Log Event Format) log files. It provides tools for parsing, filtering, and analyzing log data efficiently, making it an essential tool for developers and data analysts working with structured log data.


Key Features

  • Memory-efficient streaming: Use iter_events() to process large log files without consuming excessive memory.
  • Bulk parsing: Quickly parse smaller log files with parse().
  • Automatic field separation: Distinguishes between reified and user-defined fields.
  • Advanced filtering: Filter events by log level, timestamps, message patterns, exceptions, and user-defined fields.
  • Comprehensive error handling: Provides detailed exceptions for robust error management.
  • Custom encoding support: Handle log files with different encodings.

Installation

Install pyclef using pip:

pip install pyclef-lib

Usage

Here's a quick example of how to use pyclef to parse a CLEF log file:

from pyclef import ClefParser

# Initialize the parser
parser = ClefParser()

# Parse a CLEF log file
events = parser.parse("example.clef")

# Iterate over the parsed events
for event in events:
    print(event)

For large log files, use the memory-efficient iter_events() method:

from pyclef import ClefParser

# Initialize the parser
parser = ClefParser()

# Iterate over events in a large CLEF log file
for event in parser.iter_events("large_file.clef"):
    print(event)

Filtering Events

pyclef also provides powerful filtering capabilities. Here's how you can filter events based on various criteria:

from pyclef import ClefParser
from pyclef.filter import ClefEventFilterBuilder

# Initialize the parser
parser = ClefParser()
events = parser.parse("example.clef")

# Build a filter
filter_builder = ClefEventFilterBuilder()
filtered_events = (
    filter_builder
    .level("error")  # Filter events with log level "error"
    .start_time("2023-01-01T00:00:00Z")  # Filter events after this timestamp
    .end_time("2023-12-31T23:59:59Z")  # Filter events before this timestamp
    .msg_regex(r"Something.*")  # Filter events with specific message patterns
    .user_fields({"Environment": "Production"})  # Match user-defined fields
    .filter()  # Apply the filter
)

# Iterate over the filtered events
for event in filtered_events:
    print(f"Timestamp: {event.timestamp}, Message: {event.message}")

Error Handling

pyclef provides comprehensive error handling to manage issues that may arise during parsing. Here's an example of how to handle parsing errors:

from pyclef import ClefParser
from pyclef.exceptions import ClefParseError

try:
    parser = ClefParser()
    events = parser.parse("invalid_file.clef")
except ClefParseError as e:
    print(f"Error parsing file: {e}")

Documentation

Comprehensive documentation is available at pyclef Documentation.


Contributing

We welcome contributions to pyclef! Here's how you can help:

  1. Fork the repository on GitHub.
  2. Create a new branch for your feature or bugfix.
  3. Write tests for your changes.
  4. Submit a pull request.

For more details, see our contribution guidelines in the CONTRIBUTING.md file.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Changelog

The full changelog is available here.


Support

If you encounter any issues or have questions, feel free to open an issue on the GitHub repository.

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

pyclef_lib-0.1.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

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

pyclef_lib-0.1.0-py3-none-any.whl (27.5 kB view details)

Uploaded Python 3

File details

Details for the file pyclef_lib-0.1.0.tar.gz.

File metadata

  • Download URL: pyclef_lib-0.1.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pyclef_lib-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cc1eb15b5722b216e7f61448bfd0fad07d2cd17c380bca8095462594b98373be
MD5 eef095cfe8d020726db267940463df88
BLAKE2b-256 5ccebfb00d0f0fd5db88f58a5a251cc888a61f6e6ab0600ae223183b13297c46

See more details on using hashes here.

File details

Details for the file pyclef_lib-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyclef_lib-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for pyclef_lib-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8f9cc88e42a70a0ed35cb1f6c680a7a0bb828afe28804edbdbbfb588fb31807
MD5 f8ce1967b10d6ca25d6ef0ad21c47f87
BLAKE2b-256 396e1793f70706a687c1edb8d6080cad52d6658af3edab7b730761ab69001849

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