forked from FoundKeyGang/FoundKey
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:
parent
38c2d86983
commit
239a52eb99
4 changed files with 10 additions and 10 deletions
|
@ -3,7 +3,7 @@ import chalk from 'chalk';
|
||||||
import Xev from 'xev';
|
import Xev from 'xev';
|
||||||
|
|
||||||
import Logger from '@/services/logger.js';
|
import Logger from '@/services/logger.js';
|
||||||
import { envOption } from '@/env.js';
|
import { envOption, LOG_LEVELS } from '@/env.js';
|
||||||
|
|
||||||
// for typeorm
|
// for typeorm
|
||||||
import 'reflect-metadata';
|
import 'reflect-metadata';
|
||||||
|
@ -66,7 +66,7 @@ cluster.on('exit', worker => {
|
||||||
});
|
});
|
||||||
|
|
||||||
// Display detail of unhandled promise rejection
|
// Display detail of unhandled promise rejection
|
||||||
if (!envOption.quiet) {
|
if (envOption.logLevel !== LOG_LEVELS.quiet) {
|
||||||
process.on('unhandledRejection', console.dir);
|
process.on('unhandledRejection', console.dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@ import Logger from '@/services/logger.js';
|
||||||
import { loadConfig } from '@/config/load.js';
|
import { loadConfig } from '@/config/load.js';
|
||||||
import { Config } from '@/config/types.js';
|
import { Config } from '@/config/types.js';
|
||||||
import { showMachineInfo } from '@/misc/show-machine-info.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';
|
import { db, initDb } from '@/db/postgre.js';
|
||||||
|
|
||||||
const _filename = fileURLToPath(import.meta.url);
|
const _filename = fileURLToPath(import.meta.url);
|
||||||
|
@ -25,7 +25,7 @@ const bootLogger = logger.createSubLogger('boot', 'magenta', false);
|
||||||
const themeColor = chalk.hex('#86b300');
|
const themeColor = chalk.hex('#86b300');
|
||||||
|
|
||||||
function greet(): void {
|
function greet(): void {
|
||||||
if (!envOption.quiet) {
|
if (envOption.logLevel !== LOG_LEVELS.quiet) {
|
||||||
//#region FoundKey logo
|
//#region FoundKey logo
|
||||||
console.log(themeColor(' ___ _ _ __ '));
|
console.log(themeColor(' ___ _ _ __ '));
|
||||||
console.log(themeColor(' | __|__ _ _ _ _ __| | |/ /___ _ _ '));
|
console.log(themeColor(' | __|__ _ _ _ _ __| | |/ /___ _ _ '));
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
export const LOG_LEVELS = {
|
export const LOG_LEVELS = {
|
||||||
|
quiet: 6,
|
||||||
error: 5,
|
error: 5,
|
||||||
warning: 4,
|
warning: 4,
|
||||||
success: 3,
|
success: 3,
|
||||||
|
@ -11,9 +12,7 @@ export const envOption = {
|
||||||
onlyServer: false,
|
onlyServer: false,
|
||||||
noDaemons: false,
|
noDaemons: false,
|
||||||
disableClustering: false,
|
disableClustering: false,
|
||||||
verbose: false,
|
|
||||||
withLogTime: false,
|
withLogTime: false,
|
||||||
quiet: false,
|
|
||||||
slow: false,
|
slow: false,
|
||||||
logLevel: LOG_LEVELS.info,
|
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') {
|
||||||
if (process.env.NODE_ENV === 'test') envOption.quiet = true;
|
envOption.disableClustering = true;
|
||||||
if (process.env.NODE_ENV === 'test') envOption.noDaemons = true;
|
envOption.logLevel = LOG_LEVELS.quiet;
|
||||||
|
envOption.noDaemons = true;
|
||||||
|
}
|
||||||
|
|
|
@ -62,7 +62,6 @@ export default class Logger {
|
||||||
* @param subDomains Names of sub-loggers to be added.
|
* @param subDomains Names of sub-loggers to be added.
|
||||||
*/
|
*/
|
||||||
private log(level: Level, message: string, important = false, subDomains: Domain[] = [], _store = true): void {
|
private log(level: Level, message: string, important = false, subDomains: Domain[] = [], _store = true): void {
|
||||||
if (envOption.quiet) return;
|
|
||||||
const store = _store && this.store;
|
const store = _store && this.store;
|
||||||
|
|
||||||
// Check against the configured log level.
|
// Check against the configured log level.
|
||||||
|
|
Loading…
Reference in a new issue