Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
nestjs-pino-stackdriver
Advanced tools
Configured to be stackdriver compliant.
import { Logger } from 'nestjs-pino-stackdriver';
// In your main JS
async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger: new Logger(),
});
await app.listen(3000);
}
bootstrap();
Configure it using pino options https://github.com/pinojs/pino/blob/master/docs/api.md
import { LoggerModule } from 'nestjs-pino-stackdriver';
@Module({
// You can leave config empty
imports: [LoggerModule.forRoot({ name: 'example' })],
controllers: [AppController],
providers: [AppService],
})
export class AppModule {
}
import { Controller, Get, Logger } from '@nestjs/common';
@Controller()
export class AppController {
constructor(
private readonly logger: Logger,
) {
this.logger.log('app controller booted');
}
@Get()
getHello(): string {
this.logger.log(headers);
return 'hello';
}
}
Add in your request a correlation id if none provided
import { CorrelationIdMiddleware } from 'nestjs-pino-stackdriver';
async function bootstrap() {
const logger = new Logger();
const app = await NestFactory.create(AppModule);
app.use(CorrelationIdMiddleware(logger));
await app.listen(3000);
}
bootstrap();
Add tracer info in your log
import { TracerMiddleware } from 'nestjs-pino-stackdriver';
async function bootstrap() {
const logger = new Logger();
const app = await NestFactory.create(AppModule);
app.use(TracerMiddleware(logger))
await app.listen(3000);
}
bootstrap();
import { Controller, Get, Headers, , Query } from '@nestjs/common';
@Controller()
export class AppController {
constructor(
private readonly appService: AppService,
) {}
@Get()
getHello(@Headers() headers, @Query('logger') logger): string {
// console.log(logger);
logger.log('request received', 'app.getHello', headers);
return this.appService.getHello();
}
}
Output in production
{"severity":"info","correlation_id":"4NTtNp4X","logging.googleapis.com/trace":"281fe620078d4562b311712cf42faefd","context":"app.getHello","message":"request received {\"host\":\"localhost:3000\",\"user-agent\":\"curl/7.64.1\",\"accept\":\"*/*\",\"x-correlation-id\":\"4NTtNp4X\"}","v":1}
Or locally
[2020-03-03 19:24:00.673 +0000] INFO : request received {"host":"localhost:3000","user-agent":"curl/7.64.1","accept":"*/*","x-correlation-id":"51eLtfXz"}
correlation_id: "51eLtfXz"
logging.googleapis.com/trace: "9b25e09ac8be4e0c93ba40304bf80fe8"
context: "app.getHello"
FAQs
NestJS Pino logger with Stackdriver support
The npm package nestjs-pino-stackdriver receives a total of 309 weekly downloads. As such, nestjs-pino-stackdriver popularity was classified as not popular.
We found that nestjs-pino-stackdriver demonstrated a not healthy version release cadence and project activity because the last version was released 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
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.