cn-shell
Version:
Cloud Native Shell
80 lines (79 loc) • 2.29 kB
JavaScript
import { Logger, LogLevel } from "./logger.js";
import * as util from "node:util";
export class LoggerConsole extends Logger {
constructor(name, logTimestamps, timestampFormat) {
super(name, logTimestamps, timestampFormat);
}
fatal(appOrExtName, ...args) {
if (this._level > LogLevel.LOG_COMPLETE_SILENCE) {
let msg = util.format(
`${this.timestamp()}FATAL: ${this._name}: ${appOrExtName}: ${args[0]}`,
...args.slice(1),
);
console.error(msg);
}
}
error(appOrExtName, ...args) {
if (this._level > LogLevel.LOG_COMPLETE_SILENCE) {
let msg = util.format(
`${this.timestamp()}ERROR: ${this._name}: ${appOrExtName}: ${args[0]}`,
...args.slice(1),
);
console.error(msg);
}
}
warn(appOrExtName, ...args) {
if (this._level > LogLevel.LOG_COMPLETE_SILENCE) {
let msg = util.format(
`${this.timestamp()}WARN: ${this._name}: ${appOrExtName}: ${args[0]}`,
...args.slice(1),
);
console.warn(msg);
}
}
info(appOrExtName, ...args) {
if (this._level >= LogLevel.LOG_INFO) {
let msg = util.format(
`${this.timestamp()}INFO: ${this._name}: ${appOrExtName}: ${args[0]}`,
...args.slice(1),
);
console.info(msg);
}
}
startup(appOrExtName, ...args) {
if (this._level >= LogLevel.LOG_START_UP) {
let msg = util.format(
`${this.timestamp()}STARTUP: ${this._name}: ${appOrExtName}: ${
args[0]
}`,
...args.slice(1),
);
console.info(msg);
}
}
debug(appOrExtName, ...args) {
if (this._level >= LogLevel.LOG_DEBUG) {
let msg = util.format(
`${this.timestamp()}DEBUG: ${this._name}: ${appOrExtName}: ${args[0]}`,
...args.slice(1),
);
console.info(msg);
}
}
trace(appOrExtName, ...args) {
if (this._level >= LogLevel.LOG_TRACE) {
let msg = util.format(
`${this.timestamp()}TRACE: ${this._name}: ${appOrExtName}: ${args[0]}`,
...args.slice(1),
);
console.info(msg);
}
}
force(appOrExtName, ...args) {
let msg = util.format(
`${this.timestamp()}FORCED: ${this._name}: ${appOrExtName}: ${args[0]}`,
...args.slice(1),
);
console.error(msg);
}
}