-
-
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.
Merge pull request #65 from trojs/feature/update-20240725
Update linting
- Loading branch information
Showing
23 changed files
with
905 additions
and
1,371 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
Large diffs are not rendered by default.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,59 +1,61 @@ | ||
import test from 'node:test' | ||
import assert from 'node:assert' | ||
import makeLogger from '../logger.js' | ||
import test from 'node:test'; | ||
import assert from 'node:assert'; | ||
import makeLogger from '../logger.js'; | ||
|
||
test('Test the make loggers', async (t) => { | ||
await t.test('It should make the loggers', () => { | ||
const logger = makeLogger({ | ||
loggers: [{ | ||
type: 'console' | ||
}] | ||
}) | ||
await t.test('It should make the loggers', () => { | ||
const logger = makeLogger({ | ||
loggers: [ | ||
{ | ||
type: 'console', | ||
}, | ||
], | ||
}); | ||
|
||
assert.strictEqual(logger.level, 'info') | ||
assert.deepEqual(logger.levels, { | ||
fatal: 0, | ||
error: 1, | ||
warn: 2, | ||
info: 3, | ||
debug: 4, | ||
trace: 5 | ||
}) | ||
assert.strictEqual(logger.silent, undefined) | ||
assert.strictEqual(logger.writable, true) | ||
assert.strictEqual(logger.readable, true) | ||
assert.strictEqual(logger.allowHalfOpen, true) | ||
assert.deepEqual(logger.defaultMeta, {}) | ||
assert.strictEqual(logger.exitOnError, true) | ||
assert.deepEqual(logger.format, { | ||
options: {} | ||
}) | ||
assert.strictEqual(logger.filename, undefined) | ||
assert.strictEqual(logger.options, undefined) | ||
}) | ||
assert.strictEqual(logger.level, 'info'); | ||
assert.deepEqual(logger.levels, { | ||
fatal: 0, | ||
error: 1, | ||
warn: 2, | ||
info: 3, | ||
debug: 4, | ||
trace: 5, | ||
}); | ||
assert.strictEqual(logger.silent, undefined); | ||
assert.strictEqual(logger.writable, true); | ||
assert.strictEqual(logger.readable, true); | ||
assert.strictEqual(logger.allowHalfOpen, true); | ||
assert.deepEqual(logger.defaultMeta, {}); | ||
assert.strictEqual(logger.exitOnError, true); | ||
assert.deepEqual(logger.format, { | ||
options: {}, | ||
}); | ||
assert.strictEqual(logger.filename, undefined); | ||
assert.strictEqual(logger.options, undefined); | ||
}); | ||
|
||
await t.test('It should work without loggers', () => { | ||
const logger = makeLogger({}) | ||
await t.test('It should work without loggers', () => { | ||
const logger = makeLogger({}); | ||
|
||
assert.strictEqual(logger.level, 'info') | ||
assert.deepEqual(logger.levels, { | ||
fatal: 0, | ||
error: 1, | ||
warn: 2, | ||
info: 3, | ||
debug: 4, | ||
trace: 5 | ||
}) | ||
assert.strictEqual(logger.silent, undefined) | ||
assert.strictEqual(logger.writable, true) | ||
assert.strictEqual(logger.readable, true) | ||
assert.strictEqual(logger.allowHalfOpen, true) | ||
assert.deepEqual(logger.defaultMeta, {}) | ||
assert.strictEqual(logger.exitOnError, true) | ||
assert.deepEqual(logger.format, { | ||
options: {} | ||
}) | ||
assert.strictEqual(logger.filename, undefined) | ||
assert.strictEqual(logger.options, undefined) | ||
}) | ||
}) | ||
assert.strictEqual(logger.level, 'info'); | ||
assert.deepEqual(logger.levels, { | ||
fatal: 0, | ||
error: 1, | ||
warn: 2, | ||
info: 3, | ||
debug: 4, | ||
trace: 5, | ||
}); | ||
assert.strictEqual(logger.silent, undefined); | ||
assert.strictEqual(logger.writable, true); | ||
assert.strictEqual(logger.readable, true); | ||
assert.strictEqual(logger.allowHalfOpen, true); | ||
assert.deepEqual(logger.defaultMeta, {}); | ||
assert.strictEqual(logger.exitOnError, true); | ||
assert.deepEqual(logger.format, { | ||
options: {}, | ||
}); | ||
assert.strictEqual(logger.filename, undefined); | ||
assert.strictEqual(logger.options, undefined); | ||
}); | ||
}); |
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,33 +1,33 @@ | ||
import test from 'node:test' | ||
import assert from 'node:assert' | ||
import stackdriver from '../stackdriver.js' | ||
import test from 'node:test'; | ||
import assert from 'node:assert'; | ||
import stackdriver from '../stackdriver.js'; | ||
|
||
test('Test the stackdriver helper', async (t) => { | ||
await t.test('It should generate the meta data object', () => { | ||
const meta = stackdriver({ level: 'error', defaultLevel: 'info' }) | ||
const result = meta({ | ||
message: 'test' | ||
}) | ||
await t.test('It should generate the meta data object', () => { | ||
const meta = stackdriver({ level: 'error', defaultLevel: 'info' }); | ||
const result = meta({ | ||
message: 'test', | ||
}); | ||
|
||
assert.strictEqual(result.level, 50) | ||
assert.strictEqual(result.severity, 'ERROR') | ||
assert.strictEqual(result.message, 'test') | ||
assert.strictEqual(result.time.constructor.name, 'Number') | ||
assert.strictEqual(result.pid.constructor.name, 'Number') | ||
assert.strictEqual(result.hostname.constructor.name, 'String') | ||
}) | ||
assert.strictEqual(result.level, 50); | ||
assert.strictEqual(result.severity, 'ERROR'); | ||
assert.strictEqual(result.message, 'test'); | ||
assert.strictEqual(result.time.constructor.name, 'Number'); | ||
assert.strictEqual(result.pid.constructor.name, 'Number'); | ||
assert.strictEqual(result.hostname.constructor.name, 'String'); | ||
}); | ||
|
||
await t.test('It should generate the meta data object', () => { | ||
const meta = stackdriver({ level: 'something', defaultLevel: 'info' }) | ||
const result = meta({ | ||
message: 'test2' | ||
}) | ||
await t.test('It should generate the meta data object', () => { | ||
const meta = stackdriver({ level: 'something', defaultLevel: 'info' }); | ||
const result = meta({ | ||
message: 'test2', | ||
}); | ||
|
||
assert.strictEqual(result.level, 30) | ||
assert.strictEqual(result.severity, 'INFO') | ||
assert.strictEqual(result.message, 'test2') | ||
assert.strictEqual(result.time.constructor.name, 'Number') | ||
assert.strictEqual(result.pid.constructor.name, 'Number') | ||
assert.strictEqual(result.hostname.constructor.name, 'String') | ||
}) | ||
}) | ||
assert.strictEqual(result.level, 30); | ||
assert.strictEqual(result.severity, 'INFO'); | ||
assert.strictEqual(result.message, 'test2'); | ||
assert.strictEqual(result.time.constructor.name, 'Number'); | ||
assert.strictEqual(result.pid.constructor.name, 'Number'); | ||
assert.strictEqual(result.hostname.constructor.name, 'String'); | ||
}); | ||
}); |
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,30 +1,32 @@ | ||
import os from 'node:os' | ||
import os from 'node:os'; | ||
|
||
const levelToSeverity = { | ||
trace: 'DEBUG', | ||
debug: 'DEBUG', | ||
info: 'INFO', | ||
warn: 'WARNING', | ||
error: 'ERROR', | ||
fatal: 'CRITICAL' | ||
} | ||
trace: 'DEBUG', | ||
debug: 'DEBUG', | ||
info: 'INFO', | ||
warn: 'WARNING', | ||
error: 'ERROR', | ||
fatal: 'CRITICAL', | ||
}; | ||
|
||
const levels = { | ||
trace: 10, | ||
debug: 20, | ||
info: 30, | ||
warn: 40, | ||
error: 50, | ||
fatal: 60 | ||
} | ||
trace: 10, | ||
debug: 20, | ||
info: 30, | ||
warn: 40, | ||
error: 50, | ||
fatal: 60, | ||
}; | ||
|
||
const stackdriver = ({ level, defaultLevel }) => (info) => ({ | ||
...info, | ||
severity: levelToSeverity[level] || levelToSeverity[defaultLevel], | ||
level: levels[level] || levels[defaultLevel], | ||
time: Date.now(), | ||
pid: process.pid, | ||
hostname: os.hostname() | ||
}) | ||
const stackdriver = | ||
({ level, defaultLevel }) => | ||
(info) => ({ | ||
...info, | ||
severity: levelToSeverity[level] || levelToSeverity[defaultLevel], | ||
level: levels[level] || levels[defaultLevel], | ||
time: Date.now(), | ||
pid: process.pid, | ||
hostname: os.hostname(), | ||
}); | ||
|
||
export default stackdriver | ||
export default stackdriver; |
Oops, something went wrong.