@neoskop/nestjs-logger
Advanced tools
Comparing version 0.1.0 to 0.2.0
@@ -6,3 +6,2 @@ import { LoggerModuleOptions } from './logger-module-options.interface'; | ||
private static readonly logger; | ||
private static customFormat; | ||
error(message: any, trace?: any): void; | ||
@@ -9,0 +8,0 @@ warn(message: any, context?: any): void; |
@@ -12,3 +12,2 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { | ||
import { Injectable } from '@nestjs/common'; | ||
import chalk from 'chalk'; | ||
import * as winston from 'winston'; | ||
@@ -19,25 +18,2 @@ let LoggerService = LoggerService_1 = class LoggerService { | ||
} | ||
static customFormat(info) { | ||
let level = info.level.toUpperCase(); | ||
let padding = 0; | ||
switch (info.level) { | ||
case 'debug': | ||
level = chalk.blueBright(level); | ||
break; | ||
case 'info': | ||
level = chalk.whiteBright(level); | ||
padding = 1; | ||
break; | ||
case 'warn': | ||
level = chalk.yellowBright(level); | ||
padding = 1; | ||
break; | ||
case 'error': | ||
level = chalk.redBright(level); | ||
break; | ||
} | ||
const formattedLevel = `[${chalk.bold(level)}]${' '.repeat(padding)}`; | ||
info.message = `${chalk.gray(info.timestamp)} ${formattedLevel} ${info.message}`; | ||
return info; | ||
} | ||
error(message, trace) { | ||
@@ -66,5 +42,5 @@ LoggerService_1.logger.error(`${message} ${trace ? trace : ''}`); | ||
LoggerService.logger = winston.createLogger({ | ||
format: winston.format.combine(winston.format.timestamp({ | ||
format: winston.format.combine(winston.format.colorize({ all: true }), winston.format.timestamp({ | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
}), winston.format(LoggerService_1.customFormat)()), | ||
}), winston.format.printf((info) => `[${info.timestamp}] ${info.level.toUpperCase()}: ${info.message}`)), | ||
transports: [ | ||
@@ -71,0 +47,0 @@ new winston.transports.Console({ |
{ | ||
"name": "@neoskop/nestjs-logger", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"type": "module", | ||
@@ -26,3 +26,2 @@ "keywords": [ | ||
"@nestjs/core": "8.4.7", | ||
"chalk": "5.0.1", | ||
"reflect-metadata": "0.1.13" | ||
@@ -36,3 +35,2 @@ }, | ||
"@types/node": "18.0.3", | ||
"@types/triple-beam": "1.3.2", | ||
"jest": "28.1.2", | ||
@@ -48,7 +46,4 @@ "nodemon": "2.0.19", | ||
"dependencies": { | ||
"chalk": "5.0.1", | ||
"logform": "2.4.2", | ||
"triple-beam": "1.3.0", | ||
"winston": "3.8.1" | ||
} | ||
} |
@@ -18,2 +18,8 @@ import { Test, TestingModule } from '@nestjs/testing'; | ||
}); | ||
it('should write to stdout', () => { | ||
jest.spyOn((console as any)._stdout, 'write'); | ||
service.info('foo'); | ||
expect((console as any)._stdout).toHaveBeenCalledWith('foo'); | ||
}); | ||
}); |
import { Injectable } from '@nestjs/common'; | ||
import chalk from 'chalk'; | ||
import { TransformableInfo } from 'logform'; | ||
import * as winston from 'winston'; | ||
@@ -13,6 +11,10 @@ import { LoggerModuleOptions } from './logger-module-options.interface'; | ||
format: winston.format.combine( | ||
winston.format.colorize({ all: true }), | ||
winston.format.timestamp({ | ||
format: 'YYYY-MM-DD HH:mm:ss', | ||
}), | ||
winston.format(LoggerService.customFormat)(), | ||
winston.format.printf( | ||
(info) => | ||
`[${info.timestamp}] ${info.level.toUpperCase()}: ${info.message}`, | ||
), | ||
), | ||
@@ -27,31 +29,2 @@ transports: [ | ||
private static customFormat(info: TransformableInfo) { | ||
let level = info.level.toUpperCase(); | ||
let padding = 0; | ||
switch (info.level) { | ||
case 'debug': | ||
level = chalk.blueBright(level); | ||
break; | ||
case 'info': | ||
level = chalk.whiteBright(level); | ||
padding = 1; | ||
break; | ||
case 'warn': | ||
level = chalk.yellowBright(level); | ||
padding = 1; | ||
break; | ||
case 'error': | ||
level = chalk.redBright(level); | ||
break; | ||
} | ||
const formattedLevel = `[${chalk.bold(level)}]${' '.repeat(padding)}`; | ||
info.message = `${chalk.gray(info.timestamp)} ${formattedLevel} ${ | ||
info.message | ||
}`; | ||
return info; | ||
} | ||
public error(message: any, trace?: any) { | ||
@@ -58,0 +31,0 @@ LoggerService.logger.error(`${message} ${trace ? trace : ''}`); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4
10
24156
462
+ Addedtriple-beam@1.4.1(transitive)
- Removedchalk@5.0.1
- Removedlogform@2.4.2
- Removedtriple-beam@1.3.0
- Removed@colors/colors@1.5.0(transitive)
- Removedchalk@5.0.1(transitive)
- Removedlogform@2.4.2(transitive)
- Removedtriple-beam@1.3.0(transitive)