From cf446ac53ce557d00ac1422d48f61e48bcaa37d8 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Thu, 29 Dec 2016 17:36:03 +0900 Subject: Implement logger log-cool is no longer with Misskey --- src/utils/check-dependencies.ts | 8 ++++---- src/utils/logger.ts | 16 ++++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 src/utils/logger.ts (limited to 'src/utils') diff --git a/src/utils/check-dependencies.ts b/src/utils/check-dependencies.ts index 7bcb87a68f..364c24581d 100644 --- a/src/utils/check-dependencies.ts +++ b/src/utils/check-dependencies.ts @@ -1,4 +1,4 @@ -import {logInfo, logDone, logWarn} from 'log-cool'; +import { log } from './logger'; import {exec} from 'shelljs'; export default function(): void { @@ -6,7 +6,7 @@ export default function(): void { checkDependency('npm', 'npm -v', x => x.match(/^(.*)\r?\n$/)[1]); checkDependency('MongoDB', 'mongo --version', x => x.match(/^MongoDB shell version: (.*)\r?\n$/)[1]); checkDependency('Redis', 'redis-server --version', x => x.match(/v=([0-9\.]*)/)[1]); - logDone('Successfully checked external dependencies'); + log('Info', 'Successfully checked external dependencies'); } function checkDependency(serviceName: string, command: string, transform: (x: string) => string): void { @@ -16,8 +16,8 @@ function checkDependency(serviceName: string, command: string, transform: (x: st }; const x = exec(command, { silent: true }) as any; if (x.code === code.success) { - logInfo(`DEPS: ${serviceName} ${transform(x.stdout)}`); + log('Info', `DEPS: ${serviceName} ${transform(x.stdout)}`); } else if (x.code === code.notFound) { - logWarn(`Unable to find ${serviceName}`); + log('Warn', `Unable to find ${serviceName}`); } } diff --git a/src/utils/logger.ts b/src/utils/logger.ts new file mode 100644 index 0000000000..01c3fdc76a --- /dev/null +++ b/src/utils/logger.ts @@ -0,0 +1,16 @@ +import * as chalk from 'chalk'; + +export type LogLevel = 'Error' | 'Warn' | 'Info'; + +function toLevelColor(level: LogLevel): chalk.ChalkStyle { + switch (level) { + case 'Error': return chalk.red; + case 'Warn': return chalk.yellow; + case 'Info': return chalk.blue; + } +} + +export function log(level: LogLevel, message: string): void { + let color = toLevelColor(level); + console.log(`[${color.bold(level.toUpperCase())}] ${message}`); +} -- cgit v1.2.3-freya