init Counter writer

This commit is contained in:
2024-05-14 23:07:50 +02:00
commit 55cc0c9d77
4 changed files with 89 additions and 0 deletions
+6
View File
@@ -0,0 +1,6 @@
bun.lockb
package-lock.json
node_modules/
.idea/
._*
.DS_Store
+33
View File
@@ -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
}
}
+18
View File
@@ -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"
}
}
+32
View File
@@ -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",
]
}