async-zulip-bot-sdk

Logging

SDK logging utilities for system and bots.

The SDK uses Loguru for logging and separates system logs from bot logs using tags and different sinks.

At a high level:

System logger setup

from bot_sdk import setup_logging

# Call once at process start (e.g. in main.py)
setup_logging(level="INFO", json_logs=False)

Parameters

setup_logging() will:

Bot loggers

Bots use their own tagged loggers so you can distinguish messages per bot and write to per-bot log files.

from bot_sdk import get_bot_logger

bot_logger = get_bot_logger("echo_bot", level="INFO")

bot_logger.info("EchoBot starting up")
bot_logger.debug("Some internal state: {}", {"foo": 1})

Behavior

In most cases you don’t need to call get_bot_logger manually:

from bot_sdk import BaseBot, Message

class MyBot(BaseBot):
    async def on_message(self, message: Message):
        self.logger.info("Received message from {}", message.sender_full_name)
        await self.send_reply(message, "Hello!")

Console integration

When running the interactive console (async-zulip-bot / main.py):

Minimal examples

Simple script with system logs

from bot_sdk import setup_logging
from loguru import logger

if __name__ == "__main__":
    setup_logging(level="DEBUG")
    logger.info("SDK starting...")
    # Your startup logic here

Bot using injected logger

from bot_sdk import BaseBot, Message

class LoggingBot(BaseBot):
    async def on_start(self) -> None:
        self.logger.info("{} started", self.__class__.__name__)

    async def on_message(self, message: Message) -> None:
        self.logger.debug("Incoming message: {}", message.content[:50])
        await self.send_reply(message, "Got it!")