Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
json-logger-service
Advanced tools
Provides a Json Nest LoggerService.
$ npm i json-logger-service --save
Nest.js version | json-logger-service compatible version |
---|---|
8.x.x | 8.x.x |
7.x.x | 7.x.x |
Configuring Nest to use a custom Json LoggerService.
import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
import {JsonLoggerService} from 'json-logger-service';
const bootstrap = async () => {
const app = await NestFactory.create(AppModule);
app.useLogger(new JsonLoggerService('NestServer'));
await app.listen(3000);
};
bootstrap();
import {JsonLogger, LoggerFactory} from 'json-logger-service';
export class HelloWorldService {
private readonly logger: JsonLogger = LoggerFactory.createLogger(HelloWorldService.name);
public getHello(): string {
this.logger.info('Hello World!');
this.logger.info({myContextProperty: 'My property\'s value', anotherProperty: 'Another value'}, 'Hello World with some context!');
return 'Hello World!';
}
}
Configuring Nest to use a simple Express request logger.
import {NestFactory} from '@nestjs/core';
import {AppModule} from './app.module';
import {RequestLogger} from 'json-logger-service';
const bootstrap = async () => {
const app = await NestFactory.create(AppModule);
...
app.use(RequestLogger.buildExpressRequestLogger());
...
await app.listen(3000);
};
bootstrap();
Considering a request to /mypath
, the logger output should be something like:
{"name":"RequestLogger","hostname":"HOSTNAME","pid":1,"level":30,"msg":"Before request GET '/mypath'","time":"2019-12-09T12:10:23.020Z","v":0}
{"name":"RequestLogger","hostname":"HOSTNAME","pid":1,"level":30,"msg":"After request GET '/mypath'","time":"2019-12-09T12:10:23.021Z","v":0}
An array of base paths you do NOT want to log at all can be passed too.
app.use(RequestLogger.buildExpressRequestLogger({ doNotLogPaths: ['/health-server-status'] } as RequestLoggerOptions));
Then considering a request to /health-server-status
, the logger will not log anything.
An array of base paths you want to log without the full path (for security or GDPR reasons maybe) can be passed in the RequestLogger constructor.
app.use(RequestLogger.buildExpressRequestLogger({ logOnlyBasePaths: ['/my-path'] } as RequestLoggerOptions));
Then, considering a request to /my-path/customerEmail@gmail.com
, the logger output should be something like:
{"name":"RequestLogger","hostname":"HOSTNAME","pid":1,"level":30,"msg":"Before request GET '/my-path'","time":"2019-12-09T12:10:23.020Z","v":0}
{"name":"RequestLogger","hostname":"HOSTNAME","pid":1,"level":30,"msg":"After request GET '/my-path'","time":"2019-12-09T12:10:23.021Z","v":0}
General Logging level can be changed centrally using environment property LOGGER_LEVEL. Possible values:
FAQs
Nest Json LoggerService implementation.
The npm package json-logger-service receives a total of 809 weekly downloads. As such, json-logger-service popularity was classified as not popular.
We found that json-logger-service demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
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.