Welcome to Loggalot
Loggalot is a powerful logging library that simplifies the process of logging and debugging in your applications. With dozens of API functions, Loggalot provides the flexibility and control you need for robust and efficient logging. Let’s explore some of its features and functionalities through practical examples.
API Examples
1. Basic Logging
Get started with simple log messages:
import loggalot logger = loggalot.getLogger('exampleLogger') logger.info('This is an info message') logger.warn('This is a warning message') logger.error('This is an error message')
2. Log with Different Levels
Control the verbosity of your logs with various levels:
logger.debug('This is a debug message') logger.critical('This is a critical message')
3. Advanced Configuration
Customize log formats and handlers:
from loggalot import Formatter, FileHandler formatter = Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s') file_handler = FileHandler('app.log') file_handler.setFormatter(formatter) logger.addHandler(file_handler)
4. Exception Logging
Effortlessly log exceptions:
try: 1 / 0 except ZeroDivisionError as e: logger.exception('An exception occurred')
5. Multiple Handlers
Log to both console and file with multiple handlers:
from loggalot import StreamHandler console_handler = StreamHandler() console_handler.setLevel(logging.DEBUG) logger.addHandler(console_handler)
Application Example
Here’s a small application that leverages Loggalot for logging:
from loggalot import Logger class MyApp: def __init__(self): self.logger = Logger(__name__) self.setup_logging() def setup_logging(self): formatter = Formatter('%(levelname)s: %(message)s') console_handler = StreamHandler() console_handler.setFormatter(formatter) self.logger.addHandler(console_handler) def run(self): self.logger.info('Application started') try: self.process_data() except Exception as e: self.logger.exception('Error in processing data') def process_data(self): self.logger.debug('Processing data...') # Simulate data processing data = [1, 2, 3, 4, 5] if len(data) == 5: raise ValueError('Data length is invalid') if __name__ == "__main__": app = MyApp() app.run()
In this example, we initialize the logger, set up a custom formatter and handler, and use the logger to track the flow of the application and capture exceptions.
Integrate Loggalot into your projects today to streamline your logging and debugging tasks!
Hash: 1d41c06431b7b38b6550e3f6cc5eab8d061bf9a62be9104bcc14d5626c56eff8