Comprehensive Guide to 360 Logger Explore Dozens of Useful APIs with Code Snippets

Welcome to 360 Logger

The 360 Logger is a powerful logging library designed to help developers record, track, and analyze application events effortlessly. With a wide range of useful APIs, it’s your perfect solution for meticulous tracking and debugging.

Getting Started

First, install the 360 Logger library using npm:

npm install 360-logger

Basic Configuration

Initializing the 360 Logger is straightforward:

 const { Logger } = require('360-logger');
const config = {
    level: 'debug',
    transports: [
        new Logger.transports.Console(),
        new Logger.transports.File({ filename: 'app.log' })
    ]
};
const logger = new Logger(config); 

Logging Levels

360 Logger supports multiple logging levels:

 logger.debug('Debugging info'); logger.info('Information message'); logger.warn('Warning message'); logger.error('Error message'); 

Transport Mechanisms

Configure different transport mechanisms to log messages to various destinations:

 const { transports } = require('360-logger');
const logger = new Logger({
    transports: [
        new transports.Console(),
        new transports.File({ filename: 'app.log' }),
        new transports.Http({ url: 'http://example.com/log' })
    ]
}); 

Custom Formats

Create custom log formats to structure your log messages:

 const { format, transports } = require('360-logger');
const customFormat = format.combine(
    format.timestamp(),
    format.printf(info => `${info.timestamp} [${info.level}]: ${info.message}`)
);
const logger = new Logger({
    format: customFormat,
    transports: [
        new transports.Console()
    ]
}); 

Exception Handling

Handling exceptions is a breeze with 360 Logger:

 const logger = new Logger({
    transports: [
        new transports.Console(),
        new transports.File({ filename: 'exceptions.log' })
    ],
    exceptionHandlers: [
        new transports.Console({ timestamp: true }),
        new transports.File({ filename: 'exceptions.log' })
    ]
}); 

Profiling Application Performance

Profile your application performance easily:

 logger.profile('test');
setTimeout(() => {
    logger.profile('test');
}, 1000); 

Using Middleware in Apps

Example using 360 Logger with Express.js:

 const express = require('express'); const { Logger } = require('360-logger');
const app = express(); const logger = new Logger({
    transports: [new Logger.transports.Console()]
});
// Middleware for logging requests app.use((req, res, next) => {
    logger.info(`Received request: ${req.method} ${req.url}`);
    next();
});
app.get('/', (req, res) => {
    res.send('Hello, World!');
    logger.info('Handled request for /');
});
app.listen(3000, () => {
    logger.info('Server started on port 3000');
}); 

The above example demonstrates how to integrate 360 Logger into an Express.js application, providing seamless logging functionality for tracking requests and activities within the app.

By harnessing the power of 360 Logger, developers can enhance their logging capabilities, streamline debugging processes, and ensure their applications run smoothly and efficiently.

Hash: 98bd7abac75a1937e9de9007c4fec3f82900fbb4334b24fdf4fa12f2827ab8f9

Leave a Reply

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