Skip to main content

A simple Python logging library for chat applications

Project description

OSH Logger

A simple Python logging library for chat applications, with support for both local development and Google Cloud Platform (GCP) environments.

Features

  • Dual Environment Support: Automatically detects and configures logging for local development and GCP environments
  • Colored Local Output: Beautiful, colored terminal output with proper text wrapping in local development environment
  • Structured GCP Logging: Labelled logs and structured output on GCP, with ability to filter by a Logger instance's name
  • Thread-Safe: Supports logging with thread IDs for concurrent applications
  • Configurable Timestamps: Enable/disable timestamps as needed

Installation

Basic Installation

pip install oshtools

With Google Cloud Support

pip install oshtools[gcp]

Quick Start

from osh import Logger

# Create a separate logger instance for each module
logger = Logger("main")

# Pass in a thread ID to the contructor
# The thread ID is a unique identifier that can help trace requests on GCP
logger = Logger("utils", "123")

# Basic logging
logger.log("Application started")
logger.info("Processing complete")
logger.debug("Debug information")
logger.warn("Warning message")
logger.error("Error occurred")

# Log and add a thread ID dynamically
logger.log("Processing request", thread_id="thread-123")

# Structured logging (useful for GCP)
logger.struct_log("User action", user_id="123", action="login", level=logging.INFO)

Environment Detection

The logger automatically detects the environment:

  • GCP Environment: Detected by presence of K_SERVICE or GOOGLE_CLOUD_PROJECT environment variables
  • Local Environment: Uses colored terminal output with proper formatting

Log Types

The logger supports several log types with different colors and levels:

  • log() - General information (cyan)
  • info() - Informational messages (blue)
  • runtime() - Runtime information (bright magenta)
  • think() - Thinking/processing logs (light blue)
  • debug() - Debug information (green)
  • warn() - Warnings (yellow)
  • error() - Errors (red)
  • critical() - Critical errors (bright red)

Configuration

Timestamps

logger = Logger("my-app")
logger.set_timestamps(False)  # Disable timestamps
logger.set_timestamps(True)   # Enable timestamps

Log Levels

import logging
logger = Logger("my-app", level=logging.DEBUG)

Google Cloud Platform Integration

When running in GCP (Cloud Run, App Engine, etc.), the logger automatically:

  • Uses Google Cloud Logging handlers
  • Adds structured metadata and labels
  • Includes logger names and thread IDs in labels
  • Maintains local CLI formatting for debugging

Requirements

  • Python 3.8+
  • google-cloud-logging (optional, for GCP support)

License

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

oshtools-0.1.2.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

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

oshtools-0.1.2-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file oshtools-0.1.2.tar.gz.

File metadata

  • Download URL: oshtools-0.1.2.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for oshtools-0.1.2.tar.gz
Algorithm Hash digest
SHA256 548176ef0ee1ae1b24123a412bf04073304bf4cf9bfb585c9057f0a850bfc08a
MD5 d12c88db995987ddefa2d6d271f23dcf
BLAKE2b-256 97a9aacccbc7b527e8cb78db24f52dd15cac9a9300a60a73c5da3ab107fe4d89

See more details on using hashes here.

Provenance

The following attestation bundles were made for oshtools-0.1.2.tar.gz:

Publisher: python-publish.yml on zion-off/oshtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file oshtools-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: oshtools-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for oshtools-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3491711fdbcec99e6d51f471aa9b309b4fbf625ff20d79e17b2c3165356f7c38
MD5 06d9a2923788079c7203c94e68a34d4c
BLAKE2b-256 538354da3a10e8724fcee875ec46cda21ad0033d82e8a533aa8fcb1baf98f3e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for oshtools-0.1.2-py3-none-any.whl:

Publisher: python-publish.yml on zion-off/oshtools

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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