Introduction to Augment Logger
Welcome to Augment Logger, the ultimate tool to enhance and streamline your logging experience. Designed for developers who seek detailed and customizable logging solutions, Augment Logger offers dozens of useful API methods to suit your specific needs. This guide will introduce you to these APIs with code snippets and provide a comprehensive app example to demonstrate their usage.
Core API Methods
1. Basic Logging
from augment_logger import Logger
logger = Logger()
logger.info("This is an info message")
logger.warning("This is a warning message")
logger.error("This is an error message")
2. Advanced Logging Levels
logger.debug("This is a debug message")
logger.critical("This is a critical message")
3. Custom Log Formatting
from augment_logger import Logger, Formatter
formatter = Formatter(fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger.set_formatter(formatter)
logger.info("Logging with custom format")
4. File Logging
logger = Logger(output_file="app.log")
logger.info("This message will be logged to a file")
5. Rotating File Handler
from augment_logger import RotatingFileHandler
handler = RotatingFileHandler("app.log", maxBytes=2000, backupCount=2)
logger.add_handler(handler)
logger.info("This message will be logged with rotation")
6. Adding Custom Handlers
from augment_logger import StreamHandler
console_handler = StreamHandler()
logger.add_handler(console_handler)
logger.info("This message will appear in the console")
7. Setting Logging Levels
logger.set_level("DEBUG")
logger.debug("Debug level message after setting level")
8. Using Filters
def filter_debug(record):
return record.levelname == 'DEBUG'
logger.add_filter(filter_debug)
logger.debug("This debug message will pass the filter")
logger.info("This info message will be skipped by the filter")
Application Example Using Augment Logger
Below is an example of a simple web application integrating the Augment Logger for robust logging capabilities.
from flask import Flask
from augment_logger import Logger
app = Flask(__name__)
logger = Logger(output_file="webapp.log")
@app.route('/')
def home():
logger.info("Home page accessed")
return "Welcome to the Home Page"
@app.route('/about')
def about():
logger.info("About page accessed")
return "Welcome to the About Page"
if __name__ == "__main__":
logger.info("Starting the web application")
app.run(debug=True)
logger.info("Web application is running")
This application logs various events such as page accesses and application start-up, demonstrating how the Augment Logger can be seamlessly integrated into your projects.
Hash: 446b6bc0dfa3ac050c487fdd79689cb1b05d619e9d9c7ab5c16626f7c8018f93