Node.js
ByteHide Logger provides full logging capabilities in Node.js environments, including console and file logging.
Installation
npm install @bytehide/logger
Basic Setup
const { Log } = require('@bytehide/logger');
// Configure logger
Log.configure({
projectToken: 'your-project-token',
logLevel: 'info',
consoleOutput: true,
fileOutput: {
enabled: true,
path: './logs'
}
});
// Start logging
Log.info('Application started');
File Logging
Node.js supports file logging with automatic rotation:
Log.configure({
projectToken: 'your-project-token',
fileOutput: {
enabled: true,
path: './logs',
maxFileSize: '10MB',
maxFiles: 5
}
});
Environment Variables
// Load from environment
Log.configure({
projectToken: process.env.BYTEHIDE_PROJECT_TOKEN,
logLevel: process.env.LOG_LEVEL || 'info'
});
Express.js Integration
const express = require('express');
const app = express();
app.use((req, res, next) => {
Log.info('Request received', {
context: { method: req.method, url: req.url }
});
next();
});
Best Practices
Node.js Best Practices
- Use file logging for production applications
- Configure log rotation to manage disk space
- Use environment variables for configuration
- Log unhandled exceptions and promise rejections