Update log messages

This commit is contained in:
Aya Morisawa 2018-07-14 20:58:21 +09:00
parent f6863ed589
commit c3a330cb59
6 changed files with 52 additions and 52 deletions

23
package-lock.json generated
View file

@ -1,6 +1,6 @@
{
"name": "misskey",
"version": "4.17.1",
"version": "4.19.1",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -154,6 +154,11 @@
"@types/node": "*"
}
},
"@types/dateformat": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/@types/dateformat/-/dateformat-1.0.1.tgz",
"integrity": "sha1-LlsjXIxVZSxP7ChFBtKjb+Zf6H4="
},
"@types/debug": {
"version": "0.0.30",
"resolved": "https://registry.npmjs.org/@types/debug/-/debug-0.0.30.tgz",
@ -164,11 +169,6 @@
"resolved": "https://registry.npmjs.org/@types/deep-equal/-/deep-equal-1.0.1.tgz",
"integrity": "sha512-mMUu4nWHLBlHtxXY17Fg6+ucS/MnndyOWyOe7MmwkoMYxvfQU2ajtRaEvqSUv+aVkMqH/C0NCI8UoVfRNQ10yg=="
},
"@types/elasticsearch": {
"version": "5.0.24",
"resolved": "https://registry.npmjs.org/@types/elasticsearch/-/elasticsearch-5.0.24.tgz",
"integrity": "sha512-QRpGleGwKv70hEcdklBh3HiLZ3OHPp40nRiVfhLk9wlQ4+V//SX+n90uIHN/mfKz828bjSSAxSG/kDUEp4Yp8Q=="
},
"@types/events": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/@types/events/-/events-1.2.0.tgz",
@ -3729,9 +3729,9 @@
"integrity": "sha1-6vQ5/U1ISK105cx9vvIAZyueNFs="
},
"dateformat": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-2.2.0.tgz",
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI="
"version": "3.0.3",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-3.0.3.tgz",
"integrity": "sha512-jyCETtSl3VMZMWeRo7iY1FL19ges1t55hMo5yaam4Jrsm5EPL89UQkoQRyiI+Yf4k8r2ZpdngkV8hr1lIdjb3Q=="
},
"de-indent": {
"version": "1.0.2",
@ -7723,6 +7723,11 @@
"supports-color": "^2.0.0"
}
},
"dateformat": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/dateformat/-/dateformat-2.2.0.tgz",
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI="
},
"object-assign": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/object-assign/-/object-assign-3.0.0.tgz",

View file

@ -31,6 +31,7 @@
"@prezzemolo/rap": "0.1.2",
"@prezzemolo/zip": "0.0.3",
"@types/bcryptjs": "2.4.1",
"@types/dateformat": "1.0.1",
"@types/debug": "0.0.30",
"@types/deep-equal": "1.0.1",
"@types/elasticsearch": "5.0.25",
@ -92,6 +93,7 @@
"chalk": "2.4.1",
"crc-32": "1.2.0",
"css-loader": "1.0.0",
"dateformat": "3.0.3",
"debug": "3.1.0",
"deep-equal": "1.0.1",
"deepcopy": "0.6.3",

View file

