Log once. Understand everywhere.
Structured logger for MYKO services built on Pino with a NestJS-compatible API. Drop-in replacement for @nestjs/common Logger. Includes a built-in audit event logger.
- Description
- Key Features
- Use Cases
- Tech Stack
- Quick Start
- Configuration
- Available Scripts
- Project Structure
- Contributors
- Contributing
- License
@myko.pk/logger provides a structured, Pino-based logger for every MYKO service. It offers a NestJS-compatible API (Logger.log, Logger.error, etc.) so it can be used as a drop-in replacement for @nestjs/common's Logger, while also supporting ad-hoc logging via a global logger instance and request-scoped child loggers. Built-in AuditLogger captures auth, security, and system audit events with structured metadata.
- 🪺 NestJS-Compatible API — Drop-in replacement for
@nestjs/commonLogger. Usenew Logger(MyService.name)as you already do. - 📝 Structured JSON Logging — Pino-powered with pretty-print in dev, JSON in production.
- 🧩 Request-Scoped Child Loggers —
logger.child({ requestId })for distributed tracing. - 🔐 Built-in Audit Logger —
AuditLogger.logAuth,AuditLogger.logSystem, etc. for structured audit trails. - 📘 Fully Typed — Full TypeScript support with typed audit event types and severity levels.
- Replacing
@nestjs/commonLogger across all NestJS microservices with a structured Pino-based logger. - Capturing auth events (login success/failure, token refresh) with structured audit metadata.
- Creating request-scoped loggers with
requestIdfor tracing requests across microservices. - Standardising log output format across all MYKO services for centralised log aggregation.
- 📘 TypeScript
- 📝 Pino
npm install @myko.pk/loggerimport { Logger } from '@myko.pk/logger';
// NestJS-style logging
class MyService {
private readonly logger = new Logger(MyService.name);
doSomething() {
this.logger.log('Hello world');
this.logger.error('Something broke', error);
}
}
// Ad-hoc logging
import { logger } from '@myko.pk/logger';
logger.info('Server started', { port: 3000 });
// Request-scoped child logger
const reqLogger = logger.child({ requestId: 'abc-123' });
reqLogger.log('Handling request');
// Audit events
import { AuditLogger, AuditEventType, AuditSeverity } from '@myko.pk/logger';
await AuditLogger.logAuth(AuditEventType.LOGIN_SUCCESS, AuditSeverity.LOW, {
mykoId: 'usr_abc',
ipAddress: '192.168.1.1',
});| Variable | Default | Description |
|---|---|---|
LOG_LEVEL |
debug (dev) / info (prod) |
Minimum log level |
NODE_ENV |
— | Controls pretty-print vs JSON |
- build —
npm run build - typecheck —
npm run typecheck - test —
npm run test - test:watch —
npm run test:watch
.
├── CHANGELOG.md
├── CONTRIBUTING.md
├── LICENSE
├── SECURITY.md
├── package.json
├── src
│ ├── AuditLogger.ts
│ ├── Logger.ts
│ ├── PinoLogger.ts
│ ├── index.ts
│ └── types.ts
├── tsconfig.json
└── tsup.config.mjs
- Install Node.js (v18+ recommended)
- Install dependencies:
npm install - Build:
npm run build
This project uses Vitest for testing.
npm run testSee the full list of contributors →
Contributions are welcome! Here's the standard flow:
- Fork the repository
- Clone your fork:
git clone https://github.com/mykopk/logger.git - Branch:
git checkout -b feature/your-feature - Commit:
git commit -m 'feat: add some feature' - Push:
git push origin feature/your-feature - Open a pull request
Please follow the existing code style and include tests for new behavior where applicable.
This project is licensed under the MIT License.
MYKO Pakistan
Detail Information Website myko.pk Email support@myko.pk About Building digital infrastructure and super-app experiences for millions of users across Pakistan. Built with ❤️ in Pakistan 🇵🇰