Skip to content

Commit 18d0f6d

Browse files
committed
Add context
1 parent 22a93db commit 18d0f6d

File tree

2 files changed

+27
-25
lines changed

2 files changed

+27
-25
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: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@ 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

21-
app.listen(4000, () => {
22-
console.log(`Server is listening on port 4000`);
23-
});
22+
// app.listen(4000, () => {
23+
// console.log(`Server is listening on port 4000`);
24+
// });
2425

25-
app.get('/', (req, res) => {
26-
var logger = new BuffLog();
27-
logger.notice("Notice log via endpoint");
28-
logger.info('hello info');
29-
logger.debug('hello debug');
30-
logger.notice('hello notice');
31-
logger.warning('hello warning');
32-
logger.error('hello error');
33-
logger.critical('hello critical');
34-
});
26+
// app.get('/', (req, res) => {
27+
// var logger = new BuffLog();
28+
// logger.notice("Notice log via endpoint");
29+
// logger.info('hello info');
30+
// logger.debug('hello debug');
31+
// logger.notice('hello notice');
32+
// logger.warning('hello warning');
33+
// logger.error('hello error');
34+
// logger.critical('hello critical');
35+
// });

0 commit comments

Comments
 (0)