Skip to main content

AsyncGELF

CodeQL PyPI - Downloads PyPI

PyPI - Python Version

Async python logging handlers that send messages in the Graylog Extended Log Format (GELF).

List of ready to run GELF handlers

  • TCP (with and without TLS);
  • HTTP (with and without TLS);
  • UDP;

Get AsyncGELF

pip install asyncgelf

Usage

GELF TCP

import asyncio
import asyncgelf

async def main(message):
    handler = asyncgelf.GelfTcp(
        host='127.0.0.1',
    )

    await handler.tcp_handler(message)

asyncio.run(main(message))

GELF TCP with custom timestamp

import asyncio
import asyncgelf

from datetime import datetime


async def main(message):
    handler = asyncgelf.GelfTcp(
        host='127.0.0.1',
    )
    event_time = "2024-02-06 08:25:56.789"
    timeformat = "%Y-%m-%d %H:%M:%S.%f"
    await handler.tcp_handler(message, datetime.strptime(event_time, timeformat).timestamp())

asyncio.run(main(message))

GELF HTTP

import asyncio
import asyncgelf

async def main(message):
    handler = asyncgelf.GelfHttp(
        host='127.0.0.1',
    )

    await handler.http_handler(message)

asyncio.run(main(message))

GELF UDP

import asyncio
import asyncgelf

async def main(message):
    handler = asyncgelf.GelfUdp(
        host='127.0.0.1',
    )

    await handler.udp_handler(message)

asyncio.run(main(message))

Additional field

Expect Dict with the following moments:

  • All keys must start with underscore (_) prefix;
  • _id can't be an additional field;
  • Allowed characters in field names are any word character (letter, number, underscore), dashes and dots
import asyncio
import asyncgelf

async def main(message):
    additional_field = {
      '_key_1': 'value_1',
      '_key_2': 'value_2',
    }
    
    handler = asyncgelf.GelfTcp(
        host='127.0.0.1',
        additional_field=additional_field
    )

    await handler.tcp_handler(message)

asyncio.run(main(message))

Available params

  • host Required | Graylog server address;
  • port Optional | Graylog input port (default: 12201);
  • gelf_version Optional | GELF spec version (default: 1.1)
  • level Optional | The level equals to the standard syslog levels (default: 1);
  • scheme Optional | HTTP Scheme for GELF HTTP input only (default: http);
  • tls Optional | Path to custom (self-signed) certificate in pem format (default: None)
  • compress Optional | Compress message before sending it to the server or not (default: False)
  • compress_level Optional | Set compression level: available from 1 (BEST_SPEED) to 9 (BEST_COMPRESSION) (default: 1)
  • debug Optional | Additional information in error log (default: False)
  • additional_field Optional | Dictionary with additional fields which will be added to every gelf message (default: None)
  • dns_resolve Optional | Variable host will be checked to existing DNS as parameter and if dns is found, then on initialization will resolve to ip and variable will be updated. By default, UDP handler gets resolved by DNS on every log message. See more: #91305 (default: False)

Metadata

Release files for asyncgelf 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asyncgelf 1.2.0
File Size Uploaded
asyncgelf-1.2.0.tar.gz 6.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for asyncgelf 1.2.0
File Interpreter ABI Platform
asyncgelf-1.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / asyncgelf-1.2.0.tar.gz

Download URL asyncgelf-1.2.0.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c09294523babbb5618214703e5adceb2f278a62180ad58cf97113c05471554be
BLAKE2b-256 checksum
How to use checksums
2a111f5779a7e9066f26d739f26d8e22a4f8a28ef8759fac10f90ba89e737ea9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / asyncgelf-1.2.0-py3-none-any.whl

Download URL asyncgelf-1.2.0-py3-none-any.whl
Size 6.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9e8cf5fdf683e4769a095e743306ff36fc9423c8549bb115f6a9073107de058d
BLAKE2b-256 checksum
How to use checksums
ee7e67268419dd69b96a4b3d9c9f8e7cd4c003c3d2f89bee7a1ae1c8ecb72874
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

1.2.0 This release

2 release files

1.1.0

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

1 release file

0.1.0

1 release file

0.0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page