logtrace-node
v1.0.0
Published
Node.js SDK for the centralized logging service
Readme
Logger SDK for Node.js
A simple and effective logging SDK for Node.js applications that sends logs to your centralized logging service.
Installation
npm install @yourlogger/node-logger
# or
yarn add @yourlogger/node-loggerQuick Start
const { Logger } = require('@yourlogger/node-logger');
// Initialize the logger
const logger = new Logger({
apiKey: 'your-api-key',
projectId: 'your-project-id'
});
// Send logs
logger.info('Application started');
logger.warn('Resource usage high', { cpu: '80%', memory: '75%' });
logger.error('Failed to connect to database', { error: 'Connection timeout' });API Reference
Initialization
const logger = new Logger({
apiKey: 'your-api-key', // Required: Your API key
projectId: 'your-project-id', // Required: Your project ID
apiUrl: 'https://api.logger.com', // Optional: API endpoint (default: https://api.logger.com)
defaultContext: { // Optional: Default context included with all logs
service: 'user-service',
environment: 'production'
}
});Methods
logger.info(message, context?)- Log an informational messagelogger.warn(message, context?)- Log a warning messagelogger.error(message, context?)- Log an error messagelogger.debug(message, context?)- Log a debug message
Each method returns a Promise that resolves to a boolean indicating whether the log was successfully sent.
Context
All methods accept an optional context object which will be merged with the default context:
logger.info('User logged in', {
userId: 'user123',
loginMethod: 'email'
});TypeScript Support
This package includes TypeScript declarations.
License
MIT
