
Security News
Crates.io Users Targeted by Phishing Emails
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
nestjs-logger-roarr
Advanced tools
Roarr integration for NestJS Logging (compatible with ConsoleLogger and LoggerService)
NestJS Logger integration for Roarr (compatible with ConsoleLogger and LoggerService)
pnpm install nestjs-logger-roarr
NOTE Do not forget to set
ROARR_LOG=true
otherwise you will see no log messages!
To use the same logger for lower level NestJS code and your own:
import { RoarrLoggerService } from nestjs-logger-roarr';
import { AppModule } from "app.module";
const logger = RoarrLoggerService.sharedInstance();
const app = await NestFactory.create(AppModule, { logger });
As you might expect, calling RoarrLoggerService.sharedInstance()
multiple times returns the same Service
.
If you'd like to use the module directly:
import { Module } from '@nestjs/common';
import { RoarrLoggerModule } from 'nestjs-logger-roarr;
@Module({
imports: [
RoarrLoggerModule.forRoot(),
],
})
export class AppModule {}
Note that by importing the module, the lower level NestJS code will use a possibly different logger, while your AppModule
will use RoarrLoggerModule
. See the previously mentioned .sharedInstance()
if you want all logged code to use the RoarrLoggerService
.
If you'd like to do build the logger service asynchronously (for example to inject some options):
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config;
import { RoarrLoggerService } from 'nestjs-logger-roarr;
@Module({
imports: [
RoarrLoggerService.forRootAsync({
imports: [ ConfigModule ],
useFactory: async (cfg:ConfigService) => ({
logLevel: 'debug',
environment: cfg.get('ENVIRONMENT') ?? 'staging',
ctx: { // Context that is set @ the top level
appName: cfg.get('APP_NAME'),
},
}),
})
]
})
export class AppModule {}
You can use it from any place Injectable
s are welcome:
import { Injectable } from '@nestjs/common';
import { RoarrLoggerService } from 'nestjs-logger-roarr;
@Injectable()
export class AppService {
public constructor(@Inject() private readonly logger: RoarrLoggerService) {}
}
You can use RoarrLoggerService
just like the build in Logger
via a property in Injectable
s:
import { Logger, Injectable } from '@nestjs/common';
@Injectable()
class MyService {
private readonly logger = new Logger(MyService.name);
doSomething() {
this.logger.log('Doing something...');
}
}
Note that
RoarrLoggerService
extendsConsoleLoggerService
(which extendsLoggerService
), so you can use it anywhere the other interfaces are expected/required.
In an example application, the usual startup logs look like this:
{"context":{"in":"NestFactory","logLevel":30,"pid":2225063},"message":"Starting Nest application...","sequence":"0","time":1681023672355,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"DBModule dependencies initialized","sequence":"1","time":1681023672368,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"OpenTelemetryModule dependencies initialized","sequence":"2","time":1681023672368,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"OpenTelemetryCoreModule dependencies initialized","sequence":"3","time":1681023672369,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"ConfigHostModule dependencies initialized","sequence":"4","time":1681023672376,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"ConfigModule dependencies initialized","sequence":"5","time":1681023672376,"version":"2.0.0"}
{"context":{"in":"InstanceLoader","logLevel":30,"pid":2225063},"message":"AppModule dependencies initialized","sequence":"6","time":1681023672376,"version":"2.0.0"}
{"context":{"in":"RoutesResolver","logLevel":30,"pid":2225063},"message":"AppController {/}:","sequence":"7","time":1681023672389,"version":"2.0.0"}
{"context":{"in":"RouterExplorer","logLevel":30,"pid":2225063},"message":"Mapped {/, GET} route","sequence":"8","time":1681023672390,"version":"2.0.0"}
{"context":{"in":"NestApplication","logLevel":30,"pid":2225063},"message":"Nest application successfully started","sequence":"9","time":1681023672392,"version":"2.0.0"}
{"context":{"in":"AppService","logLevel":30,"pid":2225063},"message":"running getHello!!!","sequence":"10","time":1681023676282,"version":"2.0.0"}
Contributions are always welcome!
git checkout -b feat/my-branch
)Distributed under the MIT License. See LICENSE
for more information.
FAQs
Roarr integration for NestJS Logging (compatible with ConsoleLogger and LoggerService)
We found that nestjs-logger-roarr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
The Rust Security Response WG is warning of phishing emails from rustfoundation.dev targeting crates.io users.
Product
Socket now lets you customize pull request alert headers, helping security teams share clear guidance right in PRs to speed reviews and reduce back-and-forth.
Product
Socket's Rust support is moving to Beta: all users can scan Cargo projects and generate SBOMs, including Cargo.toml-only crates, with Rust-aware supply chain checks.