Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: logger json #12

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export class LoggerConfig implements ILoggerConfigFactory {
constructor() {
this._opts = {
hideTrace: false,
console: {
format: 'json',
},
meta: {
organization: 'NestJS ProLogger',
context: 'service',
Expand Down
12 changes: 6 additions & 6 deletions examples/replace-nest-logger-bootstrap/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { LogLevels } from '@wildegor/nestjs-prologger/modules/infrastructure/interfaces/logger.interfaces';
import { LoggerAdapter } from '@wildegor/nestjs-prologger/modules/modules/logger/logger.adapter';
import { NestExpressApplication } from '@nestjs/platform-express';
// import { LoggerAdapter } from '@wildegor/nestjs-prologger/modules/modules/logger/logger.adapter';
// import { NestExpressApplication } from '@nestjs/platform-express';
import { LoggerService } from '@wildegor/nestjs-prologger/modules/modules/logger/logger.service';
import { LoggerConstants } from '@wildegor/nestjs-prologger/modules/modules/logger/logger.constants';

async function bootstrap() {
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
const app = await NestFactory.create(AppModule, {
bufferLogs: true,
});

const logger = await app.resolve<LoggerAdapter>(LoggerAdapter);
const logger = await app.resolve<LoggerService>(LoggerConstants.logger);
logger.setLogLevels([
LogLevels.Debug,
LogLevels.Log,
Expand All @@ -20,8 +22,6 @@ async function bootstrap() {

app.useLogger(logger);

logger.error('Error message');

await app.listen(3001);
}
bootstrap();
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
if (opts?.format && 'json' === opts.format) {
return new winston.transports.Console({
format: winston.format.json({
deterministic: true,
// deterministic: true,
}),
});
}
Expand All @@ -22,21 +22,21 @@
winston.format.printf(log => {
const color = this._mapLogLevelColor(log.level as LogLevels);

const prefix = `${log.data?.label ? `[${log.data.label}]` : ''}`;

Check warning on line 25 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .label on an `any` value

Check warning on line 25 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .label on an `any` value

return `${this._colorize(color, `${prefix} - ${String(process.pid).padEnd(6)}`)} ${log.timestamp} ${

Check warning on line 27 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

No magic number: 6
log.data?.correlationId

Check warning on line 28 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .correlationId on an `any` value
? `(${this._colorize(LogColors.cyan, log.data.correlationId)})`

Check warning on line 29 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .correlationId on an `any` value
: ''
} ${this._colorize(color, log.level.toUpperCase())} ${
log.data?.source

Check warning on line 32 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .source on an `any` value
? `${this._colorize(LogColors.cyan, `[${log.data.source}]`)}`

Check warning on line 33 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .source on an `any` value
: ''
} ${this._colorize(
color,
`${log.message} - ${log.data.error ? log.data.error : ''}`,

Check warning on line 37 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .error on an `any` value

Check warning on line 37 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .error on an `any` value
)}${
typeof log.data?.durationMs !== 'undefined'

Check warning on line 39 in src/infrastructure/adapters/winston/transports/console/console.transport.ts

View workflow job for this annotation

GitHub Actions / Check

Unsafe member access .durationMs on an `any` value
? this._colorize(color, ` +${log.data.durationMs}ms`)
: ''
}${
Expand Down