@nldoc/logger
v1.1.81
Published
A logger package that handles logging in ECS format. Based on Pino.
Readme
NLdoc TypeScript Logger
A TypeScript logger package that provides structured logging in ECS (Elastic Common Schema) format. Built on top of Pino for high-performance logging with environment-configurable settings.
Overview
This logger provides:
- ECS-formatted structured logging for better log analysis
- Environment-based configuration (logging enabled/disabled, trace levels)
- Built-in metadata injection (logger version, environment, Node.js version)
- TypeScript support with full type safety
- High-performance logging through Pino
Getting Started
Prerequisites
- Node.js >= 22
Installation
Install the package via npm:
npm install @nldoc/loggerBasic Usage
import { logger } from '@nldoc/logger';
// Simple logging
logger.info('Application started');
// Structured logging with additional context
logger.child({ userId: '123', module: 'auth' }).info('User logged in');
// Different log levels
logger.debug('Debug information');
logger.warn('Warning message');
logger.error('Error occurred');Configuration
The logger can be configured through environment variables:
LOGGING_ENABLED(default:true) - Enable/disable loggingTRACE_ENABLED(default:false) - Enable trace-level loggingENVIRONMENT(default:development) - Environment identifierNODE_VERSION- Node.js version (automatically injected into logs)
Development
Local Setup
Clone the repository:
git clone https://gitlab.com/logius/nldoc/lib/typescript/logger.git cd typescript-loggerInstall dependencies:
npm installBuild the project:
npm run build
Available Scripts
npm run test- Run the test suite with coveragenpm run build- Build TypeScript to JavaScriptnpm run check- Type-check without emitting filesnpm run lint- Lint the codebasenpm run format- Format code using Prettiernpm run fix- Auto-fix linting and formatting issues
API Documentation
For detailed Pino API documentation, see the official Pino documentation.
Testing
Run the test suite:
npm testContributing
We welcome contributions! Please ensure:
- All tests pass (
npm test) - Code is properly formatted (
npm run format:check) - Linting rules are followed (
npm run lint) - Type checking passes (
npm run check)
License
This project is licensed under the European Union Public License 1.2 - see LICENSE for details.
Acknowledgements
- Built on Pino - fast and low overhead Node.js logger
- Uses Elastic ECS Pino Format for structured logging
