summaryrefslogtreecommitdiff
path: root/src
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
parent:hammer: (diff)
downloadmisskey-cf446ac53ce557d00ac1422d48f61e48bcaa37d8.tar.gz
misskey-cf446ac53ce557d00ac1422d48f61e48bcaa37d8.tar.bz2
misskey-cf446ac53ce557d00ac1422d48f61e48bcaa37d8.zip
Implement logger
log-cool is no longer with Misskey
Diffstat (limited to 'src')
-rw-r--r--src/index.ts24
-rw-r--r--src/utils/check-dependencies.ts8
-rw-r--r--src/utils/logger.ts16
3 files changed, 32 insertions, 16 deletions
diff --git a/src/index.ts b/src/index.ts
index b80b2da576..f22364a998 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -11,7 +11,7 @@ import * as fs from 'fs';
import * as os from 'os';
import * as cluster from 'cluster';
const prominence = require('prominence');
-import { logInfo, logDone, logWarn, logFailed } from 'log-cool';
+import { log } from './utils/logger';
import * as chalk from 'chalk';
const git = require('git-last-commit');
const portUsed = require('tcp-port-used');
@@ -151,41 +151,41 @@ async function init(): Promise<State> {
console.log('\nInitializing...\n');
if (IS_DEBUG) {
- logWarn('It is not in the Production mode. Do not use in the Production environment.');
+ log('Warn', 'It is not in the Production mode. Do not use in the Production environment.');
}
- logInfo(`environment: ${env}`);
+ log('Info', `environment: ${env}`);
// Get machine info
const totalmem = (os.totalmem() / 1024 / 1024 / 1024).toFixed(1);
const freemem = (os.freemem() / 1024 / 1024 / 1024).toFixed(1);
- logInfo(`MACHINE: ${os.hostname()}`);
- logInfo(`MACHINE: CPU: ${os.cpus().length}core`);
- logInfo(`MACHINE: MEM: ${totalmem}GB (available: ${freemem}GB)`);
+ log('Info', `MACHINE: ${os.hostname()}`);
+ log('Info', `MACHINE: CPU: ${os.cpus().length}core`);
+ log('Info', `MACHINE: MEM: ${totalmem}GB (available: ${freemem}GB)`);
if (!fs.existsSync(`${__dirname}/../.config/config.yml`)) {
- logFailed('Configuration not found');
+ log('Error', 'Configuration not found');
return State.failed;
}
- logDone('Success to load configuration');
- logInfo(`maintainer: ${config.maintainer}`);
+ log('Info', 'Success to load configuration');
+ log('Info', `maintainer: ${config.maintainer}`);
checkDependencies();
// Check if a port is being used
if (await portUsed.check(config.port)) {
- logFailed(`Port: ${config.port} is already used!`);
+ log('Error', `Port: ${config.port} is already used!`);
return State.failed;
}
// Try to connect to MongoDB
try {
const db = await initdb(config);
- logDone('Success to connect to MongoDB');
+ log('Info', 'Success to connect to MongoDB');
db.close();
} catch (e) {
- logFailed(`MongoDB: ${e}`);
+ log('Error', `MongoDB: ${e}`);
return State.failed;
}
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}`);
+}