Welcome to Intelli-Logger: Your Ultimate Solution for Optimized Real-Time Logging
Introducing Intelli-Logger, a versatile and powerful logging library designed to meet your real-time debugging needs. With its extensive API, it provides seamless integration into your existing applications and ensures you never miss any critical log information.
Getting Started with Intelli-Logger
Integrating Intelli-Logger is straightforward. Below is a guide to help you get started along with various API examples:
Basic Initialization
First, initialize the logger in your application file:
const { Logger } = require('intelli-logger'); const logger = new Logger();
Log Levels
Intelli-Logger supports multiple log levels to control the verbosity of your logs:
logger.info('This is an info message'); logger.warn('This is a warning message'); logger.error('This is an error message');
Log Formatting
Customize the log format to suit your needs:
const customLogger = new Logger({
format: '{timestamp} - {level}: {message}',
timestampFormat: 'YYYY-MM-DD HH:mm:ss'
}); customLogger.info('This is a custom formatted info message');
Logging Objects
Intelli-Logger allows you to log complex JSON objects:
const user = { id: 1, name: 'John Doe' }; logger.info('User details:', user);
Advanced Features of Intelli-Logger
Conditional Logging
Enable or disable logging based on conditions:
if (process.env.NODE_ENV === 'development') {
logger.debug('This is a debug message only shown in development mode');
}
Asynchronous Logging
Perform asynchronous logging for better performance:
logger.asyncLog({ level: 'info', message: 'This is an asynchronous log' })
.then(() => console.log('Log saved successfully'))
.catch(err => console.error('Failed to save log', err));
Log Rotation
Ensure your log files don’t grow indefinitely by using log rotation:
const rotatingLogger = new Logger({
rotate: { interval: '1d', maxFiles: 7 }
}); rotatingLogger.info('This log will be rotated daily and kept for 7 days');
Error Tracking
Integrate with third-party error tracking services:
const Sentry = require('@sentry/node'); Sentry.init({ dsn: 'YOUR_SENTRY_DSN' });
try {
// Your code
} catch (error) {
logger.error('An error occurred', error);
Sentry.captureException(error);
}
Application Example with Intelli-Logger
Here is a comprehensive application example using the Intelli-Logger APIs introduced above:
const express = require('express'); const { Logger } = require('intelli-logger'); const Sentry = require('@sentry/node');
Sentry.init({ dsn: 'YOUR_SENTRY_DSN' });
const app = express(); const logger = new Logger({ format: '{timestamp} - {level}: {message}' });
app.use((req, res, next) => {
logger.info(`Request to ${req.url}`);
next();
});
app.get('/', (req, res) => {
res.send('Hello, Intelli-Logger!');
logger.info('Sent response to root endpoint');
});
app.use((err, req, res, next) => {
logger.error('Internal Server Error', err);
Sentry.captureException(err);
res.status(500).send('Something broke!');
});
const port = 3000; app.listen(port, () => logger.info(`Server running on port ${port}`));
By integrating Intelli-Logger, you can ensure robust and thread-safe logging, making your debugging process more effective and efficient.
Enhance your application with Intelli-Logger today and experience the power of seamless logging!
Hash: f8da01c9aa039c4bac3a284f3427a859e004c68a9e2467b6c9d109180a090d16