Comparing version
@@ -41,2 +41,4 @@ declare namespace Logger { | ||
print?(text: string): void | ||
levels?: LevelConfig | ||
timestamp?: number | ||
} | ||
@@ -57,3 +59,2 @@ } | ||
// global config | ||
static timestamp: number | ||
static colors: number[] | ||
@@ -60,0 +61,0 @@ static instances: Record<string, Logger> |
@@ -141,4 +141,4 @@ "use strict"; | ||
output += record.content.replace(/\n/g, "\n" + " ".repeat(indent)); | ||
if (target.showDiff) { | ||
const diff = _Logger.timestamp && record.timestamp - _Logger.timestamp; | ||
if (target.showDiff && target.timestamp) { | ||
const diff = record.timestamp - target.timestamp; | ||
output += _Logger.color(target, code, " +" + import_cosmokit.Time.format(diff)); | ||
@@ -164,7 +164,7 @@ } | ||
} | ||
if (this.level < level) | ||
return; | ||
const id = ++_Logger.id; | ||
const timestamp = Date.now(); | ||
for (const target of _Logger.targets) { | ||
if (this.getLevel(target) < level) | ||
continue; | ||
const content = this.format(target, ...args); | ||
@@ -178,4 +178,4 @@ const record = { id, type, level, name: this.name, meta: this.meta, content, timestamp }; | ||
} | ||
target.timestamp = timestamp; | ||
} | ||
_Logger.timestamp = timestamp; | ||
}; | ||
@@ -212,6 +212,6 @@ } | ||
} | ||
get level() { | ||
getLevel(target) { | ||
var _a; | ||
const paths = this.name.split(":"); | ||
let config = _Logger.levels; | ||
let config = (target == null ? void 0 : target.levels) || _Logger.levels; | ||
do { | ||
@@ -222,2 +222,5 @@ config = (_a = config[paths.shift()]) != null ? _a : config["base"]; | ||
} | ||
get level() { | ||
return this.getLevel(); | ||
} | ||
set level(value) { | ||
@@ -248,3 +251,2 @@ const paths = this.name.split(":"); | ||
__publicField(_Logger, "id", 0); | ||
__publicField(_Logger, "timestamp", 0); | ||
__publicField(_Logger, "targets", [{ | ||
@@ -251,0 +253,0 @@ colors: import_supports_color.stdout && import_supports_color.stdout.level, |
{ | ||
"name": "reggol", | ||
"description": "Logger for professionals", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"sideEffects": false, | ||
@@ -6,0 +6,0 @@ "main": "lib/node.js", |
@@ -58,2 +58,4 @@ import { stdout } from 'supports-color' | ||
print?(text: string): void | ||
levels?: Logger.LevelConfig | ||
timestamp?: number | ||
} | ||
@@ -75,3 +77,2 @@ } | ||
static id = 0 | ||
static timestamp = 0 | ||
static targets: Logger.Target[] = [{ | ||
@@ -128,4 +129,4 @@ colors: stdout && stdout.level, | ||
output += record.content.replace(/\n/g, '\n' + ' '.repeat(indent)) | ||
if (target.showDiff) { | ||
const diff = Logger.timestamp && record.timestamp - Logger.timestamp | ||
if (target.showDiff && target.timestamp) { | ||
const diff = record.timestamp - target.timestamp | ||
output += Logger.color(target, code, ' +' + Time.format(diff)) | ||
@@ -163,6 +164,6 @@ } | ||
if (this.level < level) return | ||
const id = ++Logger.id | ||
const timestamp = Date.now() | ||
for (const target of Logger.targets) { | ||
if (this.getLevel(target) < level) continue | ||
const content = this.format(target, ...args) | ||
@@ -176,4 +177,4 @@ const record: Logger.Record = { id, type, level, name: this.name, meta: this.meta, content, timestamp } | ||
} | ||
target.timestamp = timestamp | ||
} | ||
Logger.timestamp = timestamp | ||
} | ||
@@ -214,5 +215,5 @@ } | ||
get level() { | ||
getLevel(target?: Logger.Target) { | ||
const paths = this.name.split(':') | ||
let config: Logger.Level = Logger.levels | ||
let config: Logger.Level = target?.levels || Logger.levels | ||
do { | ||
@@ -224,2 +225,6 @@ config = config[paths.shift()!] ?? config['base'] | ||
get level() { | ||
return this.getLevel() | ||
} | ||
set level(value) { | ||
@@ -226,0 +231,0 @@ const paths = this.name.split(':') |
Sorry, the diff of this file is not supported yet
64453
0.47%877
1.04%