@emerson-evolution-gym/logger
v0.1.0
Published
Shared logging utilities for Evolution Gym
Downloads
6
Maintainers
Readme
@evolution-gym/logger
Shared logging utilities for Evolution Gym microservices using Pino.
Installation
npm install @evolution-gym/loggerUsage
Basic Usage
import { logger } from '@evolution-gym/logger';
logger.info('Service started');
logger.error({ err: error }, 'Failed to process request');
logger.debug({ userId: '123' }, 'User logged in');Create Custom Logger
import { createLogger } from '@evolution-gym/logger';
const logger = createLogger({
serviceName: 'auth-service',
level: 'debug',
prettyPrint: true // For development
});
logger.info('Auth service initialized');With Context
const childLogger = logger.child({
requestId: '550e8400-e29b-41d4-a716-446655440000',
tenantId: 'gym-123'
});
childLogger.info('Processing payment');
childLogger.error({ err }, 'Payment failed');Environment Variables
LOG_LEVEL- Set log level (trace, debug, info, warn, error, fatal)SERVICE_NAME- Service name for log contextNODE_ENV- Set to 'production' to disable pretty printing
Log Levels
trace- Very detailed logsdebug- Debug informationinfo- General informationwarn- Warning messageserror- Error messagesfatal- Fatal errors
Best Practices
- Always include context: Add relevant data to log messages
logger.info({ userId, action: 'login' }, 'User authenticated');- Use child loggers for request tracking:
const requestLogger = logger.child({ requestId });- Log errors with stack traces:
logger.error({ err: error }, 'Operation failed');- Use structured logging:
// Good
logger.info({ userId, amount, currency }, 'Payment processed');
// Avoid
logger.info(`Payment processed for user ${userId}`);License
MIT
