From 977af0a24d3f0b3cb9799d133b02c6316f286660 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 2 Mar 2019 18:51:59 +0900 Subject: ログをデータベースに保存して管理画面で見れるように MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/misc/check-mongodb.ts | 2 +- src/misc/logger.ts | 59 ------------------------------------------- src/misc/show-machine-info.ts | 2 +- 3 files changed, 2 insertions(+), 61 deletions(-) delete mode 100644 src/misc/logger.ts (limited to 'src/misc') diff --git a/src/misc/check-mongodb.ts b/src/misc/check-mongodb.ts index f3839da31f..8e03db5d42 100644 --- a/src/misc/check-mongodb.ts +++ b/src/misc/check-mongodb.ts @@ -1,6 +1,6 @@ import { nativeDbConn } from '../db/mongodb'; import { Config } from '../config/types'; -import Logger from './logger'; +import Logger from '../services/logger'; import { lessThan } from '../prelude/array'; const requiredMongoDBVersion = [3, 6]; diff --git a/src/misc/logger.ts b/src/misc/logger.ts deleted file mode 100644 index 1d159fb6a5..0000000000 --- a/src/misc/logger.ts +++ /dev/null @@ -1,59 +0,0 @@ -import * as cluster from 'cluster'; -import chalk from 'chalk'; -import * as dateformat from 'dateformat'; -import { program } from '../argv'; - -export default class Logger { - private domain: string; - private color?: string; - private parentLogger: Logger; - - constructor(domain: string, color?: string) { - this.domain = domain; - this.color = color; - } - - public createSubLogger(domain: string, color?: string): Logger { - const logger = new Logger(domain, color); - logger.parentLogger = this; - return logger; - } - - private log(level: string, message: string, important = false, subDomains: string[] = []): void { - if (program.quiet) return; - if (process.env.NODE_ENV === 'test') return; - const domain = this.color ? chalk.keyword(this.color)(this.domain) : chalk.white(this.domain); - const domains = [domain].concat(subDomains); - if (this.parentLogger) { - this.parentLogger.log(level, message, important, domains); - } else { - const time = dateformat(new Date(), 'HH:MM:ss'); - const process = cluster.isMaster ? '*' : cluster.worker.id; - let log = `${level} ${process}\t[${domains.join(' ')}]\t${message}`; - if (program.withLogTime) log = chalk.gray(time) + ' ' + log; - console.log(important ? chalk.bold(log) : log); - } - } - - public error(message: string | Error, important = false): void { // 実行を継続できない状況で使う - this.log(important ? chalk.bgRed.white('ERR ') : chalk.red('ERR '), chalk.red(message.toString()), important); - } - - public warn(message: string, important = false): void { // 実行を継続できるが改善すべき状況で使う - this.log(chalk.yellow('WARN'), chalk.yellow(message), important); - } - - public succ(message: string, important = false): void { // 何かに成功した状況で使う - this.log(important ? chalk.bgGreen.white('DONE') : chalk.green('DONE'), chalk.green(message), important); - } - - public debug(message: string, important = false): void { // デバッグ用に使う(開発者に必要だが利用者に不要な情報) - if (process.env.NODE_ENV != 'production' || program.verbose) { - this.log(chalk.gray('VERB'), chalk.gray(message), important); - } - } - - public info(message: string, important = false): void { // それ以外 - this.log(chalk.blue('INFO'), message, important); - } -} diff --git a/src/misc/show-machine-info.ts b/src/misc/show-machine-info.ts index a4d85edfe0..2aae019be2 100644 --- a/src/misc/show-machine-info.ts +++ b/src/misc/show-machine-info.ts @@ -1,6 +1,6 @@ import * as os from 'os'; import * as sysUtils from 'systeminformation'; -import Logger from './logger'; +import Logger from '../services/logger'; export async function showMachineInfo(parentLogger: Logger) { const logger = parentLogger.createSubLogger('machine'); -- cgit v1.2.3-freya