@vladmandic/pilogger
Advanced tools
Comparing version 0.4.9 to 0.5.1
@@ -1,2 +0,1 @@ | ||
/// <reference types="node" /> | ||
import * as fs from 'fs'; | ||
@@ -3,0 +2,0 @@ export type Ring = { |
@@ -33,8 +33,8 @@ "use strict"; | ||
// node_modules/dayjs/dayjs.min.js | ||
// node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js | ||
var require_dayjs_min = __commonJS({ | ||
"node_modules/dayjs/dayjs.min.js"(exports, module2) { | ||
"node_modules/.pnpm/dayjs@1.11.13/node_modules/dayjs/dayjs.min.js"(exports2, module2) { | ||
!function(t, e) { | ||
"object" == typeof exports && "undefined" != typeof module2 ? module2.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e(); | ||
}(exports, function() { | ||
"object" == typeof exports2 && "undefined" != typeof module2 ? module2.exports = e() : "function" == typeof define && define.amd ? define(e) : (t = "undefined" != typeof globalThis ? globalThis : t || self).dayjs = e(); | ||
}(exports2, function() { | ||
"use strict"; | ||
@@ -51,4 +51,3 @@ var t = 1e3, e = 6e4, n = 36e5, r = "millisecond", i = "second", s = "minute", u = "hour", a = "day", o = "week", c = "month", f = "quarter", h = "year", d = "date", l = "Invalid Date", $ = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[Tt\s]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/, y = /\[([^\]]+)]|Y{1,4}|M{1,4}|D{1,2}|d{1,4}|H{1,2}|h{1,2}|a|A|m{1,2}|s{1,2}|Z{1,2}|SSS/g, M = { name: "en", weekdays: "Sunday_Monday_Tuesday_Wednesday_Thursday_Friday_Saturday".split("_"), months: "January_February_March_April_May_June_July_August_September_October_November_December".split("_"), ordinal: function(t2) { | ||
}, m: function t2(e2, n2) { | ||
if (e2.date() < n2.date()) | ||
return -t2(n2, e2); | ||
if (e2.date() < n2.date()) return -t2(n2, e2); | ||
var r2 = 12 * (n2.year() - e2.year()) + (n2.month() - e2.month()), i2 = e2.clone().add(r2, c), s2 = n2 - i2 < 0, u2 = e2.clone().add(r2 + (s2 ? -1 : 1), c); | ||
@@ -68,4 +67,3 @@ return +(-(r2 + (n2 - i2) / (s2 ? i2 - u2 : u2 - i2)) || 0); | ||
var i2; | ||
if (!e2) | ||
return g; | ||
if (!e2) return g; | ||
if ("string" == typeof e2) { | ||
@@ -75,4 +73,3 @@ var s2 = e2.toLowerCase(); | ||
var u2 = e2.split("-"); | ||
if (!i2 && u2.length > 1) | ||
return t2(u2[0]); | ||
if (!i2 && u2.length > 1) return t2(u2[0]); | ||
} else { | ||
@@ -84,4 +81,3 @@ var a2 = e2.name; | ||
}, O = function(t2, e2) { | ||
if (S(t2)) | ||
return t2.clone(); | ||
if (S(t2)) return t2.clone(); | ||
var n2 = "object" == typeof e2 ? e2 : {}; | ||
@@ -101,8 +97,5 @@ return n2.date = t2, n2.args = arguments, new _(n2); | ||
var e2 = t3.date, n2 = t3.utc; | ||
if (null === e2) | ||
return /* @__PURE__ */ new Date(NaN); | ||
if (b.u(e2)) | ||
return /* @__PURE__ */ new Date(); | ||
if (e2 instanceof Date) | ||
return new Date(e2); | ||
if (null === e2) return /* @__PURE__ */ new Date(NaN); | ||
if (b.u(e2)) return /* @__PURE__ */ new Date(); | ||
if (e2 instanceof Date) return new Date(e2); | ||
if ("string" == typeof e2 && !/Z$/i.test(e2)) { | ||
@@ -171,4 +164,3 @@ var r2 = e2.match($); | ||
y2.$d[l2]($2), y2.init(), this.$d = y2.set(d, Math.min(this.$D, y2.daysInMonth())).$d; | ||
} else | ||
l2 && this.$d[l2]($2); | ||
} else l2 && this.$d[l2]($2); | ||
return this.init(), this; | ||
@@ -186,10 +178,6 @@ }, m2.set = function(t2, e2) { | ||
}; | ||
if ($2 === c) | ||
return this.set(c, this.$M + r2); | ||
if ($2 === h) | ||
return this.set(h, this.$y + r2); | ||
if ($2 === a) | ||
return y2(1); | ||
if ($2 === o) | ||
return y2(7); | ||
if ($2 === c) return this.set(c, this.$M + r2); | ||
if ($2 === h) return this.set(h, this.$y + r2); | ||
if ($2 === a) return y2(1); | ||
if ($2 === o) return y2(7); | ||
var M3 = (d2 = {}, d2[s] = e, d2[u] = n, d2[i] = t, d2)[$2] || 1, m3 = this.$d.getTime() + r2 * M3; | ||
@@ -201,4 +189,3 @@ return b.w(m3, this); | ||
var e2 = this, n2 = this.$locale(); | ||
if (!this.isValid()) | ||
return n2.invalidDate || l; | ||
if (!this.isValid()) return n2.invalidDate || l; | ||
var r2 = t2 || "YYYY-MM-DDTHH:mm:ssZ", i2 = b.z(this), s2 = this.$H, u2 = this.$m, a2 = this.$M, o2 = n2.weekdays, c2 = n2.months, f2 = n2.meridiem, h2 = function(t3, n3, i3, s3) { | ||
@@ -307,4 +294,3 @@ return t3 && (t3[n3] || t3(e2, r2)) || i3[n3].slice(0, s3); | ||
}, m2.locale = function(t2, e2) { | ||
if (!t2) | ||
return this.$L; | ||
if (!t2) return this.$L; | ||
var n2 = this.clone(), r2 = w(t2, e2, true); | ||
@@ -371,3 +357,3 @@ return r2 && (n2.$L = r2), n2; | ||
// node_modules/chalk/source/vendor/ansi-styles/index.js | ||
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js | ||
var ANSI_BACKGROUND_OFFSET = 10; | ||
@@ -558,6 +544,6 @@ var wrapAnsi16 = (offset = 0) => (code) => `\x1B[${code + offset}m`; | ||
// node_modules/chalk/source/vendor/supports-color/index.js | ||
var import_node_process = __toESM(require("process"), 1); | ||
var import_node_os = __toESM(require("os"), 1); | ||
var import_node_tty = __toESM(require("tty"), 1); | ||
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/supports-color/index.js | ||
var import_node_process = __toESM(require("node:process"), 1); | ||
var import_node_os = __toESM(require("node:os"), 1); | ||
var import_node_tty = __toESM(require("node:tty"), 1); | ||
function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) { | ||
@@ -685,3 +671,3 @@ const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--"; | ||
// node_modules/chalk/source/utilities.js | ||
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/utilities.js | ||
function stringReplaceAll(string, substring, replacer) { | ||
@@ -716,3 +702,3 @@ let index = string.indexOf(substring); | ||
// node_modules/chalk/source/index.js | ||
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/index.js | ||
var { stdout: stdoutColor, stderr: stderrColor } = supports_color_default; | ||
@@ -939,11 +925,8 @@ var GENERATOR = Symbol("GENERATOR"); | ||
if (options.console) { | ||
if (options.timeStamp) | ||
logger.log(time, ...messages); | ||
else | ||
logger.log(...messages); | ||
if (options.timeStamp) logger.log(time, ...messages); | ||
else logger.log(...messages); | ||
} | ||
} | ||
function logFile(file) { | ||
if (typeof file !== "string") | ||
return; | ||
if (typeof file !== "string") return; | ||
options.logFile = file; | ||
@@ -960,4 +943,3 @@ streams.logFile = true; | ||
function accessFile(file) { | ||
if (typeof file !== "string") | ||
return; | ||
if (typeof file !== "string") return; | ||
options.accessFile = file; | ||
@@ -974,4 +956,3 @@ streams.accessFile = true; | ||
function clientFile(file) { | ||
if (typeof file !== "string") | ||
return; | ||
if (typeof file !== "string") return; | ||
options.clientFile = file; | ||
@@ -1000,6 +981,4 @@ streams.clientFile = true; | ||
const time = (0, import_dayjs.default)(Date.now()).format(options.dateFormat); | ||
if (options.console) | ||
logger.log(time, tags.timed, `${elapsed.toLocaleString()} ms`, ...messages); | ||
if (streams.logFile && streams.logStream) | ||
streams.logStream.write(`${tags.timed} ${time} ${elapsed.toLocaleString()} ms ${combineMessages(...messages)} | ||
if (options.console) logger.log(time, tags.timed, `${elapsed.toLocaleString()} ms`, ...messages); | ||
if (streams.logFile && streams.logStream) streams.logStream.write(`${tags.timed} ${time} ${elapsed.toLocaleString()} ms ${combineMessages(...messages)} | ||
`); | ||
@@ -1009,21 +988,15 @@ } | ||
const time = (0, import_dayjs.default)(Date.now()).format(options.dateFormat); | ||
if (tags[tag]) | ||
print(tags[tag], ...messages); | ||
else | ||
print(...messages); | ||
if (streams.logFile && streams.logStream) | ||
streams.logStream.write(`${time} ${tags[tag]} ${combineMessages(...messages)} | ||
if (tags[tag]) print(tags[tag], ...messages); | ||
else print(...messages); | ||
if (streams.logFile && streams.logStream) streams.logStream.write(`${time} ${tags[tag]} ${combineMessages(...messages)} | ||
`); | ||
ring.push({ tag, time, msg: combineMessages(...messages) }); | ||
if (ring.length > options.ringLength) | ||
ring.shift(); | ||
if (ring.length > options.ringLength) ring.shift(); | ||
} | ||
async function assert(res, exp, ...messages) { | ||
if (res !== exp) | ||
log("assert", ...messages, { res, exp }); | ||
if (res !== exp) log("assert", ...messages, { res, exp }); | ||
} | ||
async function access(...messages) { | ||
const time = (0, import_dayjs.default)(Date.now()).format(options.dateFormat); | ||
if (streams.accessFile && streams.accessStream) | ||
streams.accessStream.write(`${time} ${combineMessages(...messages)} | ||
if (streams.accessFile && streams.accessStream) streams.accessStream.write(`${time} ${combineMessages(...messages)} | ||
`); | ||
@@ -1033,21 +1006,13 @@ } | ||
const time = (0, import_dayjs.default)(Date.now()).format(options.dateFormat); | ||
if (streams.clientFile && streams.clientStream) | ||
streams.clientStream.write(`${time} ${combineMessages(...messages)} | ||
if (streams.clientFile && streams.clientStream) streams.clientStream.write(`${time} ${combineMessages(...messages)} | ||
`); | ||
} | ||
function configure(userOptions) { | ||
if (!userOptions) | ||
return; | ||
if (userOptions.dateFormat) | ||
options.dateFormat = userOptions.dateFormat; | ||
if (userOptions.ringLength) | ||
options.ringLength = userOptions.ringLength; | ||
if (userOptions.logFile) | ||
logFile(userOptions.logFile); | ||
if (userOptions.accessFile) | ||
accessFile(userOptions.accessFile); | ||
if (userOptions.clientFile) | ||
clientFile(userOptions.clientFile); | ||
if (userOptions.inspect) | ||
inspectOptions = { ...inspectOptions, ...userOptions.inspect }; | ||
if (!userOptions) return; | ||
if (userOptions.dateFormat) options.dateFormat = userOptions.dateFormat; | ||
if (userOptions.ringLength) options.ringLength = userOptions.ringLength; | ||
if (userOptions.logFile) logFile(userOptions.logFile); | ||
if (userOptions.accessFile) accessFile(userOptions.accessFile); | ||
if (userOptions.clientFile) clientFile(userOptions.clientFile); | ||
if (userOptions.inspect) inspectOptions = { ...inspectOptions, ...userOptions.inspect }; | ||
logger = new import_console.Console({ | ||
@@ -1062,4 +1027,3 @@ stdout: process.stdout, | ||
const f = "./package.json"; | ||
if (!fs.existsSync(f)) | ||
return; | ||
if (!fs.existsSync(f)) return; | ||
const node = JSON.parse(fs.readFileSync(f).toString()); | ||
@@ -1069,13 +1033,9 @@ process.title = node.name; | ||
log("info", "User:", os2.userInfo().username, "Platform:", process.platform, "Arch:", process.arch, "Node:", process.version); | ||
if (options.logFile && streams.logFile) | ||
print(tags.state, "Application log:", path.resolve(options.logFile)); | ||
if (options.accessFile && streams.accessFile) | ||
print(tags.state, "Access log:", path.resolve(options.accessFile)); | ||
if (options.clientFile && streams.clientFile) | ||
print(tags.state, "Client log:", path.resolve(options.clientFile)); | ||
if (options.logFile && streams.logFile) print(tags.state, "Application log:", path.resolve(options.logFile)); | ||
if (options.accessFile && streams.accessFile) print(tags.state, "Access log:", path.resolve(options.accessFile)); | ||
if (options.clientFile && streams.clientFile) print(tags.state, "Client log:", path.resolve(options.clientFile)); | ||
} | ||
function headerJson() { | ||
const f = "./package.json"; | ||
if (!fs.existsSync(f)) | ||
return; | ||
if (!fs.existsSync(f)) return; | ||
const node = JSON.parse(fs.readFileSync(f).toString()); | ||
@@ -1085,4 +1045,3 @@ process.title = node.name; | ||
log("info", { user: os2.userInfo().username, platform: process.platform, arch: process.arch, node: process.version }); | ||
if (options.logFile || options.accessFile || options.clientFile) | ||
print(tags.state, { log: path.resolve(options.logFile || ""), access: path.resolve(options.accessFile || ""), client: path.resolve(options.clientFile || "") }); | ||
if (options.logFile || options.accessFile || options.clientFile) print(tags.state, { log: path.resolve(options.logFile || ""), access: path.resolve(options.accessFile || ""), client: path.resolve(options.clientFile || "") }); | ||
} | ||
@@ -1089,0 +1048,0 @@ var blank = (...message) => log("blank", ...message); |
{ | ||
"name": "@vladmandic/pilogger", | ||
"version": "0.4.9", | ||
"version": "0.5.1", | ||
"description": "Simple Logger for NodeJS", | ||
@@ -31,17 +31,17 @@ "main": "dist/pilogger.js", | ||
"devDependencies": { | ||
"@types/node": "^20.10.3", | ||
"@typescript-eslint/eslint-plugin": "^6.13.2", | ||
"@typescript-eslint/parser": "^6.13.2", | ||
"@vladmandic/build": "^0.9.2", | ||
"@types/node": "^22.5.4", | ||
"@typescript-eslint/eslint-plugin": "^8.5.0", | ||
"@typescript-eslint/parser": "^8.5.0", | ||
"@vladmandic/build": "^0.9.3", | ||
"chalk": "^5.3.0", | ||
"dayjs": "^1.11.10", | ||
"esbuild": "^0.19.8", | ||
"eslint": "8.55.0", | ||
"dayjs": "^1.11.13", | ||
"esbuild": "^0.23.1", | ||
"eslint": "8.57.0", | ||
"eslint-config-airbnb-base": "^15.0.0", | ||
"eslint-plugin-html": "^7.1.0", | ||
"eslint-plugin-import": "^2.29.0", | ||
"eslint-plugin-json": "^3.1.0", | ||
"tslib": "^2.6.2", | ||
"typescript": "^5.3.2" | ||
"eslint-plugin-html": "^8.1.1", | ||
"eslint-plugin-import": "^2.30.0", | ||
"eslint-plugin-json": "^4.0.1", | ||
"tslib": "^2.7.0", | ||
"typescript": "5.5.4" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
71222
1445