init Counter writer
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
bun.lockb
|
||||
package-lock.json
|
||||
node_modules/
|
||||
.idea/
|
||||
._*
|
||||
.DS_Store
|
||||
@@ -0,0 +1,33 @@
|
||||
import logger, {Writer, Level} from 'log'
|
||||
|
||||
export * as log from 'log'
|
||||
export default logger
|
||||
|
||||
export class Counter extends Writer {
|
||||
private readonly calls = {
|
||||
debug: 0,
|
||||
trace: 0,
|
||||
info: 0,
|
||||
warn: 0,
|
||||
error: 0,
|
||||
}
|
||||
|
||||
public constructor() {
|
||||
super({minLevel: Level.DEBUG, with_color: false});
|
||||
}
|
||||
|
||||
protected write(level: Level, ..._data: any[]): void {
|
||||
switch (level) {
|
||||
case Level.DEBUG: this.calls.debug++; break
|
||||
case Level.TRACE: this.calls.trace++; break
|
||||
case Level.INFO: this.calls.info++; break
|
||||
case Level.WARNING: this.calls.warn++; break
|
||||
case Level.ERROR: this.calls.error++; break
|
||||
default: throw new Error(`Unknown level: ${level}`)
|
||||
}
|
||||
}
|
||||
|
||||
public get count() {
|
||||
return this.calls
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "logger-counter",
|
||||
"description": "Dummy logger that only counts logs sent, used for testing purposes.",
|
||||
"version": "1.0.0",
|
||||
|
||||
"author": "Pascal Perrenoud <pascal@pband.ch>",
|
||||
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"files": ["index.ts"],
|
||||
|
||||
"dependencies": {
|
||||
"log": "git+git@git.pband.ch:typescript/log"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// Enable latest features
|
||||
"lib": ["ESNext","dom"],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"allowJs": true,
|
||||
"checkJs": true,
|
||||
|
||||
// Bundler mode
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
// Best practices
|
||||
"strict": true,
|
||||
"skipLibCheck": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
|
||||
// Some stricter flags (disabled by default)
|
||||
"noUnusedLocals": false,
|
||||
"noUnusedParameters": false,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"noPropertyAccessFromIndexSignature": false
|
||||
},
|
||||
|
||||
"include": [
|
||||
"index.ts",
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user