diff --git a/src/actions/ping.ts b/src/actions/ping.ts index 41479f2..dfd83a5 100644 --- a/src/actions/ping.ts +++ b/src/actions/ping.ts @@ -17,7 +17,7 @@ export const pingAction = async ( retryCount++ const url = `https://${cid}.ipfs.${endpoint}` - console.log(`${isTTY + logger.text(`${isTTY ? `${colors.bold(`[${retryCount}]`)}: Requesting content at ${url}` : `[${retryCount}]`}: Requesting content at ${url}`, ) @@ -25,18 +25,18 @@ export const pingAction = async ( const response = await fetch(url, { signal: AbortSignal.timeout(timeout), redirect: 'follow' }) if (response.status === 504) { if (retries > 1) { - console.log(`🔄 Retrying in ${retryInterval / 1000} seconds...`) + logger.text(`🔄 Retrying in ${retryInterval / 1000} seconds...`) await new Promise(resolve => setTimeout(resolve, retryInterval)) return pingAction({ cid, endpoint, options: { maxRetries: retries - 1, retryInterval } }) } else { - return console.error(gwOfflineMessage) + return logger.error(gwOfflineMessage) } } else { - return console.log(`Gateway status: ${ + return logger.text(`Gateway status: ${ response.status >= 200 && response.status < 400 - ? logger.info((isTTY ? colors.bold(colors.green(`Online ${response.status}`)) : `Online ${response.status}`)) + ? (isTTY ? colors.bold(colors.green(`🟢 Online ${response.status}`)) : `🟢 Online ${response.status}`) : response.status }`) } @@ -44,11 +44,11 @@ export const pingAction = async ( catch (error) { if (error instanceof DOMException) { if (retries > 1) { - console.log(`⌛ Timed out. Retrying...`) + logger.info(`⌛ Timed out. Retrying...`) return pingAction({ cid, endpoint, options: { maxRetries: retries - 1, retryInterval } }) } else { - return console.error(gwOfflineMessage) + return logger.error(gwOfflineMessage) } } logger.error('Error fetching endpoint:', (error as Error).message) diff --git a/src/utils/logger.ts b/src/utils/logger.ts index fa4d681..d8dcab9 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -28,6 +28,9 @@ export const logger = { if (isTTY) console.log('\n', method === 'GET' ? cyan(method) : green(method), url, responseStatus(status)) else console.log('\n', method, url, status) }, + text(...args: unknown[]) { + console.log(...args) + }, } export const deployMessage = (provider: string, supports: SupportedMethods) => {