1
1
mirror of https://github.com/kokonect-link/cherrypick synced 2024-12-12 21:58:58 +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 portscanner from 'portscanner';
import * as isRoot from 'is-root'; import * as isRoot from 'is-root';
import Xev from 'xev'; import Xev from 'xev';
import * as program from 'commander';
import * as sysUtils from 'systeminformation'; import * as sysUtils from 'systeminformation';
import mongo, { nativeDbConn } from './db/mongodb'; import mongo, { nativeDbConn } from './db/mongodb';
@ -23,21 +22,13 @@ import loadConfig from './config/load';
import { Config } from './config/types'; import { Config } from './config/types';
import { lessThan } from './prelude/array'; import { lessThan } from './prelude/array';
import * as pkg from '../package.json'; import * as pkg from '../package.json';
import { program } from './argv';
const logger = new Logger('core', 'cyan'); const logger = new Logger('core', 'cyan');
const bootLogger = logger.createSubLogger('boot', 'magenta'); const bootLogger = logger.createSubLogger('boot', 'magenta');
const clusterLog = logger.createSubLogger('cluster', 'orange'); const clusterLog = logger.createSubLogger('cluster', 'orange');
const ev = new Xev(); 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 * Init process
*/ */

View File

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