From 42f60ac885c7e3f306c59ca7e5e344f1801e0309 Mon Sep 17 00:00:00 2001 From: Pascal Perrenoud Date: Tue, 14 May 2024 23:21:28 +0200 Subject: [PATCH] init File Logger --- .gitignore | 6 ++++++ index.ts | 23 +++++++++++++++++++++++ package.json | 18 ++++++++++++++++++ tsconfig.json | 32 ++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 .gitignore create mode 100644 index.ts create mode 100644 package.json create mode 100644 tsconfig.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fa5646b --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +bun.lockb +package-lock.json +node_modules/ +.idea/ +._* +.DS_Store diff --git a/index.ts b/index.ts new file mode 100644 index 0000000..c3fd1ef --- /dev/null +++ b/index.ts @@ -0,0 +1,23 @@ +import logger, {Level, Writer, type WriterOptions} from 'log' +import {type FileSink} from 'bun' + +export * as log from 'log' +export default logger + +export class File extends Writer { + private readonly sink: FileSink; + + public constructor(options: WriterOptions & { path: string }) { + const {path, ...rest} = options + super(rest) + this.sink = Bun.file(path).writer() + } + + protected write(_level: Level, ...data: any[]) : void { + this.sink.write(data.join(" ")) + } + + public end() : number | Promise { + return this.sink.end() + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..6cb5941 --- /dev/null +++ b/package.json @@ -0,0 +1,18 @@ +{ + "name": "logger-file", + "description": "Log writer to file", + "version": "1.0.0", + "author": "Pascal Perrenoud ", + "module": "index.ts", + "type": "module", + "files": ["index.ts"], + "dependencies": { + "log": "git+git@git.pband.ch:typescript/log" + }, + "peerDependencies": { + "typescript": "^5.0.0" + }, + "devDependencies": { + "@types/bun": "^1.1.2" + } +} diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..3d49bf0 --- /dev/null +++ b/tsconfig.json @@ -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", + ] +}