mylogger/lib/salix.js

61 lines
1.3 KiB
JavaScript
Raw Normal View History

module.exports = class Salix {
constructor() {
this.conf = null;
this._logInfo = [];
this._salixVersion = null;
}
async init(logger) {
this.conf = logger.conf;
setInterval(() => this.getSalixVersion, this.conf.salix.renewInterval);
await this.salixLogInfo();
2024-04-25 05:34:32 +00:00
}
2024-04-25 05:34:32 +00:00
async fetch(path) {
2024-04-25 06:19:28 +00:00
try {
let salixCall = await fetch(`${this.conf.salix.url}/${path}`, {
method: "GET",
});
const response = JSON.parse(await salixCall.text());
if (salixCall.status !== 200) {
console.error(response.error);
throw new Error(response.error.message);
}
this._salixVersion = salixCall.headers.get("Salix-version");
return response;
} catch (error) {
throw new Error(error.message);
2024-04-25 05:34:32 +00:00
}
}
async getSalixVersion() {
2024-04-25 06:19:28 +00:00
this.log("CHECK VERSION");
2024-04-25 05:34:32 +00:00
2024-04-27 18:07:25 +00:00
const salixVersion = await this.fetch("applications/status");
2024-04-25 05:34:32 +00:00
if (this._salixVersion !== salixVersion) fetch();
2024-04-25 06:19:28 +00:00
this.log("VERSION CHECKED");
2024-04-25 05:34:32 +00:00
}
async salixLogInfo() {
2024-04-25 06:19:28 +00:00
this.log("LOGINFO REQUEST");
2024-04-25 05:34:32 +00:00
let salixLogConfig = await this.fetch("schemas/logInfo");
2024-04-25 06:19:28 +00:00
this._logInfo = salixLogConfig;
2024-04-25 05:34:32 +00:00
2024-04-25 06:19:28 +00:00
this.log("LOGINFO REQUESTED");
2024-04-25 05:34:32 +00:00
}
log(param) {
console.log(`${Salix.name} - ${param}`);
}
2024-04-25 05:34:32 +00:00
get logInfo() {
return this._logInfo;
}
2024-04-25 05:34:32 +00:00
get salixVersion() {
return this._salixVersion;
}
};