@myko.pk/logger
v1.2.0
Published
Shared structured logger for MYKOPK packages (Pino wrapper with NestJS-compatible API)
Readme
📑 Table of Contents
- Description
- Key Features
- Use Cases
- Tech Stack
- Quick Start
- Configuration
- Available Scripts
- Project Structure
- Contributors
- Contributing
- License
📝 Description
@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.
✨ Key Features
- 🪺 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.
🎯 Use Cases
- 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.
🛠️ Tech Stack
- 📘 TypeScript
- 📝 Pino
⚡ Quick Start
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',
});Configuration
| Variable | Default | Description |
|----------|---------|-------------|
| LOG_LEVEL | debug (dev) / info (prod) | Minimum log level |
| NODE_ENV | — | Controls pretty-print vs JSON |
🚀 Available Scripts
- build —
npm run build - typecheck —
npm run typecheck - test —
npm run test - test:watch —
npm run test:watch
📁 Project Structure
.
├── 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🛠️ Development Setup
- Install Node.js (v18+ recommended)
- Install dependencies:
npm install - Build:
npm run build
🧪 Testing
This project uses Vitest for testing.
npm run test👥 Contributors
See the full list of contributors →
👥 Contributing
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.
📜 License
This project is licensed under the MIT License.
MYKO Pakistan
Detail Information Website myko.pk Email [email protected] About Building digital infrastructure and super-app experiences for millions of users across Pakistan. Built with ❤️ in Pakistan 🇵🇰
