Skip to content

Commit

Permalink
feat: New option for customLocatePosition option - context
Browse files Browse the repository at this point in the history
  • Loading branch information
unlight committed Feb 19, 2021
1 parent 1266949 commit 81c54b7
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ customLocate: undefined as undefined | boolean | typeof customLocateDefault,
* Place of callee info.
* 'bottom' - next on new line (default)
* 'column' - between tag and message columnized
* 'context' - in context column if context is empty
*/
customLocatePosition: 'bottom' as 'bottom' | 'column',
customLocatePosition: 'bottom' as 'bottom' | 'column' | 'context',
/**
* Limit callee info length in case of customLocatePosition = 'column'
*/
Expand Down
11 changes: 11 additions & 0 deletions src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,14 @@ it('custom locate column', () => {
expect(lines).toHaveLength(1);
expect(output).toContain('Context index.spec.ts');
});

it('custom locate context', () => {
let output = createOutput({
customLocate: true,
customLocatePosition: 'context',
context: '',
contextLimit: 80,
});
output = output.replace(/\s+/g, ' ');
expect(output).toContain('INFO createOutput @ index.spec.ts');
});
3 changes: 2 additions & 1 deletion src/nestolog-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ export const nestologOptionsDefaults = {
* Place of callee info.
* 'bottom' - next on new line (default)
* 'column' - between tag and message columnized
* 'context' - in context column if context is empty
*/
customLocatePosition: 'bottom' as 'bottom' | 'column',
customLocatePosition: 'bottom' as 'bottom' | 'column' | 'context',
/**
* Limit callee info length in case of customLocatePosition = 'column'
*/
Expand Down
6 changes: 6 additions & 0 deletions src/nestologger.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,12 @@ export class NestoLogger implements LoggerService {
calleeInfo = calleeInfo.padEnd(customLocateColumnLimit);
calleeInfo = stringify.limit(calleeInfo, customLocateColumnLimit);
lines = bullet(ansicolor.darkGray(calleeInfo) + ' ', lines);
} else if (customLocatePosition === 'context' && !context) {
calleeInfo = customLocate(where, {
...this.options,
customLocateColumnLimit: contextLimit,
});
context = calleeInfo;
} else {
lines.push(ansicolor.darkGray(calleeInfo));
}
Expand Down

0 comments on commit 81c54b7

Please sign in to comment.