Skip to content

Commit 77c9307

Browse files
authored
Merge pull request #7 from bufferapp/task/static-bufflog
Make `bufflog` importable
2 parents 9737cbc + c70f069 commit 77c9307

File tree

3 files changed

+29
-20
lines changed

3 files changed

+29
-20
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
# js-bufflog
22
logger for all javascript and typescript Buffer services
33

4+
# Usage
5+
```js
6+
import bufflog from "BuffLog";
7+
8+
bufflog.debug('hello critical', {"some":"stuff"});
9+
bufflog.info('hello info');
10+
bufflog.notice('hello notice with context', {"foo":"bar"});
11+
bufflog.error('hello error');
12+
bufflog.critical('hello critical');
13+
```
414

515
## Log verbosity levels
616

bufflog.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,14 @@ export class BuffLog {
5454

5555
error(message: string, context?: object) {
5656
this.pinoLogger.error({context: context}, message);
57-
5857
}
5958

6059
// for consistency with php-bufflog, critical == fatal
6160
critical(message: string, context?: object) {
6261
this.pinoLogger.fatal({context: context}, message);
6362
}
6463

65-
}
64+
}
65+
66+
var bufflog = new BuffLog();
67+
export default bufflog;

index.ts

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
import tracer from "dd-trace";
22
import express from 'express';
3-
import {BuffLog} from './bufflog';
3+
import bufflog from './bufflog';
44

55
tracer.init({
66
hostname: "dd-agent-hostname",
77
logInjection: false
88
});
99

10-
let logger = new BuffLog();
11-
12-
logger.info('hello info');
13-
logger.notice('hello notice');
14-
logger.notice('hello notice with context', {"test":"toto"});
15-
logger.warning('hello warning');
16-
logger.error('hello error');
17-
logger.critical('hello critical');
18-
logger.critical('hello critical', {"some":"stuff"});
10+
bufflog.info('hello info');
11+
bufflog.notice('hello notice');
12+
bufflog.notice('hello notice with context', {"test":"toto"});
13+
bufflog.warning('hello warning');
14+
bufflog.error('hello error');
15+
bufflog.critical('hello critical');
16+
bufflog.critical('hello critical', {"some":"stuff"});
1917

2018
const app = express();
2119

@@ -24,12 +22,11 @@ app.listen(4000, () => {
2422
});
2523

2624
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');
25+
bufflog.notice("Notice log via endpoint");
26+
bufflog.info('hello info');
27+
bufflog.debug('hello debug');
28+
bufflog.notice('hello notice');
29+
bufflog.warning('hello warning');
30+
bufflog.error('hello error');
31+
bufflog.critical('hello critical');
3532
});

0 commit comments

Comments
 (0)