Skip to main content

Log chains for webserver

Project description

logngo: Python Logging Library

Overview

logngo is a versatile Python logging library designed for modern web services. It provides advanced logging capabilities including context-aware logging for request and internal tasks, automatic file rotation based on time intervals, and socket-based logging with automatic Socket.IO support.

Key Features

  • Context-Aware Logging: Log messages are tagged with a unique context, making it easier to trace logs back to specific requests or internal tasks.
  • Automatic File Rotation: Log files are automatically rotated based on configurable time intervals, helping manage log file sizes and organization.
  • Socket Logging: Real-time logging through web sockets v2 (EIO=3), with built-in support for Socket.IO.
  • Easy Integration with Web Frameworks: Designed to be easily integrated with frameworks like FastAPI.

Installation

You can install logngo via pip:

pip install logngo

Setup and Configuration

Basic Logger Setup

To set up the logger, import the Logger from logngo and configure it with your preferences:

from logngo import Logger

Logger().setup(name="test")
Logger().setup_file_handler(file_path="../log/.log", when="M", interval=1)
Logger().setup_socket_handler(url="http://localhost:8000", handshake_path="logngo/socket.io")
Logger().setup_stream_handler()

Parameters:

  • name: Name of the logging service.
  • file_path: Path to the log file.
  • when and interval: Controls the log file rotation. For instance, "M" and 1 means the file rotates every minute.
  • url: URL for the socket logging server.
  • handshake_path: Handshake path for the Socket.IO server.

Context-Aware Logging

For logging with request or task-specific contexts:

from logngo import context

# Set a unique identifier for the current context
context.set(UNIQUE_ID)

Each log message will include this unique identifier, making it easier to correlate logs with specific requests or tasks.

Socket Logging with FastAPI

To use socket logging with FastAPI, mount the socket from logngo:

from fastapi import FastAPI
from logngo import socket_ngo

app = FastAPI()

# Mount the socket logger
app.mount("logngo", socket_ngo())

This sets up an endpoint for the Socket.IO server, enabling real-time log streaming.

Usage

After setting up logngo, you can use its logger to log messages of different severities:

from logngo import Logger

# Logging an info message
Logger().logger.info("This is an info message.")

# Logging a warning message
Logger().logger.warning("This is a warning message.")

# Logging an error message
Logger().logger.error("This is an error message.")

# Logging a debug message
Logger().logger.debug("This is a debug message.")

# Logging a critical message
Logger().logger.critical("This is a critical message.")

Contributing

Contributions to logngo are welcome! Please refer to the repository's contribution guidelines for more details.

License

logngo is released under MIT License.

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

logngo-1.7.36.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

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

logngo-1.7.36-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file logngo-1.7.36.tar.gz.

File metadata

  • Download URL: logngo-1.7.36.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for logngo-1.7.36.tar.gz
Algorithm Hash digest
SHA256 08f7734da00b97c52481874f05fd744b585220be4837fc464c9999e4e28cd088
MD5 914151870ecc1797208bdc7f4027a63e
BLAKE2b-256 9fce0ec81ac74cc65b43f9b3b16c3ef420dc810ad5584a4cd2d3c08dea6bc5e2

See more details on using hashes here.

File details

Details for the file logngo-1.7.36-py3-none-any.whl.

File metadata

  • Download URL: logngo-1.7.36-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.18

File hashes

Hashes for logngo-1.7.36-py3-none-any.whl
Algorithm Hash digest
SHA256 2175a823ebda6590c90822b5c739551b470b7c555084a3e7659dce2a0b91cbf6
MD5 007fba486e9c30a9464ff9715298c186
BLAKE2b-256 678fbf6a1be9684d27ffda53977cc25efee8d9a93110062ba9c8cbbd5c2f7398

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