Skip to content

Commit

Permalink
add ok level to logger
Browse files Browse the repository at this point in the history
  • Loading branch information
annemarie35 authored Sep 12, 2023
1 parent f3c8485 commit b78e110
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
4 changes: 4 additions & 0 deletions common/services/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ const info = ({ event, message, job, stack }, injectedLogger = console) => {
const warn = ({ event, message, job, stack }, injectedLogger = console) => {
injectedLogger.warn(serialize({ event, message, job, stack, level: 'warn' }));
};
const ok = ({ event, message, job, stack }, injectedLogger = console) => {
injectedLogger.ok(serialize({ event, message, job, stack, level: 'ok' }));
};

module.exports = {
error,
info,
warn,
ok,
};
32 changes: 32 additions & 0 deletions test/unit/common/services/logger_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,36 @@ describe('logger', function () {
});
});
});
describe('ok', function () {
describe('when an message is passed', function () {
it('should call injectedLogger ok', function () {
// given
const injectedLogger = { ok: sinon.stub() };

// when
logger.ok({ event: 'toto', message: 'titi', stack: 'stack' }, injectedLogger);

// then
expect(injectedLogger.ok.calledOnce).to.be.true;
expect(injectedLogger.ok.firstCall.args[0]).to.equal(
'{"event":"toto","message":"titi","stack":"stack","level":"ok"}',
);
});
});
describe('when an object is passed', function () {
it('should call injectedLogger warn with object in message', function () {
// given
const injectedLogger = { ok: sinon.stub() };

// when
logger.ok({ event: 'toto', message: { foo: 'bar' }, stack: 'stack' }, injectedLogger);

// then
expect(injectedLogger.ok.calledOnce).to.be.true;
expect(injectedLogger.ok.firstCall.args[0]).to.equal(
'{"event":"toto","message":"{\\"foo\\":\\"bar\\"}","stack":"stack","level":"ok"}',
);
});
});
});
});

0 comments on commit b78e110

Please sign in to comment.