
Security News
Risky Biz Podcast: Making Reachability Analysis Work in Real-World Codebases
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
@arv-bedrock/logger
Advanced tools
Request tracing and logging middleware for NestJS microservices with Winston colored output
A powerful Nest.js logger middleware that supports both structured JSON logging (Loki-optimized) and pretty console output.
npm i @arv-bedrock/logger
import { Logger, LoggerInterceptor, LoggerOptions, LogLevel, setupHttpInterceptor } from '@arv-bedrock/logger';
import { HttpService } from '@nestjs/axios';
const app = await NestFactory.create(AppModule);
// Create logger instance
// Add logger into file main.ts
const options: LoggerOptions = {
level: LogLevel.INFO, // Minimum log level
format: 'loki', // 'loki' or 'pretty'
timestamp: true, // Include timestamps
serviceName: 'smart-utilities' // Service name for identification
};
const logger = new Logger(options);
// Create and use the logger interceptor
const interceptor = new LoggerInterceptor(logger);
app.use(interceptor.logRequest.bind(interceptor));
// **(optional) If you use httpService from @nestjs/axios add this code it will intercept your axios request and response
const httpService = app.get(HttpService);
setupHttpInterceptor(logger, httpService);
// Direct logging
logger.debug('Debug message');
logger.info('Info message');
logger.warn('Warning message');
logger.error('Error message', new Error('Something went wrong'));
interface LoggerOptions {
level?: LogLevel; // DEBUG, INFO, WARN, ERROR (default: INFO)
timestamp?: boolean; // Include timestamps (default: true)
format?: 'loki' | 'pretty'; // Log format (default: 'loki')
serviceName?: string; // Service name for identification
maxBodySize?: number; // Maximum response body size in bytes (default: 1MB)
}
The logger automatically handles request IDs for tracing requests across services:
Example of request ID header:
x-request-id: de021845-08ec-4158-8e83-d8f1022931a5
Outputs structured JSON logs optimized for Grafana Loki ingestion:
{
"labels": {
"level": "INFO",
"service": "smart-utilities",
"timestamp": "2025-03-08T17:53:27.164Z",
"request_id": "de021845-08ec-4158-8e83-d8f1022931a5",
"method": "GET",
"path": "/api/example"
},
"message": "Incoming GET /api/example",
"data": {
"requestId": "de021845-08ec-4158-8e83-d8f1022931a5",
"method": "GET",
"path": "/api/example",
"params": {},
"query": {},
"headers": {},
"timestamp": 1741456407164,
"type": "request"
}
}
Human-readable colored output for local development:
[2025-03-08T17:53:27.164Z] [smart-utilities] [INFO] [de021845-08ec] Incoming GET /api/example
The logger intelligently handles response bodies:
Size Limit:
maxBodySize
option (in bytes)[Content Excluded: <size> bytes]
Binary Content:
Example configuration with custom body size limit:
const logger = new Logger({
maxBodySize: 512 * 1024, // Set 512KB limit
format: 'pretty',
serviceName: 'my-service'
});
{serviceName="smart-utilities"} | json | data_statusCode = 200
{serviceName="smart-utilities"} | json | data_method = "GET" and data_path = "/api/example"
{serviceName="smart-utilities"} | json
| data_timestamp > unix_timestamp("2025-03-08T17:53:27.164Z")
| data_timestamp < unix_timestamp("2025-03-08T17:53:28.519Z")
Follow request across services:
{app=~".*"} | json | request_id = "de021845-08ec-4158-8e83-d8f1022931a5"
Query nested JSON response data:
{serviceName="smart-utilities"} | json | data_body := unwrap data.body | json data_body
| paymentStatus[*].label = "รอการถอดถอนมาตร"
The logger automatically handles errors and prevents duplicate error logs. Each error is logged only once with:
MIT
FAQs
Request tracing and logging middleware for NestJS microservices with Winston colored output
We found that @arv-bedrock/logger demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 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.
Security News
This episode explores the hard problem of reachability analysis, from static analysis limits to handling dynamic languages and massive dependency trees.
Security News
/Research
Malicious Nx npm versions stole secrets and wallet info using AI CLI tools; Socket’s AI scanner detected the supply chain attack and flagged the malware.
Security News
CISA’s 2025 draft SBOM guidance adds new fields like hashes, licenses, and tool metadata to make software inventories more actionable.