Skip to content

mykopk/logger

Repository files navigation

@myko.pk/logger

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.

npm version npm downloads build stars forks issues last commit license

📑 Table of Contents

📝 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/common Logger. Use new Logger(MyService.name) as you already do.
  • 📝 Structured JSON Logging — Pino-powered with pretty-print in dev, JSON in production.
  • 🧩 Request-Scoped Child Loggerslogger.child({ requestId }) for distributed tracing.
  • 🔐 Built-in Audit LoggerAuditLogger.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/common Logger 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 requestId for 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/logger
import { 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

  • buildnpm run build
  • typechecknpm run typecheck
  • testnpm run test
  • test:watchnpm 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

  1. Install Node.js (v18+ recommended)
  2. Install dependencies: npm install
  3. Build: npm run build

🧪 Testing

This project uses Vitest for testing.

npm run test

👥 Contributors

arsalanwahab

See the full list of contributors →

👥 Contributing

Contributions are welcome! Here's the standard flow:

  1. Fork the repository
  2. Clone your fork: git clone https://github.com/mykopk/logger.git
  3. Branch: git checkout -b feature/your-feature
  4. Commit: git commit -m 'feat: add some feature'
  5. Push: git push origin feature/your-feature
  6. 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 support@myko.pk About Building digital infrastructure and super-app experiences for millions of users across Pakistan. Built with ❤️ in Pakistan 🇵🇰

About

Shared structured logger for @myko.pk packages — Pino wrapper with NestJS-compatible API

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors