forked from FoundKeyGang/FoundKey
Refactoring
This commit is contained in:
parent
64c1075b06
commit
4a23ebe534
3 changed files with 14 additions and 13 deletions
11
src/argv.ts
Normal file
11
src/argv.ts
Normal 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 };
|
11
src/index.ts
11
src/index.ts
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue