UNPKG

ts-logs

Version:

This package provide a skd for audit and manager logs in nodejs and express

26 lines 1.17 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WriteDefaultLocal = void 0; const promises_1 = require("node:fs/promises"); const node_path_1 = require("node:path"); const ensure_local_folder_util_1 = require("./ensure-local-folder.util"); const get_file_name_util_1 = require("./get-file-name.util"); const get_logs_dirname_util_1 = require("./get-logs-dirname.util"); /** * @description Save logs locally. * @param log instance of Log with hydrated state. * @param path dir name to save log file. * @returns Promise<void> */ const WriteDefaultLocal = async (log, path) => { const dir = (0, get_logs_dirname_util_1.GetLogsDirname)(log.name, path); const fileName = (0, get_file_name_util_1.default)(log.createdAt); const exists = await (0, ensure_local_folder_util_1.default)(dir); if (!exists) return; const filePath = (0, node_path_1.resolve)(dir, fileName); await (0, promises_1.appendFile)(filePath, JSON.stringify(log, null, 2) + '\n', 'utf8'); }; exports.WriteDefaultLocal = WriteDefaultLocal; exports.default = exports.WriteDefaultLocal; //# sourceMappingURL=write-default-local.util.js.map