@lewist9x/distil
Version:
An opinionated library for managing LLM pipelines. Define, track, rate, and curate prompt–completion pairs for fine-tuning.
50 lines (49 loc) • 1.7 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Logger = void 0;
// src/logger.ts
const elasticsearch_1 = require("@elastic/elasticsearch");
const config_1 = require("./config");
class Logger {
constructor(level = "DEBUG") {
this.level = level;
if (config_1.config.elastic.host) {
const clientConfig = {
node: config_1.config.elastic.host
};
// Only add authentication if credentials are provided
if (config_1.config.elastic.user && config_1.config.elastic.password) {
clientConfig.auth = {
username: config_1.config.elastic.user,
password: config_1.config.elastic.password
};
}
this.esClient = new elasticsearch_1.Client(clientConfig);
}
}
async logToES(index, message) {
if (!this.esClient)
return;
await this.esClient.index({
index,
body: { ...message, "@timestamp": new Date().toISOString() }
});
}
async debug(msg) {
console.debug(msg);
await this.logToES(config_1.config.elastic.logIndex, { level: "DEBUG", msg });
}
async info(msg) {
console.info(msg);
await this.logToES(config_1.config.elastic.logIndex, { level: "INFO", msg });
}
async warn(msg) {
console.warn(msg);
await this.logToES(config_1.config.elastic.logIndex, { level: "WARNING", msg });
}
async error(msg) {
console.error(msg);
await this.logToES(config_1.config.elastic.logIndex, { level: "ERROR", msg });
}
}
exports.Logger = Logger;