add "quiet" log level

This log level replaces the "MK_QUIET" environment variable to unify
the interface in a sensible way. This also removes the "MK_VERBOSE"
environment variable which was unused.
This commit is contained in:
Johann150 2023-05-23 19:45:33 +02:00
parent 38c2d86983
commit 239a52eb99
Signed by untrusted user: Johann150
GPG key ID: 9EE6577A2A06F8F1
4 changed files with 10 additions and 10 deletions

View file

@ -3,7 +3,7 @@ import chalk from 'chalk';
import Xev from 'xev';
import Logger from '@/services/logger.js';
import { envOption } from '@/env.js';
import { envOption, LOG_LEVELS } from '@/env.js';
// for typeorm
import 'reflect-metadata';
@ -66,7 +66,7 @@ cluster.on('exit', worker => {
});
// Display detail of unhandled promise rejection
if (!envOption.quiet) {
if (envOption.logLevel !== LOG_LEVELS.quiet) {
process.on('unhandledRejection', console.dir);
}

View file

@ -11,7 +11,7 @@ import Logger from '@/services/logger.js';
import { loadConfig } from '@/config/load.js';
import { Config } from '@/config/types.js';
import { showMachineInfo } from '@/misc/show-machine-info.js';
import { envOption } from '@/env.js';
import { envOption, LOG_LEVELS } from '@/env.js';
import { db, initDb } from '@/db/postgre.js';
const _filename = fileURLToPath(import.meta.url);
@ -25,7 +25,7 @@ const bootLogger = logger.createSubLogger('boot', 'magenta', false);
const themeColor = chalk.hex('#86b300');
function greet(): void {
if (!envOption.quiet) {
if (envOption.logLevel !== LOG_LEVELS.quiet) {
//#region FoundKey logo
console.log(themeColor(' ___ _ _ __ '));
console.log(themeColor(' | __|__ _ _ _ _ __| | |/ /___ _ _ '));

View file

@ -1,4 +1,5 @@
export const LOG_LEVELS = {
quiet: 6,
error: 5,
warning: 4,
success: 3,
@ -11,9 +12,7 @@ export const envOption = {
onlyServer: false,
noDaemons: false,
disableClustering: false,
verbose: false,
withLogTime: false,
quiet: false,
slow: false,
logLevel: LOG_LEVELS.info,
};
@ -32,6 +31,8 @@ for (const key of Object.keys(envOption) as (keyof typeof envOption)[]) {
}
}
if (process.env.NODE_ENV === 'test') envOption.disableClustering = true;
if (process.env.NODE_ENV === 'test') envOption.quiet = true;
if (process.env.NODE_ENV === 'test') envOption.noDaemons = true;
if (process.env.NODE_ENV === 'test') {
envOption.disableClustering = true;
envOption.logLevel = LOG_LEVELS.quiet;
envOption.noDaemons = true;
}

View file

@ -62,7 +62,6 @@ export default class Logger {
* @param subDomains Names of sub-loggers to be added.
*/
private log(level: Level, message: string, important = false, subDomains: Domain[] = [], _store = true): void {
if (envOption.quiet) return;
const store = _store && this.store;
// Check against the configured log level.