gather-ts
Version:
A powerful code analysis and packaging tool designed for creating AI-friendly code representations for javascript and typescript projects.
106 lines • 3.69 kB
JavaScript
"use strict";
// src/utils/logging/Logger.ts
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
const services_1 = require("@/types/services");
class Logger extends services_1.BaseService {
constructor(deps, options = {}) {
super();
this.deps = deps;
this.colors = {
reset: "\x1b[0m",
bright: "\x1b[1m",
dim: "\x1b[2m",
blue: "\x1b[34m",
green: "\x1b[32m",
yellow: "\x1b[33m",
red: "\x1b[31m",
gray: "\x1b[90m",
...options.colors,
};
this.debugEnabled = options.enableDebug || false;
this.timestamp = options.timestamp || false;
this.logLevel = options.logLevel || "info";
}
async initialize() {
await super.initialize();
if (this.debugEnabled) {
this.debug("Logger initialized");
}
}
cleanup() {
if (this.debugEnabled) {
this.debug("Logger cleanup");
}
super.cleanup();
}
format(color, message) {
return `${this.colors[color]}${message}${this.colors.reset}`;
}
formatWithTimestamp(message) {
if (!this.timestamp)
return message;
const timestamp = new Date().toISOString();
return `[${timestamp}] ${message}`;
}
shouldLog(level) {
const levels = ["debug", "info", "warn", "error"];
const currentLevel = levels.indexOf(this.logLevel);
const messageLevel = levels.indexOf(level);
return messageLevel >= currentLevel;
}
info(message) {
if (!this.shouldLog("info"))
return;
const formattedMessage = this.formatWithTimestamp(this.format("blue", "ℹ") + " " + message);
this.deps.outputStream.write(formattedMessage + "\n");
}
success(message) {
if (!this.shouldLog("info"))
return;
const formattedMessage = this.formatWithTimestamp(this.format("green", "✓") + " " + message);
this.deps.outputStream.write(formattedMessage + "\n");
}
warn(message) {
if (!this.shouldLog("warn"))
return;
const formattedMessage = this.formatWithTimestamp(this.format("yellow", "⚠") + " " + message);
this.deps.outputStream.write(formattedMessage + "\n");
}
error(message) {
if (!this.shouldLog("error"))
return;
const formattedMessage = this.formatWithTimestamp(this.format("red", "✖") + " " + message);
this.deps.errorStream.write(formattedMessage + "\n");
}
debug(message) {
if (!this.debugEnabled || !this.shouldLog("debug"))
return;
const formattedMessage = this.formatWithTimestamp(this.format("gray", "→") + " " + message);
this.deps.outputStream.write(formattedMessage + "\n");
}
section(title) {
if (!this.shouldLog("info"))
return;
this.deps.outputStream.write("\n" + this.format("bright", title) + "\n");
this.deps.outputStream.write(this.format("dim", "─".repeat(title.length)) + "\n");
}
summary(title, stats) {
if (!this.shouldLog("info"))
return;
this.section(title);
Object.entries(stats).forEach(([key, value]) => {
this.deps.outputStream.write(this.format("gray", `${key.padStart(15)}: `) +
this.format("bright", String(value)) +
"\n");
});
}
enableDebug() {
this.debugEnabled = true;
}
isDebugEnabled() {
return this.debugEnabled;
}
}
exports.Logger = Logger;
//# sourceMappingURL=Logger.js.map