
Research
/Security News
Weaponizing Discord for Command and Control Across npm, PyPI, and RubyGems.org
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
nestjs-logitron
Advanced tools
Powerful logger module for Nodejs/ Nestjs, seamlessly integrating Pino and Winston for flexible logging with easy configuration.
A lightweight, high-performance logging utility for NestJS applications, built on Pino and Winston, with execution time tracking, request tracing, and Kafka trace interception.
Pino
(lightweight, high-performance) and Winston
(multi-transport support) based on your needs.Install via npm:
npm install nestjs-logitron
or via yarn:
yarn add nestjs-logitron
main.ts
You can initialize the logger with either PINO
or WINSTON
as the logging backend.
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { LoggerService } from 'nestjs-logitron';
async function bootstrap() {
const app = await NestFactory.create(AppModule, { bufferLogs: true });
app.useLogger(app.get(LoggerService));
await app.listen(3000);
}
bootstrap().catch(console.error);
app.module.ts
import { Module } from '@nestjs/common';
import { LoggerType, LoggerModule } from 'nestjs-logitron';
import { AppController } from './app.controller';
import { AppService } from './app.service';
@Module({
imports: [
LoggerModule.forRoot({
type: LoggerType.PINO,
options: {
transport: {
targets: [
{
target: 'pino-pretty',
options: {
destination: 'api.log',
singleLine: true,
colorize: false,
translateTime: 'yyyy-mm-dd HH:MM:ss',
},
},
{
target: 'pino-pretty',
options: {
colorize: true,
translateTime: 'yyyy-mm-dd HH:MM:ss',
},
},
],
},
},
}),
],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {}
import { Controller, Get, Logger } from '@nestjs/common';
import { AppService } from './app.service';
import { TraceIdHandler } from 'nestjs-logitron';
@Controller()
export class AppController {
constructor(private readonly appService: AppService) {}
private readonly logger = new Logger(AppController.name);
@Get()
async getHello() {
this.logger.debug({ traceId: TraceIdHandler.getTraceId() });
return this.appService.getWorld();
}
}
async_hooks
for Trace ID StorageHandling trace IDs in asynchronous environments (like HTTP requests, DB queries, and background tasks) is difficult because global variables do not retain execution context.
Node.js async_hooks
enables continuation-local storage (CLS), ensuring that each trace ID is bound to its originating request, even in async operations.
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';
import { v4 as uuidv4 } from 'uuid';
import { TraceIdHandler, withTraceId } from 'nestjs-logitron';
@Injectable()
export class TraceMiddleware implements NestMiddleware {
use(req: Request, _: Response, next: NextFunction) {
const traceId = req.headers['x-trace-id'] || uuidv4();
withTraceId(traceId, () => next());
}
}
In microservices architectures, messages pass through Kafka, but they lose their original HTTP request trace IDs. This makes debugging very difficult.
traceId
from Kafka messages (if present) or generates a new one.traceId
using async_hooks
.traceId
.import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { Observable } from 'rxjs';
import { v4 as uuidv4 } from 'uuid';
import { TraceIdHandler, withTraceId } from 'nestjs-logitron';
@Injectable()
export class KafkaTraceInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const payload = context.switchToRpc().getData();
const traceId = payload?.traceId ?? uuidv4();
return new Observable((subscriber) => {
withTraceId(traceId, () => {
next.handle().subscribe({
next: (value) => subscriber.next(value),
error: (err) => subscriber.error(err),
complete: () => subscriber.complete(),
});
});
});
}
}
[yyyy-mm-dd HH:MM:ss.MS] [log_level] [app_name] [trace_id] [message] [payload] [time_taken_MS]
Example:
[2025-03-18T06:30:20.156Z] [ERROR] [NESTJS-LOGITRON] [12345-trace-id] [Something went wrong] [N/A] [N/A]
We welcome contributions from the community! 🚀
git checkout -b feature-name
.git commit -m "Added new feature"
.git push origin feature-name
.nestjs-logitron
is licensed under the MIT License.
Have questions? Found an issue? Open an issue on GitHub or reach out!
Happy logging! 📜✨
FAQs
Powerful logger module for Nodejs/ Nestjs, seamlessly integrating Pino and Winston for flexible logging with easy configuration.
We found that nestjs-logitron demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
Socket researchers uncover how threat actors weaponize Discord across the npm, PyPI, and RubyGems ecosystems to exfiltrate sensitive data.
Security News
Socket now integrates with Bun 1.3’s Security Scanner API to block risky packages at install time and enforce your organization’s policies in local dev and CI.
Research
The Socket Threat Research Team is tracking weekly intrusions into the npm registry that follow a repeatable adversarial playbook used by North Korean state-sponsored actors.