mirror of
https://github.com/misskey-dev/misskey
synced 2024-12-22 18:48:34 +09:00
18 lines
511 B
TypeScript
18 lines
511 B
TypeScript
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);
|
|
let time = (new Date()).toLocaleTimeString([], { hour12: false });
|
|
console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${message}`);
|
|
}
|