Last active
May 30, 2023 17:32
-
-
Save airburst/1404d07ebdb9448477d69a08b32f9150 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
type LogLevel = "log" | "info" | "error" | "debug" | "warning"; | |
class Logger { | |
constructor() { | |
this.module = console; | |
} | |
format(message: string, level: LogLevel = "log"): string { | |
const dateTime = new Date().toISOString(); | |
return JSON.stringify({ time: dateTime, level, message }); | |
} | |
log(message: string, level: LogLevel = "log") { | |
this.module.log(this.format(message, level)); | |
} | |
info(message: string) { | |
this.log(message, "info"); | |
} | |
warning(message: string) { | |
this.log(message, "warning"); | |
} | |
error(message: string) { | |
this.log(message, "error"); | |
} | |
debug(message: string) { | |
this.log(message, "debug"); | |
} | |
} | |
const logger = new Logger(); | |
logger.log("test"); | |
logger.info("Nothing important"); | |
logger.warning("Warning!"); | |
logger.error("Alert!"); | |
logger.debug("Break point reached"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment