Skip to content

Commit

Permalink
Fix: config option name not printing as application; Minor grammar fi…
Browse files Browse the repository at this point in the history
…x for unsupported logger error (#130)

* Fix: config option name not printing as application; Minor grammar fix for unsupported logger error (#128)

* Chore: adds tests to application name configuration

---------

Co-authored-by: Dean Ayalon <deanayalon@me.com>
  • Loading branch information
pustovitDmytro and DeanAyalon committed Apr 5, 2024
1 parent 15a82eb commit 4e73cd1
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
9 changes: 5 additions & 4 deletions src/decorators/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ export default class FunctionDecorator extends BaseFunctionDecorator {
resultSanitizer,
errorSanitizer,
contextSanitizer,
timestamp
timestamp,
name
} = this.config;

const basicLogObject = {
application : name,
service : this.config.serviceName,
method : methodName,
application : this.name
method : methodName
};

const buildLogObject = (level, obj) => {
Expand All @@ -65,7 +66,7 @@ export default class FunctionDecorator extends BaseFunctionDecorator {

if (isFunction(logger)) return logger(lev, dat);
if (isFunction(logger[lev])) return logger[lev](dat);
throw new Error(`logger not supports ${lev} level`);
throw new Error(`logger does not support ${lev} level`); // Alternatively - logger level ${lev} not supported
};

const time = startBenchmark();
Expand Down
38 changes: 37 additions & 1 deletion tests/package/configurations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ test('Negative: broken logger', function () {

assert.throws(() => {
decorated(5, 9);
}, Error, 'logger not supports');
}, Error, 'logger does not support');
});

test('Positive: function logger', function () {
Expand All @@ -148,3 +148,39 @@ test('Positive: function logger', function () {
result : '14'
});
});

test('Positive: specify application name', function () {
const catched = [];
const decorator = new Decorator({
name : 'Atons Forts Bassent',
logger : (type, data) => catched.push({ type, data })
});
const decorated = decorator()(sum);
const res = decorated(5, 11);

assert.equal(res, 16);
assert.deepOwnInclude(catched[0].data, {
method : 'sum',
params : '[ 5, 11 ]',
result : '16',
application : 'Atons Forts Bassent'
});
});

test('Negative: dont specify application name', function () {
const catched = [];
const decorator = new Decorator({
logger : (type, data) => catched.push({ type, data })
});
const decorated = decorator()(sum);
const res = decorated(2, 1);

assert.equal(res, 3);
assert.deepOwnInclude(catched[0].data, {
method : 'sum',
params : '[ 2, 1 ]',
result : '3'
});
assert.notExists(catched[0].data.application);
});

0 comments on commit 4e73cd1

Please sign in to comment.