-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Port hookshot logger * changelog * fix func name * Log line improvements * tidy up * fix mistaken typo
- Loading branch information
Showing
24 changed files
with
492 additions
and
260 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
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,2 @@ | ||
Port the Logger class from `matrix-hookshot` to this SDK, granting JSON logging support and less noisy logs. | ||
**Note**: This change is breaking. `Logging.get(...)` becomes `new Logger(...)` and `Logging.configure` becomes `Logger.configure`. |
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 |
---|---|---|
|
@@ -871,6 +871,13 @@ is-arrayish@^0.3.1: | |
resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.3.2.tgz#4574a2ae56f7ab206896fb431eaeed066fdf8f03" | ||
integrity sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ== | ||
|
||
is-core-module@^2.8.1: | ||
version "2.9.0" | ||
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.9.0.tgz#e1c34429cd51c6dd9e09e0799e396e27b19a9c69" | ||
integrity sha512-+5FPy5PnwmO3lvfMb0AsoPaBG+5KHUI0wYFXOtYPnVVVspTFUuMZNfNaNVRt3FZadstu2c8x23vykRW/NBoU6A== | ||
dependencies: | ||
has "^1.0.3" | ||
|
||
is-my-ip-valid@^1.0.0: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/is-my-ip-valid/-/is-my-ip-valid-1.0.1.tgz#f7220d1146257c98672e6fba097a9f3f2d348442" | ||
|
@@ -1281,6 +1288,16 @@ parseurl@~1.3.3: | |
resolved "https://registry.yarnpkg.com/parseurl/-/parseurl-1.3.3.tgz#9da19e7bee8d12dff0513ed5b76957793bc2e8d4" | ||
integrity sha512-CiyeOxFT/JZyN5m0z9PfXw4SCBJ6Sygz1Dpl0wqjlhDEGGBP1GnsUVEL0p63hoG1fcj3fHynXi9NYO4nWOL+qQ== | ||
|
||
path-is-absolute@^1.0.0: | ||
version "1.0.1" | ||
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" | ||
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= | ||
|
||
path-parse@^1.0.7: | ||
version "1.0.7" | ||
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735" | ||
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw== | ||
|
||
[email protected]: | ||
version "0.1.7" | ||
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c" | ||
|
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,86 @@ | ||
import { Writable } from "stream"; | ||
import { Logger, GlobalLogger } from "../../src/index"; | ||
|
||
const tortureArgs: [unknown, ...unknown[]][] = [ | ||
["test-msg"], | ||
[Number.MAX_VALUE], | ||
[false], | ||
[Buffer.from('foo')], | ||
[new Error('Test')], | ||
[undefined], | ||
[null], | ||
[NaN], | ||
[[]], | ||
[() => { /*dummy*/}], | ||
["Foo", "test-msg"], | ||
["Foo", Number.MAX_VALUE], | ||
["Foo", false], | ||
["Foo", Buffer.from('foo')], | ||
["Foo", new Error('Test')], | ||
["Foo", undefined], | ||
["Foo", null], | ||
["Foo", NaN], | ||
["Foo", []], | ||
["Foo", () => { /*dummy*/}], | ||
] | ||
|
||
const MODULE_NAME = 'LogTesting'; | ||
|
||
describe('Logger', () => { | ||
describe('text logger torture test', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let data: any; | ||
const global = new GlobalLogger(); | ||
global.configureLogging({ | ||
json: false, | ||
console: 'debug', | ||
}, new Writable({ | ||
write(chunk, _encoding, callback) { | ||
data = chunk.toString(); | ||
callback(); | ||
}, | ||
})); | ||
|
||
const log = new Logger(MODULE_NAME, {}, global); | ||
for (const args of tortureArgs) { | ||
it(`handles logging '${args.map(t => typeof t).join(', ')}'`, () => { | ||
for (const level of ['debug', 'info', 'warn', 'error']) { | ||
log[level as 'debug'|'info'|'warn'|'error'](args[0], ...args.slice(1)); | ||
expect(data).toBeDefined(); | ||
expect(data).toContain(level.toUpperCase()); | ||
expect(data).toContain(MODULE_NAME); | ||
} | ||
}) | ||
} | ||
}); | ||
describe('JSON logger torture test', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let data: any; | ||
const global = new GlobalLogger(); | ||
global.configureLogging({ | ||
json: true, | ||
console: 'debug', | ||
}, new Writable({ | ||
write(chunk, _encoding, callback) { | ||
data = JSON.parse(chunk.toString()); | ||
callback(); | ||
}, | ||
})); | ||
|
||
const log = new Logger(MODULE_NAME, {}, global); | ||
for (const args of tortureArgs) { | ||
it(`handles logging '${args.map(t => typeof t).join(', ')}'`, () => { | ||
for (const level of ['debug', 'info', 'warn', 'error']) { | ||
log[level as 'debug'|'info'|'warn'|'error'](args[0], ...args.slice(1)); | ||
expect(data.level).toEqual(level.toUpperCase()); | ||
expect(data.module).toEqual(MODULE_NAME); | ||
expect(data.message).toBeDefined(); | ||
expect(data.timestamp).toBeDefined(); | ||
if (args.length > 1) { | ||
expect(data.args).toHaveSize(args.length-1); | ||
} | ||
} | ||
}) | ||
} | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.