Custom Logging
Example showing how to use a custom logger with Kern.
1"""2Custom Logging3=============================45Example showing how to use a custom logger with Kern.6"""78import logging910from kern.agent import Agent11from kern.utils.log import configure_agno_logging, log_info121314def get_custom_logger():15 """Return an example custom logger."""16 custom_logger = logging.getLogger("custom_logger")17 handler = logging.StreamHandler()18 formatter = logging.Formatter("[CUSTOM_LOGGER] %(levelname)s: %(message)s")19 handler.setFormatter(formatter)20 custom_logger.addHandler(handler)21 custom_logger.setLevel(logging.INFO) # Set level to INFO to show info messages22 custom_logger.propagate = False23 return custom_logger242526# Get the custom logger we will use for the example.27custom_logger = get_custom_logger()2829# Configure Kern to use our custom logger. It will be used for all logging.30configure_agno_logging(custom_default_logger=custom_logger)3132# Every use of the logging function in kern.utils.log will now use our custom logger.33log_info("This is using our custom logger!")3435# Now let's setup an Agent and run it.36# All logging coming from the Agent will use our custom logger.37# ---------------------------------------------------------------------------38# Create Agent39# ---------------------------------------------------------------------------40agent = Agent()4142# ---------------------------------------------------------------------------43# Run Agent44# ---------------------------------------------------------------------------45if __name__ == "__main__":46 agent.print_response("What can I do to improve my sleep?")Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/14_advanced45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python custom_logging.py