Skip to main content

A lightweight logging library for Kybra on the Internet Computer (IC)

Project description

Kybra Simple Logging

Test Python Versions License

A robust logging system for Internet Computer canisters built with Kybra, designed to overcome the limitations of Python's standard logging module in the IC environment.

Features

  • Works seamlessly in both Internet Computer and non-IC environments
  • Avoids using Python's standard logging module (which has compatibility issues in the IC environment)
  • Named loggers with get_logger() function similar to Python's standard library
  • Support for level-based filtering (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • Global and per-logger log level configuration
  • Ability to enable/disable logging completely
  • Best practices for library logging implementation

Installation

Using pip

pip install kybra-simple-logging

Manual Installation

In your Kybra project, simply copy the kybra_simple_logging directory to your project.

Quick Start

from kybra_simple_logging import get_logger

# Create a logger
logger = get_logger("my_canister")

# Log messages at different levels
logger.debug("This is a debug message")
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
logger.critical("This is a critical message")

# Configure logging
from kybra_simple_logging import set_log_level, LogLevel

# Set global log level
set_log_level(LogLevel.INFO)

# Set log level for a specific logger
logger.set_level(LogLevel.DEBUG)

# Disable logging completely
from kybra_simple_logging import disable_logging, enable_logging

disable_logging()
# ... operations without logging ...
enable_logging()

Advanced Usage

Creating Multiple Loggers

# Create loggers for different components
db_logger = get_logger("database")
api_logger = get_logger("api")
auth_logger = get_logger("auth")

# Set different log levels per component
db_logger.set_level(LogLevel.DEBUG)  # More verbose logging for database
api_logger.set_level(LogLevel.INFO)  # Standard logging for API
auth_logger.set_level(LogLevel.WARNING)  # Only warnings and above for auth

In Kybra Canister Functions

from kybra import query
from kybra_simple_logging import get_logger

logger = get_logger("my_canister")

@query
def get_data():
    logger.info("Processing get_data request")
    # ... your code ...
    return result

Development

# Clone the repository
git clone https://github.com/smart-social-contracts/kybra-simple-logging.git
cd kybra-simple-logging

# Recommended setup
pip install pyenv virtualenv
pyenv local 3.10.7
python -m virtualenv venv
source venv/bin/activate

# Install development dependencies
pip install -r requirements-dev.txt

# Run tests
cd tests && ./run_test.sh

# Run linters
black .
isort .
flake8 .
mypy .

Running Tests

pip install -r requirements-dev.txt
python -m pytest -v

License

MIT

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

kybra_simple_logging-0.0.3.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

kybra_simple_logging-0.0.3-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

Details for the file kybra_simple_logging-0.0.3.tar.gz.

File metadata

  • Download URL: kybra_simple_logging-0.0.3.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.16

File hashes

Hashes for kybra_simple_logging-0.0.3.tar.gz
Algorithm Hash digest
SHA256 907d1dc34fe421bd3673fe81bdf903ecf83b11c396f093e691d2386b0d987dd6
MD5 306f351cd1505331f7490b1cc8e321b9
BLAKE2b-256 4c9f43918a0dfa63487c59f842a3869ee49e505167711c0f674e4a74f0cfaa61

See more details on using hashes here.

File details

Details for the file kybra_simple_logging-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for kybra_simple_logging-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5463ccd1f60d7022707dc696e86986ad68e8c60b427ce3dd850089e7ca1d26c0
MD5 aee3aa07680eb4a14d2d00e52d884ba8
BLAKE2b-256 f7fdf18f289701d8391190c176777072e7272f95f84c49dc5f09381ff415ecff

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