Files
Pascal Perrenoud 14a9a6fa8d Disable colors
2024-06-03 16:41:18 +02:00

31 lines
824 B
TypeScript

import logger, {Level, type Writer, type WriterOptions} from 'log'
import {type FileSink, file} from 'bun'
import os from 'os'
export * as log from 'log'
export default logger
export class File implements Writer {
private readonly sink: FileSink;
readonly _options: WriterOptions;
public constructor(options: { minLevel: Level, path: string }) {
const {path, minLevel} = options
this._options = {minLevel, with_color: false}
this.sink = file(path).writer({ highWaterMark: 128 * 1024 })
}
public log(_level: Level, ...data: any[]) : void {
this.sink.write(data.join(" "))
this.sink.write(os.EOL)
}
public end() : number | Promise<number> {
return this.sink.end()
}
get options() : WriterOptions {
return this._options;
}
}