Last active
April 25, 2024 14:08
-
-
Save toky-nomena/279b93f86b3c3b32cfd575ba04f7acdc to your computer and use it in GitHub Desktop.
This file contains 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
const enum LogLevel { | |
Info = 'info', | |
Warning = 'warning', | |
Error = 'error', | |
} | |
class Logger { | |
private static logStyle = { | |
info: 'color: #3498db; font-weight: bold;', | |
warning: 'color: #f39c12; font-weight: bold;', | |
error: 'color: #e74c3c; font-weight: bold;', | |
}; | |
static log(level: LogLevel, message: string, title?: string) { | |
const style = Logger.logStyle[level] || ''; | |
const titleStyle = 'font-weight: bold;'; | |
const logTitle = title ? `%c[${level}] %c${title}` : `%c[${level}]`; | |
console.log(logTitle, style, titleStyle, title, message); | |
} | |
static info(message: string, title?: string) { | |
Logger.log(LogLevel.Info, message, title); | |
} | |
static warning(message: string, title?: string) { | |
Logger.log(LogLevel.Warning, message, title); | |
} | |
static error(message: string, title?: string) { | |
Logger.log(LogLevel.Error, message, title); | |
} | |
} | |
// Example usage: | |
Logger.info('This is an info message', 'Info Title'); | |
Logger.warning('This is a warning message', 'Warning Title'); | |
Logger.error('This is an error message', 'Error Title'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment