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.2.tar.gz (6.2 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.2-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kybra_simple_logging-0.0.2.tar.gz
  • Upload date:
  • Size: 6.2 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.2.tar.gz
Algorithm Hash digest
SHA256 7122201617b006fddebfc7d074f85327448614b39894a4d105b95764042f6965
MD5 6bbf5ad529b6a351dd8a1bcd56fc2a29
BLAKE2b-256 306b5e9d07249172ccc5f9bd2b60f5d36cc2c61e5dc5bd2e6b82f72c0ae19763

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for kybra_simple_logging-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 4792ef805d31b9523a9ee2140bfeb341c549d3cd3b26b9cd338960899dfcea78
MD5 d9d8ae03a995dd67b2f5ff622fefb6f7
BLAKE2b-256 679faf37d389ee89fee0163eaea55dd451ecca72a4faa974292391ad242eee89

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