A structured logging library with OpenTelemetry support for Gushwork services
Project description
Gushwork Logger
A structured logging library with OpenTelemetry support for Gushwork services. This library provides a simple and consistent way to set up logging with OpenTelemetry integration across different Python applications.
Features
- 🚀 Simple and easy to use logging setup
- 📊 OpenTelemetry integration for distributed tracing
- ☁️ AWS Lambda compatibility
- 🔧 Configurable console and OTLP logging
- 🎯 Service-specific logging configuration
- 📝 Structured logging support
Installation
pip install gushwork-logger
Quick Start
Basic Usage
from gushwork_logger import initialize_logging, get_logger
# Initialize logging (call this once at application startup)
initialize_logging(
service_name="my-service",
environment="production"
)
# Get a logger instance
logger = get_logger(__name__)
# Use the logger
logger.info("Application started")
logger.error("Something went wrong", extra={"user_id": 123})
Advanced Configuration
from gushwork_logger import initialize_logging, get_logger
import logging
# Initialize with custom configuration
initialize_logging(
service_name="my-microservice",
environment="staging",
log_level=logging.DEBUG,
enable_console=True, # Enable console output
enable_otlp=True # Enable OpenTelemetry export
)
logger = get_logger("my_module")
logger.debug("Debug information")
logger.info("Process completed successfully")
Environment Variables
The library supports configuration through environment variables:
OTEL_SERVICE_NAME: Default service nameENVIRONMENT: Default environment (dev, staging, production)AWS_LAMBDA_FUNCTION_NAME: Automatically detected for Lambda compatibility
AWS Lambda Usage
The library automatically detects AWS Lambda environments and adjusts logging accordingly:
from gushwork_logger import initialize_logging, get_logger
def lambda_handler(event, context):
# Initialize logging (console output disabled in Lambda)
initialize_logging(service_name="my-lambda-function")
logger = get_logger(__name__)
logger.info("Lambda function started", extra={"request_id": context.aws_request_id})
# Your Lambda logic here
return {"statusCode": 200, "body": "Success"}
API Reference
initialize_logging(service_name, environment, log_level, enable_console, enable_otlp)
Initialize the logging system with OpenTelemetry support.
Parameters:
service_name(str, optional): Name of the service. Defaults toOTEL_SERVICE_NAMEenv var or "gushwork-service"environment(str, optional): Environment name. Defaults toENVIRONMENTenv var or "dev"log_level(int, optional): Logging level. Default:logging.INFOenable_console(bool, optional): Enable console logging. Default:Trueenable_otlp(bool, optional): Enable OpenTelemetry export. Default:True
Returns:
LoggerProviderorNone: OpenTelemetry LoggerProvider instance if OTLP is enabled and successful
get_logger(name)
Get a logger instance.
Parameters:
name(str, optional): Logger name. Defaults to calling module name
Returns:
logging.Logger: Standard Python logger instance
shutdown_logging()
Shutdown the logging system and clean up resources. Call this when your application is shutting down.
is_initialized()
Check if logging has been initialized.
Returns:
bool: True if logging is initialized
get_logger_provider()
Get the current OpenTelemetry logger provider instance.
Returns:
LoggerProviderorNone: Current logger provider or None if not initialized with OTLP
Usage in Different Repositories
After publishing to PyPI, you can use this library in any Python project:
1. Add to requirements.txt
gushwork-logger>=0.1.0
2. Initialize in your main application
# main.py or app.py
from gushwork_logger import initialize_logging
def main():
initialize_logging(
service_name="my-backend-service",
environment="production"
)
# Rest of your application
3. Use in any module
# any_module.py
from gushwork_logger import get_logger
logger = get_logger(__name__)
def some_function():
logger.info("Function called")
try:
# Some operation
pass
except Exception as e:
logger.error("Operation failed", extra={"error": str(e)})
Development
Setting up development environment
git clone <repository-url>
cd gushwork-logger
pip install -r requirements-dev.txt
Running tests
pytest
Code formatting
black gushwork_logger/
flake8 gushwork_logger/
mypy gushwork_logger/
Building and publishing
# Build the package
python -m build
# Upload to PyPI (requires proper credentials)
twine upload dist/*
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Run the test suite
- Submit a pull request
Support
For issues and feature requests, please use the GitHub issue tracker.
Project details
Release history Release notifications | RSS feed
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 gushwork_logger-0.1.0.tar.gz.
File metadata
- Download URL: gushwork_logger-0.1.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ebb313cdbeed259f091c35042005bb84b79b80d39fae06cae3b5e01c398d0450
|
|
| MD5 |
1afd248b37005a66043456b69c84c1dc
|
|
| BLAKE2b-256 |
1570956ee0a5b511a0bf61cca1d95ab2e7f701d78f24b2f49f51b5a5f8dd0158
|
File details
Details for the file gushwork_logger-0.1.0-py3-none-any.whl.
File metadata
- Download URL: gushwork_logger-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d56cd33615d80ca935a9f30e608f1382ec40a4d4c3c0225b727829f7cbf8546
|
|
| MD5 |
f950de80c4a3260ab340021bb521666b
|
|
| BLAKE2b-256 |
7185afdf8ce21df5665c7d292e97ad7d355dcfaddd234e512a05001e15d5d041
|