Skip to content

Commit d3fba11

Browse files
committed
Pass log arguments to augment processor function
1 parent 4dc45ea commit d3fba11

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

README.md

+9
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,15 @@ logger.info("How blissful it is, for one who has nothing");
206206
}
207207
```
208208

209+
The source function will be called with an object containing the following parameters
210+
211+
| name | type | notes |
212+
| ------- | ------------------ | ------------------------------------ |
213+
| level | Level | The log level |
214+
| message | string | The log message |
215+
| context | Object | The log context |
216+
| record | Object | The log record prior to augmentation |
217+
209218
### buffer
210219

211220
The buffer processor outputs the record as a buffer, optionally encoding it before doing so. For this processor to work, the record must previously have been converted to a string.

lib/processors/augment.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ module.exports = (params = {}) => {
44
};
55

66
function augmentFn(fn) {
7-
return ({ record }) => {
8-
return { ...record, ...fn() };
7+
return ({ level, message, ctx, record }) => {
8+
return { ...record, ...fn({ level, message, ctx, record }) };
99
};
1010
}
1111

test/processors/augment.test.js

+9
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ describe('augment', () => {
1212
eq(result, { a: 'b', x: 'y' });
1313
});
1414

15+
it('should pass the log arguments to the supplied function', () => {
16+
const source = ({ level, message, ctx, record }) => {
17+
return { level, message, ctx, record };
18+
};
19+
const fn = augment({ source });
20+
const result = fn({ level: 1, message: 2, ctx: 3, record: { a: 'b' } });
21+
eq(result, { a: 'b', level: 1, message: 2, ctx: 3, record: { a: 'b' } });
22+
});
23+
1524
it('should prefer source to record', () => {
1625
const source = () => {
1726
return { x: 'y' };

0 commit comments

Comments
 (0)