Implement Writer as interface
This commit is contained in:
@@ -1,23 +1,28 @@
|
||||
import logger, {Level, Writer, type WriterOptions} from 'log'
|
||||
import {type FileSink} from 'bun'
|
||||
import logger, {Level, type Writer, type WriterOptions} from 'log'
|
||||
import {type FileSink, file} from 'bun'
|
||||
|
||||
export * as log from 'log'
|
||||
export default logger
|
||||
|
||||
export class File extends Writer {
|
||||
export class File implements Writer {
|
||||
private readonly sink: FileSink;
|
||||
readonly _options: WriterOptions;
|
||||
|
||||
public constructor(options: WriterOptions & { path: string }) {
|
||||
const {path, ...rest} = options
|
||||
super(rest)
|
||||
this.sink = Bun.file(path).writer()
|
||||
this._options = rest
|
||||
this.sink = file(path).writer()
|
||||
}
|
||||
|
||||
protected write(_level: Level, ...data: any[]) : void {
|
||||
public log(_level: Level, ...data: any[]) : void {
|
||||
this.sink.write(data.join(" "))
|
||||
}
|
||||
|
||||
public end() : number | Promise<number> {
|
||||
return this.sink.end()
|
||||
}
|
||||
|
||||
get options() : WriterOptions {
|
||||
return this._options;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user