
Product
Introducing Scala and Kotlin Support in Socket
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
kybra-simple-logging
Advanced tools
A simple logging system for the Internet Computer built with Kybra. The library includes in-memory log storage capabilities, providing robust logging for all canister functions including asynchronous operations.
--follow
)get_logger()
function similar to Python's standard librarypip install kybra-simple-logging
from kybra_simple_logging import get_logger
# Create a logger
logger = get_logger("my_canister")
# Log messages at a specific level
logger.info("This is an info message")
# Set log level for a specific logger
logger.set_level(LogLevel.DEBUG)
# Use in-memory logging to retrieve logs
from kybra_simple_logging import get_logs, clear_logs, enable_memory_logging, disable_memory_logging
# Retrieve only ERROR logs
error_logs = get_logs(min_level="ERROR")
# Filter logs by logger name
component_logs = get_logs(logger_name="my_component")
The package includes a command-line tool for querying logs from canisters. Example:
# View the first 10 ERROR log entries of logger with name MY_LOGGER_NAME, and then follow and poll every 5 seconds, from the canister with ID <CANISTER_ID> on the IC network
kslog <CANISTER_ID> --tail 10 --level ERROR --name MY_LOGGER_NAME --follow --ic --interval 5
To use this kslog
with your canister, expose the query function:
# ##### Import Kybra and the internal function #####
from kybra import Opt, Record, Vec, nat, query
from kybra_simple_logging import get_canister_logs as _get_canister_logs
# Define the PublicLogEntry class directly in the test canister
class PublicLogEntry(Record):
timestamp: nat
level: str
logger_name: str
message: str
id: nat
@query
def get_canister_logs(
from_entry: Opt[nat] = None,
max_entries: Opt[nat] = None,
min_level: Opt[str] = None,
logger_name: Opt[str] = None,
) -> Vec[PublicLogEntry]:
"""
Re-export the get_canister_logs query function from the library
This makes it accessible as a query method on the test canister
"""
logs = _get_canister_logs(
from_entry=from_entry,
max_entries=max_entries,
min_level=min_level,
logger_name=logger_name
)
# Convert the logs to our local PublicLogEntry type
return [
PublicLogEntry(
timestamp=log["timestamp"],
level=log["level"],
logger_name=log["logger_name"],
message=log["message"],
id=log["id"],
)
for log in logs
]
# Clone the repository
git clone https://github.com/smart-social-contracts/kybra-simple-logging.git
cd kybra-simple-logging
# Recommended setup
pyenv install 3.10.7
pyenv local 3.10.7
python -m venv venv
source venv/bin/activate
pip install kybra
python -m kybra install-dfx-extension
# Install development dependencies
pip install -r requirements-dev.txt
# Run linters
./run_linters.sh
# Run tests
cd tests && ./run_test.sh
Contributions are welcome! Please feel free to submit a Pull Request.
MIT
FAQs
A lightweight logging library for Kybra on the Internet Computer (IC)
We found that kybra-simple-logging demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.
Research
/Security News
Threat actors hijacked Toptal’s GitHub org, publishing npm packages with malicious payloads that steal tokens and attempt to wipe victim systems.