Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@wiredcraft/nestjs-bunyan-logger
Advanced tools
A logger module for [Nestjs](https://github.com/nestjs/nest), built on top of [node-bunyan](https://github.com/trentm/node-bunyan).
A logger module for Nestjs, built on top of node-bunyan.
request-id
, timestamp
, status-code
, etc.yarn add @wiredcraft/nestjs-bunyan-logger
npm install @wiredcraft/nestjs-bunyan-logger --save
LoggerModule
in the root App module, this provides initialized bunyan logger instance that is available to other modules by injection.import { Module } from '@nestjs/common';
import { LoggerConfig, LoggerModule } from '@wiredcraft/nestjs-bunyan-logger';
import configuration from './src/configuration';
@Module({
imports: [
ConfigModule.forRoot({
load: [configuration],
}),
LoggerModule.forRootAsync({
imports: [ConfigModule],
useFactory: async (configService: ConfigService) => {
return configService.get<LoggerConfig>('logger', { infer: true });
},
inject: [ConfigService],
}),
],
})
export class AppModule {}
A sample configuration file is as below,
export default () => ({
logger: {
name: 'awesome-app',
streamType: 'FILE' | 'STDOUT',
path: './logs/app.log', // only available for `FILE` streamType
excludeReqPath: '/health', // the path that you want to skip logging
},
});
import { Injectable } from '@nestjs/common';
import { Logger, Bunyan } from '@wiredcraf/nestjs-bunyan-logger';
@Injectable()
export class CatService {
constructor(@Logger() private logger: Bunyan) {}
}
transformers
is a config option that could allow the user to specify a list of customized transform rules to apply to each log entry. The current library supports three types of transformers: constant
, clone
and map
.
constant
type allows the user to copy a object type constant directly to the log entry. An example is as follows:
const options: LoggerConfig = {
name: 'test-app',
streamType: 'STDOUT',
transformers: [{ constant: { customField: '123' } }],
};
logger.info({ originalField: 'abc' });
// The above will generate the following log entry:
// {
// originalField: 'abc',
// customField: '123'
// }
clone
type allows the user to copy value from one fieldname to the specified fieldname with the following rules:
An example is as follows:
const options: LoggerConfig = {
name: 'test-app',
streamType: 'STDOUT',
transformers: [{ clone: { originalField: 'newField' } }],
};
logger.info({ originalField: 'abc' });
// The above will generate the following log entry:
// {
// originalField: 'abc',
// newField: 'abc'
// }
An one embed level example is as follows:
const options: LoggerConfig = {
name: 'test-app',
streamType: 'STDOUT',
transformers: [{ clone: { originalField: 'newParent.newField' } }],
};
logger.info({ originalField: 'abc' });
// The above will generate the following log entry:
// {
// originalField: 'abc',
// newParent: {
// {
// newField: 'abc'
// }
// }
// }
map
type allows the user to apply a map value or a map function to the target field and replace the field value with the mapped value with the following rules:
An example of simple map value is as follows:
const options: LoggerConfig = {
name: 'test-app',
streamType: 'STDOUT',
transformers: [{ map: { originalField: 'new-value' } }],
};
logger.info({ originalField: 'abc' });
// The above will generate the following log entry:
// {
// originalField: 'new-value',
// }
An example of map function is as follows:
const options: LoggerConfig = {
name: 'test-app',
streamType: 'STDOUT',
transformers: [
{ map: { originalField: (oldValue) => oldValue + 'transformed' } },
],
};
logger.info({ originalField: 'abc' });
// The above will generate the following log entry:
// {
// originalField: 'abctransformed',
// }
An one embed level example is as follows:
const options: LoggerConfig = {
name: 'test-app',
streamType: 'STDOUT',
transformers: [
{ map: { ['originalParentField.originalField']: 'new-value' } },
],
};
logger.info({
originalParentField: {
originalField: 'abc',
},
});
// The above will generate the following log entry:
// {
// originalParentField: {
// originalField: 'new-value',
// },
// }
Multiple transformers are applied in the order as they are specified in the transformers
option. An example is as follows:
const transformers = [
{
constant: { customField: 'custom-value' },
},
{
clone: { originalField: 'backupField' },
},
{
map: { originalField: (oldValue) => oldValue + 'transformed' },
},
];
const options: LoggerConfig = {
name: 'test-app',
streamType: 'STDOUT',
transformers,
};
logger.info({ originalField: 'original-value' });
// The above will generate the following log entry:
// {
// originalField: 'original-value-transformed',
// backupField: 'original-value',
// customField: 'custom-value'
// }
$ npm install
$ npm version major|minor|patch
$ npm publish
FAQs
A logger module for [Nestjs](https://github.com/nestjs/nest), built on top of [node-bunyan](https://github.com/trentm/node-bunyan).
We found that @wiredcraft/nestjs-bunyan-logger 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.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.