Skip to main content

SeqPyLogger

PyPI version

SeqPyLogger is a python loghandler for seq.

Usage

import os

os.environ["SEQ_APIKEY"] = "xSxExQxAxPxIxKxExYx"
os.environ["SEQ_SERVER"] = "http://localhost:8794/"
os.environ["Environment"] = "Staging"

import logging
from seqpylogger import SeqPyLogger

root = logging.getLogger()
root.setLevel(logging.INFO)
seqLogger = SeqPyLogger(buffer_capacity=10)
root.addHandler(seqLogger)

logger = logging.getLogger("MyLogger")

logger.debug("Debug log message")
logger.info("Informational log message")
logger.warning("Warning log message")
logger.error("Error log message")
logger.critical("Critical log message")
logger.fatal("Critical log message")

logger.info("Test log message with argument %s", "dummy argument")
logger.info("Test log message with arguments %s, %s", "dummy argument 1", "dummy argument 2")

try:
    raise Exception("Some issue")
except:
    logging.exception("An error occured but now we have the stacktrace")
    # logging.error("There was an error", exc_info=1)  # alternative to .exception()

# logs are flushed every 10 seconds and every 10 logs

An alternative way of setting the handler is using the dictConfig

import os
import time
import logging
import logging.config

os.environ["SEQ_APIKEY"] = "xSxExQxAxPxIxKxExYx"
os.environ["SEQ_SERVER"] = "http://localhost:8794/"
os.environ["Environment"] = "Staging"

logger_config = {
    "version": 1,
    "disable_existing_loggers": True,
    "root": {
        "level": logging.INFO,
        "handlers": ["seq"]
    },
    "handlers": {
        "seq": {
            "level": logging.INFO,
            "class": "seqpylogger.SeqPyLogger"
        },
    },
}

logging.config.dictConfig(logger_config)

logging.info("Example message")

Installation

pip install seqpylogger

Test install

Used for development on the package.

sudo python3 -m pip install -U .

Examples

try:
    raise Exception("Some issue")
except:
    logging.exception("An error occured but now we have the stacktrace")
    # logging.error("There was an error", exc_info=1)  # alternative to .exception()

try:
    raise Exception("Some issue")
except:
    logging.fatal("This time no stacktrace")

try:
    raise Exception("Some issue")
except:
    logging.fatal("Stacktrace is not limited to ERROR", exc_info=1)

Images

Screenshot image

Changelog

inspired by Keep a changelog

[2024-08-15]

  • [Added] object serialization support
  • [Added] fallback parse when parsing fails

[2024-07-16]

  • [Added] allow for extra named attributes
  • [Changed] ENVIRONMENT with capital letters will be recognized first

[2023-02-15]

  • [Fixed] Formatting using %d broke the internal formatter

[2023-01-08]

  • [Fixed] Update dependencies in Pipfile.lock
  • [Added] Tests for basic usage (added script pipenv run tests)

[2021-08-20]

  • [Fixed] Version file removed as this broke pip installation
  • [Fixed] Missing .version file in MANIFEST.md broke pip installation

[2021-08-13]

  • [Fixed] Replaced badge.fury.io pypi badge with shields.io
  • [Changed] Added tagging in create_release.sh
  • [Changed] Used atexit to register flush on exit
  • [Fixed] Fixed issue of duplicate logs when doing a manualflush

[2021-03-22]

  • [Fixed] Update dependencies in Pipfile.lock

[2020-12-29]

  • [Fixed] old dependencies for development

[2020-07-17]

  • [Fixed] .msg and arg objects always converted to str
  • [Changed] internal logs nolonger use root logger

[2020-05-13]

  • [Fixed] Removed print line when adding seq url without trailing slash
  • [Changed] README example to fully work if copied
  • [Added] changelog to README

[Unreleased]

  • Environment variable only works using Environment while full uppercase is the best practice for environment variables
  • logger.info("", extra={}) parameters are not shown in seq

Metadata

Release files for seqpylogger 1.1.1

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

Source distribution (sdist)

Source distribution for seqpylogger 1.1.1
File Size Uploaded
seqpylogger-1.1.1.tar.gz 14.4 kB Details

Release files / seqpylogger-1.1.1.tar.gz

Download URL seqpylogger-1.1.1.tar.gz
Size 14.4 kB
Tags Source
SHA-256 checksum
How to use checksums
089bdaf91fd9d8d0f1356bad60d27dab1c3fc463998b64979ed140696ac75054
BLAKE2b-256 checksum
How to use checksums
0b8fa79865a8f3f7ee2164b6724756bf44a934ca8024edeaba228460ce962e34
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.8

Release history Release notifications | RSS feed

This release

1.1.1 This release

1 release file

1.1.0

1 release file

1.0.11

1 release file

1.0.10

1 release file

1.0.9

1 release file

1.0.8

1 release file

1.0.7

1 release file

1.0.6

1 release file

1.0.5

1 release file

1.0.4

1 release file

1.0.3

1 release file

1.0.2

1 release file

1.0.1

1 release file

1.0.0

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