init DailyFile Logger
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
bun.lockb
|
||||
package-lock.json
|
||||
node_modules/
|
||||
.idea/
|
||||
._*
|
||||
.DS_Store
|
||||
@@ -0,0 +1,40 @@
|
||||
import logger, {Level, Writer, type WriterOptions} from 'log'
|
||||
import {File} from 'logger-file'
|
||||
|
||||
export * as log from 'log'
|
||||
export default logger
|
||||
|
||||
export class DailyFile extends Writer {
|
||||
private writer: File
|
||||
private readonly folder: string
|
||||
private current_date: Date = new Date()
|
||||
|
||||
public constructor(options: WriterOptions & {folder: string}) {
|
||||
const {folder, ...rest} = options
|
||||
|
||||
super(rest)
|
||||
this.folder = folder
|
||||
|
||||
this.writer = DailyFile.start(this.options, this.folder, this.current_date)
|
||||
}
|
||||
|
||||
private static start(options: WriterOptions, folder: string, now: Date) : File {
|
||||
const date = now.toISOString().split('T')[0]
|
||||
const path = `${folder}/${date}.log`
|
||||
return new File({...options, path})
|
||||
}
|
||||
|
||||
protected write(level: Level, ...data: any[]): void {
|
||||
if (new Date().getDay() !== this.current_date.getDay()) {
|
||||
this.current_date = new Date()
|
||||
this.writer.end()
|
||||
this.writer = DailyFile.start(this.options, this.folder, this.current_date)
|
||||
}
|
||||
|
||||
return this.writer.log(level, data)
|
||||
}
|
||||
|
||||
public end() : number | Promise<number> {
|
||||
return this.writer.end()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "logger-daily-file",
|
||||
"description": "Log writer to a different file every day, uses Bun !",
|
||||
"version": "1.0.0",
|
||||
|
||||
"author": "Pascal Perrenoud <pascal@pband.ch>",
|
||||
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"files": ["index.ts"],
|
||||
|
||||
"dependencies": {
|
||||
"logger-file": "git+git@git.pband.ch:typescript/logger-file"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bun": "^1.1.2"
|
||||
}
|
||||
}
|
||||
@@ -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