-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
137 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
import ansicolor from 'ansicolor'; | ||
import expect from 'expect'; | ||
|
||
import { messageColumnWidth } from './message-column-width'; | ||
import { nestologOptionsDefaults } from './nestolog-options.provider'; | ||
import { NestoLogger } from './nestologger.service'; | ||
|
||
describe('nestoLog', () => { | ||
it('configure messageColumnWidth temp', () => { | ||
const result = messageColumnWidth(nestologOptionsDefaults); | ||
expect(result).not.toBeUndefined(); | ||
it('messageColumnWidth', () => { | ||
const result = messageColumnWidth(nestologOptionsDefaults); | ||
expect(result).not.toBeUndefined(); | ||
}); | ||
|
||
it('custom locate', () => { | ||
let output = ''; | ||
const logger = new NestoLogger({ | ||
...nestologOptionsDefaults, | ||
customLocate: true, | ||
render: (input: string) => { | ||
output = ansicolor.strip(input); | ||
}, | ||
}); | ||
logger.log('Test message', 'Contex'); | ||
const lines = output.split('\n'); | ||
expect(lines).toHaveLength(2); | ||
expect(lines[0]!.indexOf('Test message')).toEqual(lines[1]?.indexOf('<anonymous>')); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,16 @@ | ||
import { Provider } from '@nestjs/common'; | ||
import ololog from 'ololog'; | ||
|
||
export const NESTOLOG_OPTIONS = Symbol('NESTOLOG_OPTIONS'); | ||
import { nestologOptionsDefaults } from './nestolog-options'; | ||
|
||
export const nestologOptionsDefaults = { | ||
time: true, | ||
locate: true, | ||
tag: true, | ||
contextLimit: 13, | ||
/** | ||
* Word wrap width for message. | ||
* If 0 (default) tries to auto detect. | ||
* If -1 disable | ||
*/ | ||
messageColumnWidth: 0, | ||
}; | ||
export const NESTOLOG_OPTIONS = Symbol('NESTOLOG_OPTIONS'); | ||
|
||
export const nestologOptionsProvider: Provider = { | ||
provide: NESTOLOG_OPTIONS, | ||
useValue: nestologOptionsDefaults, | ||
}; | ||
|
||
export type NestologOptions = Partial< | ||
typeof nestologOptionsDefaults & Parameters<typeof ololog.configure>[0] | ||
>; | ||
export type NestologOptions = typeof nestologOptionsDefaults & | ||
Parameters<typeof ololog.configure>[0]; | ||
|
||
export { nestologOptionsDefaults }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import ololog from 'ololog'; | ||
|
||
import { Entry } from './types'; | ||
|
||
export const nestologOptionsDefaults = { | ||
time: true, | ||
locate: true, | ||
tag: true, | ||
contextLimit: 13, | ||
/** | ||
* Word wrap width for message. | ||
* If 0 (default) tries to auto detect. | ||
* If -1 disable | ||
*/ | ||
messageColumnWidth: 0, | ||
/** | ||
* Alternative locate. Default ololog's locate add callee info to the last non-empty string | ||
* Custom locate add callee info on next new line. | ||
*/ | ||
customLocate: undefined as undefined | boolean | typeof customLocateDefault, | ||
}; | ||
|
||
export type NestologOptions = Partial< | ||
typeof nestologOptionsDefaults & Parameters<typeof ololog.configure>[0] | ||
>; | ||
|
||
export function customLocateDefault({ calleeShort, fileName, line }: Entry): string { | ||
let result = ''; | ||
if (calleeShort) { | ||
result += calleeShort; | ||
} | ||
if (fileName && line) { | ||
if (result.length > 0) { | ||
result += ' @ '; | ||
} | ||
result += fileName; | ||
result += ':'; | ||
result += line; | ||
} | ||
return result; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export type LocatePrint = (args: { | ||
calleeShort: string; | ||
fileName: string; | ||
line: string; | ||
}) => string; | ||
|
||
export interface Location { | ||
file: string; | ||
line?: number; | ||
column?: number; | ||
} | ||
|
||
export interface Entry extends Location { | ||
beforeParse: string; | ||
callee: string; | ||
index: boolean; | ||
native: boolean; | ||
|
||
calleeShort: string; | ||
fileRelative: string; | ||
fileShort: string; | ||
fileName: string; | ||
thirdParty: boolean; | ||
|
||
hide?: boolean; | ||
sourceLine?: string; | ||
sourceFile?: SourceFile; | ||
error?: Error; | ||
} | ||
|
||
export interface SourceFile { | ||
path: string; | ||
text: string; | ||
lines: string[]; | ||
error?: Error; | ||
} |