From 7c0d22945c91bb2b4bb823469940205f41a54a45 Mon Sep 17 00:00:00 2001 From: Aya Morisawa Date: Thu, 29 Dec 2016 20:03:34 +0900 Subject: [PATCH] :sparkles: --- src/index.ts | 10 +++++++--- src/utils/logger.ts | 14 ++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/index.ts b/src/index.ts index e5171a38f6..0bb6157176 100644 --- a/src/index.ts +++ b/src/index.ts @@ -139,10 +139,14 @@ async function init(): Promise { // Get commit info try { const commit = await prominence(git).getLastCommit(); - log('Info', `commit: ${commit.shortHash} ${commit.author.name} <${commit.author.email}>`); - log('Info', ` ${new Date(parseInt(commit.committedOn, 10) * 1000)}`); + const shortHash: string = commit.shortHash; + const hash: string = commit.hash; + const commitDate = new Date(parseInt(commit.committedOn, 10) * 1000).toLocaleDateString('ja-JP'); + const commitTime = new Date(parseInt(commit.committedOn, 10) * 1000).toLocaleTimeString('ja-JP'); + log('Info', `${shortHash}${chalk.gray(hash.substr(shortHash.length))}`, 'LastCommit'); + log('Info', `${commit.subject} ${chalk.green(`(${commitDate} ${commitTime})`)} ${chalk.blue(`<${commit.author.name}>`)}`, 'LastCommit'); } catch (e) { - // noop + log('Info', `No commit information found`, 'LastCommit'); } log('Info', 'Initializing...'); diff --git a/src/utils/logger.ts b/src/utils/logger.ts index de4ac65812..2189dd5ea5 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -10,8 +10,14 @@ function toLevelColor(level: LogLevel): chalk.ChalkStyle { } } -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}`); +export function log(level: LogLevel, message: string): void; +export function log(level: LogLevel, message: string, domain: string): void; +export function log(level: LogLevel, message: string, domain?: string): void { + if (typeof domain == 'string') { + log(level, `[${domain}] ${message}`); + } else { + let color = toLevelColor(level); + let time = (new Date()).toLocaleTimeString('ja-JP'); + console.log(`[${time} ${color.bold(level.toUpperCase())}]: ${message}`); + } }