UNPKG

@denodnt/logger

Version:

deno logger available for deno and NPM

60 lines (59 loc) 1.38 kB
import * as dntShim from "./_dnt.shims.js"; import { writeAll } from "./deps.js"; const { open, close, stat } = dntShim.Deno; /** * Writable class */ export default class Writable { /** * Writable constructor * @param path */ constructor(path) { Object.defineProperty(this, "file", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "path", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "currentSize", { enumerable: true, configurable: true, writable: true, value: 0 }); this.path = path; } /** * Setup writable file */ async setup() { this.file = await open(this.path, { create: true, append: true, write: true, }); this.currentSize = (await stat(this.path)).size; } /** * Write message to file * @param msg */ async write(msg) { await writeAll(this.file, msg); this.currentSize += msg.byteLength; } /** * Close file */ close() { // this.file.close(); close(this.file.rid); } }