Last active
November 17, 2023 21:54
-
-
Save kauefraga/5ff6d7b0e83c62d3c0de37a9b5862c78 to your computer and use it in GitHub Desktop.
Simple console output wrapper without any dependency. (typescript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type WhoIsLogging = 'SERVER' | 'MIDDLEWARE' | 'API' | 'DATABASE'; | |
// ANSI escape code | |
const reset = '\x1b[0m'; | |
// Foreground colors | |
const red = '\x1b[31m'; | |
const green = '\x1b[32m'; | |
const yellow = '\x1b[33m'; | |
const info = (who: WhoIsLogging, message: string) => { | |
console.info(`[${green}${who}${reset}] ${message}`); | |
}; | |
const warn = (who: WhoIsLogging, message: string) => { | |
console.warn(`[${yellow}${who}${reset}] ${message}`); | |
}; | |
const error = (who: WhoIsLogging, message: string) => { | |
console.error(`[${red}${who}${reset}] ${message}`); | |
}; | |
/* Examples | |
info('API', 'generating shortened url'); | |
warn('SERVER', 'booting up...'); | |
error('DATABASE', 'could not handle the amount of reading'); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment