1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-10-31 15:21:46 +09:00

Refactoring

This commit is contained in:
syuilo 2019-02-03 20:10:20 +09:00
parent 64c1075b06
commit 4a23ebe534
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
3 changed files with 14 additions and 13 deletions

11
src/argv.ts Normal file
View File

@ -0,0 +1,11 @@
import * as program from 'commander';
import * as pkg from '../package.json';
program
.version(pkg.version)
.option('--no-daemons', 'Disable daemon processes (for debbuging)')
.option('--disable-clustering', 'Disable clustering')
.option('--quiet', 'Suppress all logs')
.parse(process.argv);
export { program };

View File

@ -12,7 +12,6 @@ import chalk from 'chalk';
import * as portscanner from 'portscanner';
import * as isRoot from 'is-root';
import Xev from 'xev';
import * as program from 'commander';
import * as sysUtils from 'systeminformation';
import mongo, { nativeDbConn } from './db/mongodb';
@ -23,21 +22,13 @@ import loadConfig from './config/load';
import { Config } from './config/types';
import { lessThan } from './prelude/array';
import * as pkg from '../package.json';
import { program } from './argv';
const logger = new Logger('core', 'cyan');
const bootLogger = logger.createSubLogger('boot', 'magenta');
const clusterLog = logger.createSubLogger('cluster', 'orange');
const ev = new Xev();
//#region Command line argument definitions
program
.version(pkg.version)
.option('--no-daemons', 'Disable daemon processes (for debbuging)')
.option('--disable-clustering', 'Disable clustering')
.option('--quiet', 'Suppress all logs')
.parse(process.argv);
//#endregion
/**
* Init process
*/

View File

@ -1,8 +1,7 @@
import * as cluster from 'cluster';
import chalk from 'chalk';
import * as dateformat from 'dateformat';
const quiet = process.argv.find(x => x == '--quiet');
import { program } from '../argv';
export default class Logger {
private domain: string;
@ -21,7 +20,7 @@ export default class Logger {
}
public log(level: string, message: string, important = false): void {
if (quiet) return;
if (program.quiet) return;
const domain = this.color ? chalk.keyword(this.color)(this.domain) : chalk.white(this.domain);
if (this.parentLogger) {
this.parentLogger.log(level, `[${domain}]\t${message}`, important);