@ -26,7 +26,7 @@ export default function load() {
const mixin = {} as Mixin;
// Validate URLs
if (!isUrl(config.url)) urlError(config.url);
if (!isUrl(config.url)) throw `url="${config.url}" is not a valid URL`;
const url = new URL(config.url);
config.url = normalizeUrl(config.url);
@ -50,8 +50,3 @@ export default function load() {
function normalizeUrl(url: string) {
return url[url.length - 1] === '/' ? url.substr(0, url.length - 1) : url;
}
function urlError(url: string) {
console.error(`${url}」は、正しいURLではありません。先頭に http:// または https:// をつけ忘れてないかなど確認してください。`);
process.exit(99);
}

View file

@ -63,18 +63,15 @@ async function masterMain() {
config = await init();
} catch (e) {
console.error(e);
Logger.error(chalk.red('Fatal error occurred during initializing :('));
Logger.error('Fatal error occurred during initialization');
process.exit(1);
}
Logger.info(chalk.green('Successfully initialized :)'));
Logger.succ('Successfully initialized');
spawnWorkers(() => {
Logger.info(chalk.bold.green(
`Now listening on port ${chalk.underline(config.port.toString())}`));
Logger.info(chalk.bold.green(`Now listening on port ${chalk.underline(config.port.toString())}`));
Logger.info(chalk.bold.green(config.url));
Logger.info(chalk.bold.green('Now processing jobs'));
});
}
@ -98,7 +95,6 @@ async function workerMain() {
*/
async function init(): Promise<Config> {
Logger.info('Welcome to Misskey!');
Logger.info('Initializing...');
EnvironmentInfo.show();
MachineInfo.show();
@ -110,14 +106,18 @@ async function init(): Promise<Config> {
try {
config = loadConfig();
} catch (exception) {
if (exception.code === 'ENOENT') {
throw 'Configuration not found - Please run "npm run config" command.';
if (typeof exception === 'string') {
configLogger.error(exception);
process.exit(1);
}
if (exception.code === 'ENOENT') {
configLogger.error('Configuration file not found');
process.exit(1);
}
throw exception;
}
configLogger.info('Successfully loaded');
configLogger.succ('Successfully loaded');
configLogger.info(`Maintainer: ${config.maintainer.name}`);
if (process.platform === 'linux' && !isRoot() && config.port < 1024) {
@ -133,7 +133,7 @@ async function init(): Promise<Config> {
// Try to connect to MongoDB
const mongoDBLogger = new Logger('MongoDB');
const db = require('./db/mongodb').default;
mongoDBLogger.info('Successfully connected');
mongoDBLogger.succ('Successfully connected');
db.close();
return config;

View file

@ -21,7 +21,7 @@ export default class {
const x = execSync(command, { stdio: ['pipe', 'pipe', 'ignore'] });
const ver = transform(x.toString());
if (ver != null) {
this.logger.info(`${serviceName} ${ver[1]} found`);
this.logger.succ(`${serviceName} ${ver[1]} found`);
} else {
this.logger.warn(`${serviceName} not found`);
this.logger.warn(`Regexp used for version check of ${serviceName} is probably messed up`);

View file

@ -1,14 +1,5 @@
import chalk, { Chalk } from 'chalk';
export type LogLevel = 'Error' | 'Warn' | 'Info';
function toLevelColor(level: LogLevel): Chalk {
switch (level) {
case 'Error': return chalk.red;
case 'Warn': return chalk.yellow;
case 'Info': return chalk.blue;
}
}
import chalk from 'chalk';
import * as dateformat from 'dateformat';
export default class Logger {
private domain: string;
@ -17,38 +8,45 @@ export default class Logger {
this.domain = domain;
}
public static log(level: LogLevel, message: string): void {
const color = toLevelColor(level);
const time = (new Date()).toLocaleTimeString('ja-JP');
const coloredMessage = level === 'Info' ? message : color.bold(message);
console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${coloredMessage}`);
public static log(level: string, message: string): void {
const time = dateformat(new Date(), 'HH:MM:ss');
console.log(`[${time} ${level}] ${message}`);
}
public static error(message: string): void {
Logger.log('Error', message);
(new Logger('')).error(message);
}
public static warn(message: string): void {
Logger.log('Warn', message);
(new Logger('')).warn(message);
}
public static info(message: string): void {
Logger.log('Info', message);
(new Logger('')).info(message);
}
public log(level: LogLevel, message: string): void {
Logger.log(level, `[${this.domain}] ${message}`);
public static succ(message: string): void {
(new Logger('')).succ(message);
}
public log(level: string, message: string) {
const domain = this.domain.length > 0 ? `[${this.domain}] ` : '';
Logger.log(level, `${domain}${message}`);
}
public error(message: string): void {
this.log('Error', message);
this.log(chalk.red.bold('ERROR'), chalk.red.bold(message));
}
public warn(message: string): void {
this.log('Warn', message);
this.log(chalk.yellow.bold('WARN'), chalk.yellow.bold(message));
}
public info(message: string): void {
this.log('Info', message);
this.log(chalk.blue.bold('INFO'), message);
}
public succ(message: string): void {
this.log(chalk.blue.bold('INFO'), chalk.green.bold(message));
}
}