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_SERVICEorGOOGLE_CLOUD_PROJECTenvironment 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file oshtools-0.1.6.tar.gz.
File metadata
- Download URL: oshtools-0.1.6.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d260d89aeb7ea427b06b10659a8639ac09dd288511ba6252b3123ad2c8abd7d
|
|
| MD5 |
dc412be664077e1bd4741e950cf38d37
|
|
| BLAKE2b-256 |
c76e53e712472362f4eef016b42d3e26766c733a71ba0c96193441794f63f0f1
|
Provenance
The following attestation bundles were made for oshtools-0.1.6.tar.gz:
Publisher:
python-publish.yml on zion-off/oshtools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oshtools-0.1.6.tar.gz -
Subject digest:
9d260d89aeb7ea427b06b10659a8639ac09dd288511ba6252b3123ad2c8abd7d - Sigstore transparency entry: 512915820
- Sigstore integration time:
-
Permalink:
zion-off/oshtools@6a5e244491592c16151ddfb508ad416d38c392c9 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/zion-off
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@6a5e244491592c16151ddfb508ad416d38c392c9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file oshtools-0.1.6-py3-none-any.whl.
File metadata
- Download URL: oshtools-0.1.6-py3-none-any.whl
- Upload date:
- Size: 8.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1b1f24b28a465747d01494b70a2c2c6a32865c22124fecee339965782ff13033
|
|
| MD5 |
eeeba84093d1802bbcae351850d2e36b
|
|
| BLAKE2b-256 |
39cfebdeefbc50e4d39bebb5667df3f4944bb3a49fec89cd1b7849df371d0e4d
|
Provenance
The following attestation bundles were made for oshtools-0.1.6-py3-none-any.whl:
Publisher:
python-publish.yml on zion-off/oshtools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
oshtools-0.1.6-py3-none-any.whl -
Subject digest:
1b1f24b28a465747d01494b70a2c2c6a32865c22124fecee339965782ff13033 - Sigstore transparency entry: 512915823
- Sigstore integration time:
-
Permalink:
zion-off/oshtools@6a5e244491592c16151ddfb508ad416d38c392c9 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/zion-off
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@6a5e244491592c16151ddfb508ad416d38c392c9 -
Trigger Event:
push
-
Statement type: