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

style: error & trace print in same line #452

Merged
merged 7 commits into from
Apr 3, 2021
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
2 changes: 1 addition & 1 deletion packages/core/src/__tests__/log4js.module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('@nestx-log4js module', () => {
logger.log('test logger logging powered by log4js');
logger.warn('test logger logging powered by log4js');
logger.error('test logger logging powered by log4js');
logger.error('test logger logging powered by log4js', 'error log with trace');
logger.error('test logger logging powered by log4js', '& error log with trace in same line');

const log4jsModule = module.get(Log4jsModule);
expect(log4jsModule).toBeInstanceOf(Log4jsModule);
Expand Down
13 changes: 1 addition & 12 deletions packages/core/src/log4js.classes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ export class Log4jsLogger implements LoggerService {

error(message: any, trace?: string, context?: string) {
this.updateContext(context);
this.logger.error(message);
this.printStackTrace(trace);
this.logger.error(message, trace);
}

static getTimestamp() {
Expand All @@ -54,14 +53,4 @@ export class Log4jsLogger implements LoggerService {
getTimestamp() {
return Log4jsLogger.getTimestamp();
}

// nestjs logging use `process['stdout' | ...].write(message) to print log
// But log4js use async logging clustering to print log `clustering.send(loggingEvent);`
// to maintain the same behavior as nestjs logging, there should use error level
printStackTrace(stackTrace?: string) {
if (!stackTrace) {
return;
}
this.logger.error(stackTrace);
}
}