Aurora Logger The Ultimate Library for High-performance Logging

Welcome to Aurora Logger

Aurora Logger is a powerful and highly flexible logging library designed for modern applications. It allows easy integration and provides dozens of useful APIs to tailor logging to your application’s needs.

Basic Logging

To get started with Aurora Logger, you need to initialize the basic logger configuration:

import aurora_logger as al
logger = al.get_logger("my_logger")
logger.info("This is an info message")

Log Levels

Aurora Logger supports multiple log levels, including DEBUG, INFO, WARNING, ERROR, and CRITICAL. Here are some examples:

logger.debug("Debugging information")
logger.warning("This is a warning")
logger.error("An error occurred")
logger.critical("Critical error!")

Custom Log Handlers

You can create custom log handlers to add more functionality to your logging system:

class CustomHandler(al.Handler):
    def emit(self, record):
        log_entry = self.format(record)
        print(f"Custom log entry: {log_entry}")

custom_handler = CustomHandler()
logger.addHandler(custom_handler)

Formatting Logs

Formatting log messages is a breeze with predefined formats or custom formats:

formatter = al.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
console_handler = al.StreamHandler()
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)

Configuration from File

Aurora Logger can be configured using a configuration file for easier management in production environments:

import yaml
with open('logging_config.yaml', 'r') as file:
    config = yaml.safe_load(file.read())
    al.config.dictConfig(config)

Logging to Multiple Destinations

Logging to multiple destinations such as files, databases, or external monitoring systems is easy:

file_handler = al.FileHandler('app.log')
db_handler = al.DBHandler(conn_string="database_uri")
logger.addHandler(file_handler)
logger.addHandler(db_handler)

Complete Application Example

Here is a sample application utilizing different features of Aurora Logger:

import aurora_logger as al

def main():
    logger = al.get_logger("app")
    formatter = al.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    
    console_handler = al.StreamHandler()
    console_handler.setFormatter(formatter)
    file_handler = al.FileHandler('app.log')
    file_handler.setFormatter(formatter)
    
    logger.addHandler(console_handler)
    logger.addHandler(file_handler)
    
    logger.info("Application started")
    try:
        # Application logic here
        logger.debug("This is a debug message")
        logger.info("Informational message")
    except Exception as e:
        logger.error(f"An error occurred: {e}", exc_info=True)
    logger.info("Application finished")

if __name__ == "__main__":
    main()

With Aurora Logger, managing logs becomes easier and more efficient, enabling developers to focus on building robust applications.

Hash: 02ac80108a29472ffaf766546c4872f34c0f15d3e41784284e61381c5e412e8f

Leave a Reply

Your email address will not be published. Required fields are marked *