summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
authorAya Morisawa <AyaMorisawa4869@gmail.com>2016-12-29 17:36:03 +0900
committerAya Morisawa <AyaMorisawa4869@gmail.com>2016-12-29 17:36:03 +0900
commitcf446ac53ce557d00ac1422d48f61e48bcaa37d8 (patch)
tree2d7830dd43ca78dfb51b5210bc417fa258da1ccb /src/utils
parent:hammer: (diff)
downloadsharkey-cf446ac53ce557d00ac1422d48f61e48bcaa37d8.tar.gz
sharkey-cf446ac53ce557d00ac1422d48f61e48bcaa37d8.tar.bz2
sharkey-cf446ac53ce557d00ac1422d48f61e48bcaa37d8.zip
Implement logger
log-cool is no longer with Misskey
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/check-dependencies.ts8
-rw-r--r--src/utils/logger.ts16
2 files changed, 20 insertions, 4 deletions
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}`);
+}