Skip to content

Commit

Permalink
wip [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
fmauNeko committed Jun 25, 2024
1 parent b35ce72 commit b155ca6
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 75 deletions.
93 changes: 93 additions & 0 deletions lib/kuzzle/Logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Kuzzle, a backend software, self-hostable and ready to use
* to power modern apps
*
* Copyright 2015-2022 Kuzzle
* mailto: support AT kuzzle.io
* website: http://kuzzle.io
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { pino, Logger as PinoLogger } from "pino";

export class Logger {
private pino: PinoLogger<"silly" | "verbose">;
private failsafeModeString: string;

constructor() {
this.pino = pino<"silly" | "verbose">({
customLevels: {
silly: 5,
verbose: 25,
},
});

this.failsafeModeString = global.kuzzle.config.plugins.common.failsafeMode
? "[FAILSAFE MODE] "
: "";
}

trace(message: string) {
this.pino.trace(this.formatMessage(message));
}

debug(message: string) {
this.pino.debug(this.formatMessage(message));
}

info(message: string) {
this.pino.info(this.formatMessage(message));
}

warn(message: string) {
this.pino.warn(this.formatMessage(message));
}

error(message: string) {
this.pino.error(this.formatMessage(message));
}

fatal(message: string) {
this.pino.fatal(this.formatMessage(message));
}

silly(message: string) {
this.pino.warn(
"[DEPRECATED] Logger.silly is deprecated, use Logger.trace instead.",
);
this.pino.silly(this.formatMessage(message));
}

verbose(message: string) {
this.pino.warn(
"[DEPRECATED] Logger.verbose is deprecated, use Logger.debug instead.",
);
this.pino.verbose(this.formatMessage(message));
}

private formatMessage(message: string): string {
const nodeIdString = global.kuzzle.id ? `[${global.kuzzle.id}] ` : "";
let requestIdString = "";

if (
global.kuzzle.asyncStore.exists() &&
global.kuzzle.asyncStore.has("REQUEST")
) {
const request = global.kuzzle.asyncStore.get("REQUEST");

requestIdString = `[${request.id}] `;
}
return `${nodeIdString}${this.failsafeModeString}${requestIdString}${message}`;
}
}
2 changes: 1 addition & 1 deletion lib/kuzzle/kuzzle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import Router from "../core/network/router";
import Statistics from "../core/statistics";
import { TokenManager } from "../core/auth/tokenManager";
import Validation from "../core/validation";
import Logger from "./log";
import { Logger } from "./Logger";
import vault from "./vault";
import DumpGenerator from "./dumpGenerator";
import AsyncStore from "../util/asyncStore";
Expand Down
74 changes: 0 additions & 74 deletions lib/kuzzle/log.js

This file was deleted.

0 comments on commit b155ca6

Please sign in to comment.