Skip to content

Commit

Permalink
fix: get complete origin args (#1130)
Browse files Browse the repository at this point in the history
  • Loading branch information
czy88840616 authored Jul 2, 2021
1 parent e728b0b commit d652016
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/logger/src/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ export class MidwayBaseLogger extends EmptyLogger implements IMidwayLogger {
}

log(level, ...args) {
const originArgs = args;
const originArgs = [...args];
let meta, msg;
if (args.length > 1 && isPlainObject(args[args.length - 1])) {
meta = args.pop();
Expand Down
27 changes: 24 additions & 3 deletions packages/logger/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ describe('/test/index.test.ts', () => {
it('should test logger output format', function () {
const logger = createConsoleLogger(
'globalOutputConsoleLogger'
) as IMidwayLogger;
) as MidwayBaseLogger;

const fn = jest.spyOn(logger, 'write');

logger.info('test', 'test1', 'test2', 'test3');
logger.verbose('test', 'test1', 'test2', 'test3');
expect(fn.mock.calls[0][0].message).toEqual('test test1 test2 test3');

logger.info('test', 123, 'test2', 'test3');
logger.silly('test', 123, 'test2', 'test3');
expect(fn.mock.calls[1][0].message).toEqual('test 123 test2 test3');

logger.info('test', 123, [3,2,1], 'test3', new Error('abc'));
Expand Down Expand Up @@ -1125,4 +1125,25 @@ describe('/test/index.test.ts', () => {
process.env.MIDWAY_LOGGER_DISABLE_COLORS = '';
expect(fn.mock.calls[0][0]).not.toContain('\x1B');
});

it('should check info content', function () {
const fn = jest.fn();
const logger = createConsoleLogger(
'globalOutputConsoleLogger',
{
printFormat: fn,
}
) as ILogger;

logger.info('test', 'test1', 'test2', 'test3');
expect(fn.mock.calls[0][0].originArgs).toEqual(['test', 'test1', 'test2', 'test3']);

const err = new Error('abc');
logger.info(err);
expect(fn.mock.calls[1][0].originError).toEqual(err);

const err2 = new Error('abc2');
logger.info('abc', err2);
expect(fn.mock.calls[2][0].originError).toEqual(err2);
});
});

0 comments on commit d652016

Please sign in to comment.