Skip to content

Commit 9737cbc

Browse files
authored
Merge pull request #6 from bufferapp/task/add-context
Add context if needed
2 parents a8276c0 + d15c0e8 commit 9737cbc

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

bufflog.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,29 +36,30 @@ export class BuffLog {
3636
});
3737
}
3838

39-
debug(message: string) {
40-
this.pinoLogger.debug(message);
39+
debug(message: string, context?: object) {
40+
this.pinoLogger.debug({context: context}, message);
4141
}
4242

43-
info(message: string) {
43+
info(message: string, context?: object) {
4444
this.pinoLogger.info(message);
4545
}
4646

47-
notice(message: string) {
48-
this.pinoLogger.notice(message);
47+
notice(message: string, context?: object) {
48+
this.pinoLogger.notice({context: context}, message);
4949
}
5050

51-
warning(message: string) {
52-
this.pinoLogger.warn(message);
51+
warning(message: string, context?: object) {
52+
this.pinoLogger.warn({context: context}, message);
5353
}
5454

55-
error(message: string) {
56-
this.pinoLogger.error(message);
55+
error(message: string, context?: object) {
56+
this.pinoLogger.error({context: context}, message);
57+
5758
}
5859

5960
// for consistency with php-bufflog, critical == fatal
60-
critical(message: string) {
61-
this.pinoLogger.fatal(message);
61+
critical(message: string, context?: object) {
62+
this.pinoLogger.fatal({context: context}, message);
6263
}
6364

6465
}

index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@ tracer.init({
1010
let logger = new BuffLog();
1111

1212
logger.info('hello info');
13-
logger.debug('hello debug');
1413
logger.notice('hello notice');
14+
logger.notice('hello notice with context', {"test":"toto"});
1515
logger.warning('hello warning');
1616
logger.error('hello error');
1717
logger.critical('hello critical');
18+
logger.critical('hello critical', {"some":"stuff"});
1819

1920
const app = express();
2021

0 commit comments

Comments
 (0)