Comprehensive Guide to Aegis Logger Unleashing Powerful APIs for Enhanced Application Logging

Introduction to Aegis Logger

Aegis Logger is an advanced and powerful library designed for seamless application logging. It provides a plethora of features and APIs that make application logging and debugging efficient and effective.

Core Features and API Examples

Basic Usage

Importing and setting up the basic logger:

  
    const Logger = require('aegis-logger');
    const logger = new Logger();
    logger.log('This is a basic log message');
  

Log Levels

Aegis Logger supports various log levels to categorize log messages:

  
    logger.info('This is an info message');
    logger.warn('This is a warning message');
    logger.error('This is an error message');
    logger.debug('This is a debug message');
  

Customizing Log Levels

You can define custom log levels based on the specific needs of your application:

  
    const customLevels = {
      levels: {
        fatal: 0,
        error: 1,
        warn: 2,
        info: 3,
        debug: 4,
        trace: 5
      }
    };
    const customLogger = new Logger({ levels: customLevels.levels });
    customLogger.fatal('This is a fatal error message');
  

Formatting Log Messages

Customizing the format of log messages:

  
    const format = '([timestamp]) [level]: [message]';
    const formattedLogger = new Logger({ format });
    formattedLogger.info('This is a formatted info message');
  

Log Rotation

Enable log rotation to manage size and number of log files:

  
    const rotationOptions = {
      maxSize: '10M',
      maxFiles: '14d'
    };
    const rotatingLogger = new Logger({ rotation: rotationOptions });
    rotatingLogger.log('This is a log message with rotation enabled');
  

Application Example

Below is an example of a simple Node.js application using Aegis Logger:

  
    const express = require('express');
    const Logger = require('aegis-logger');
    const app = express();
    const logger = new Logger();

    app.use((req, res, next) => {
      logger.info(`Received request for ${req.url}`);
      next();
    });

    app.get('/', (req, res) => {
      logger.debug('Handling root route');
      res.send('Hello, Aegis Logger!');
    });

    app.listen(3000, () => {
      logger.info('Server is running on port 3000');
    });
  

This example demonstrates logging various levels of messages in an Express application, from incoming requests to route handling, and the server start-up.

Hash: ec639e54e6d4f6603bb7f811f62b34a115a124529df43b87e41d57b459db5c55

Leave a Reply

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