Gathering detailed insights and metrics for @betsys-nestjs/logger
Gathering detailed insights and metrics for @betsys-nestjs/logger
Gathering detailed insights and metrics for @betsys-nestjs/logger
Gathering detailed insights and metrics for @betsys-nestjs/logger
npm install @betsys-nestjs/logger
Typescript
Module System
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
8
This library is responsible for all logging.
It supports HTTP (expres
) and grpc
action logging and nodejs cluster logging (using process messaging).
In the background it uses Winston logger.
We are using npm levels from the winston itself (the lower the number higher the priority is):
error: 0,
warn: 1,
info: 2,
http: 3,
verbose: 4,
debug: 5,
silly: 6
This library requires next ENV variables:
Variable name | Description |
---|---|
CONFIG_LOG_LEVEL | Logger levels with lower priority will be skipped |
CONFIG_LOG_FORMAT=simple | Logger format logstash or simple (value logstash will format logs in kibana friendly way) |
Package | Version |
---|---|
on-headers | ^1.0.2 |
winston | ^3.3.3 |
@betsys-nestjs/config-utils | ^2.0.0 |
@hapi/joi | ^17.1.1 |
@nestjs/common | ^10.0.0 |
@nestjs/config | ^3.0.0 |
@nestjs/core | ^10.0.0 |
express | ^4.17.1 |
reflect-metadata | ^0.1.12 |
rxjs | ^7.1.0 |
To start using this library simply import LoggerModule
to your main application module.
1import {DATA_RETRIEVER, LoggerModule, DataRetrieverService, ContextTypeEnum} from '@betsys-nestjs/logger'; 2import {ExpressDefaultDataRetrieverService} from "./express-default-data-retriever.service"; 3 4@Module({ 5 imports: [ 6 LoggerModule.forRoot('express', { 7 provide: DATA_RETRIEVER, 8 useClass: ExpressDefaultDataRetrieverService, 9 }), 10 ] 11}) 12class AppModule { 13}
You can define whether you want to use express
or grpc
in forRoot
method. For all platforms there are default
data retrievers that are responsible for getting data to log from Request and Response objects based on platform. This
can be specified as second parameter of forRoot
method and you can add any providers you need to inject to module.
DATA_RETRIVER
is defined in provider array and creates a provider with this token. This should be a service that
inherits from exposed interface DataRetriever
.
For express
you can use:
{
provide: DATA_RETRIEVER,
useClass: ExpressDefaultDataRetrieverService,
}
For grpc
you can use:
{
provide: DATA_RETRIEVER,
useClass: GrpcDefaultDataRetrieverService,
}
Then inject Logger
provider wherever you want to log something.
1import {LoggerModule} from '@betsys/logger'; 2 3class AppService { 4 constructor(private readonly logger: Logger) { 5 } 6}
If you for some reason do not trust dependency resolver without providing annotation, you can use @InjectLogger()
to
provide explicit logger token.
1import {InjectLogger, Logger} from '@betsys/logger'; 2 3class AppService { 4 constructor(@InjectLogger() private readonly logger: Logger) { 5 } 6}
If you want to exclude any actions from HTTP logging you can mark them using @LoggerExclude()
.
1import {LoggerExclude} from '@betsys/logger'; 2 3@Controller() 4export class CatsController { 5 6 @LoggerExclude() 7 @Get() 8 public getHello(): string { 9 } 10}
Or you can mark whole controllers.
1import {LoggerExclude} from '@betsys/logger'; 2 3@LoggerExclude() 4@Controller() 5export class CatsController { 6}
No vulnerabilities found.
No security vulnerabilities found.