Implement Writer as interface
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import logger, {Level, Writer, type WriterOptions} from 'log'
|
||||
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 extends Writer {
|
||||
export class DailyFile implements Writer {
|
||||
readonly _options: WriterOptions;
|
||||
private writer: File
|
||||
private readonly folder: string
|
||||
private current_date: Date = new Date()
|
||||
@@ -12,7 +13,7 @@ export class DailyFile extends Writer {
|
||||
public constructor(options: WriterOptions & {folder: string}) {
|
||||
const {folder, ...rest} = options
|
||||
|
||||
super(rest)
|
||||
this._options = rest
|
||||
this.folder = folder
|
||||
|
||||
this.writer = DailyFile.start(this.options, this.folder, this.current_date)
|
||||
@@ -24,11 +25,11 @@ export class DailyFile extends Writer {
|
||||
return new File({...options, path})
|
||||
}
|
||||
|
||||
protected write(level: Level, ...data: any[]): void {
|
||||
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, this.folder, this.current_date)
|
||||
this.writer = DailyFile.start(this._options, this.folder, this.current_date)
|
||||
}
|
||||
|
||||
return this.writer.log(level, data)
|
||||
@@ -37,4 +38,8 @@ export class DailyFile extends Writer {
|
||||
public end() : number | Promise<number> {
|
||||
return this.writer.end()
|
||||
}
|
||||
|
||||
public get options() : WriterOptions {
|
||||
return this._options
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user