Skip to content
Extraits de code Groupes Projets
Valider 7f182d63 rédigé par Christian Paul's avatar Christian Paul
Parcourir les fichiers

Warn if the log level is invalid

parent c29cfc72
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -46,6 +46,10 @@ export class Log {
private static config: DiscordBridgeConfigLogging;
private static logger: Logger;
private static isValidLevel(level: string) {
return ['silly', 'verbose', 'info', 'http', 'warn', 'error', 'silent'].includes(level);
}
private static setupLogger() {
if (Log.logger) {
Log.logger.close();
......@@ -53,6 +57,9 @@ export class Log {
const tsports: transports.StreamTransportInstance[] = Log.config.files.map((file) =>
Log.setupFileTransport(file),
);
if (Log.config.console && !Log.isValidLevel(Log.config.console)) {
new Log("Log").warn("Console log level is invalid. Please pick one of the case-sensitive levels provided in the sample config.");
}
tsports.push(new transports.Console({
level: Log.config.console,
}));
......@@ -80,6 +87,10 @@ export class Log {
return info;
});
if (config.level && !Log.isValidLevel(config.level)) {
new Log("Log").warn(`Log level of ${config.file} is invalid. Please pick one of the case-sensitive levels provided in the sample config.`);
}
const opts = {
datePattern: config.datePattern,
filename: config.file,
......
......@@ -71,6 +71,24 @@ describe("Log", () => {
expect(Log.config.files).to.not.be.empty;
expect(Log.config.files[0].file).to.equal("./logfile.log");
});
it("should warn if log level got misspelled", () => {
Log.Configure({
console: "WARNING",
lineDateFormat: "HH:mm:ss",
});
expect(loggedMessages).to.contain("Console log level is invalid. Please pick one of the case-sensitive levels provided in the sample config.");
});
it("should warn if log level for a file got misspelled", () => {
Log.Configure({
files: [
{
file: "./logfile.log",
level: "WARNING",
},
],
});
expect(loggedMessages).to.contain("Log level of ./logfile.log is invalid. Please pick one of the case-sensitive levels provided in the sample config.");
});
});
describe("ForceSilent", () => {
it("should be silent", () => {
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter