Implement logger
log-cool is no longer with Misskey
This commit is contained in:
@ -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}`);
|
||||
}
|
||||
}
|
||||
|
16
src/utils/logger.ts
Normal file
16
src/utils/logger.ts
Normal file
@ -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}`);
|
||||
}
|
Reference in New Issue
Block a user