import logger, {Level, type Writer, type WriterOptions} from 'log' import {File} from 'logger-file' export * as log from 'log' export default logger export class DailyFile implements Writer { readonly _options: WriterOptions; private writer: File private readonly folder: string private current_date: Date = new Date() public constructor(options: {minLevel: Level, folder: string}) { const {folder, minLevel} = options this._options = {minLevel, with_color: false} this.folder = folder this.writer = DailyFile.start(this._options.minLevel, this.folder, this.current_date) } private static start(minLevel: Level, folder: string, now: Date) : File { const date = now.toISOString().split('T')[0] const path = `${folder}/${date}.log` return new File({minLevel, path}) } public log(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.minLevel, this.folder, this.current_date) } return this.writer.log(level, ...data) } public end() : number | Promise { return this.writer.end() } public get options() : WriterOptions { return this._options } }