UNPKG

@logtape/file

Version:

File sink and rotating file sink for LogTape

60 lines (58 loc) 1.93 kB
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs'); const require_filesink_base = require('./filesink.base.cjs'); const node_fs = require_rolldown_runtime.__toESM(require("node:fs")); //#region filesink.node.ts /** * A Node.js-specific file sink driver. */ const nodeDriver = { openSync(path) { return node_fs.default.openSync(path, "a"); }, writeSync: node_fs.default.writeSync, flushSync: node_fs.default.fsyncSync, closeSync: node_fs.default.closeSync, statSync: node_fs.default.statSync, renameSync: node_fs.default.renameSync }; /** * Get a file sink. * * Note that this function is unavailable in the browser. * * @param path A path to the file to write to. * @param options The options for the sink. * @returns A sink that writes to the file. The sink is also a disposable * object that closes the file when disposed. */ function getFileSink(path, options = {}) { return require_filesink_base.getBaseFileSink(path, { ...options, ...nodeDriver }); } /** * Get a rotating file sink. * * This sink writes log records to a file, and rotates the file when it reaches * the `maxSize`. The rotated files are named with the original file name * followed by a dot and a number, starting from 1. The number is incremented * for each rotation, and the maximum number of files to keep is `maxFiles`. * * Note that this function is unavailable in the browser. * * @param path A path to the file to write to. * @param options The options for the sink and the file driver. * @returns A sink that writes to the file. The sink is also a disposable * object that closes the file when disposed. */ function getRotatingFileSink(path, options = {}) { return require_filesink_base.getBaseRotatingFileSink(path, { ...options, ...nodeDriver }); } //#endregion exports.getFileSink = getFileSink; exports.getRotatingFileSink = getRotatingFileSink; exports.nodeDriver = nodeDriver;