Created
June 19, 2020 23:19
-
-
Save Jamie-/4b7bd23c462c6f7838295f503e9c94ab to your computer and use it in GitHub Desktop.
Simple custom JS logging formating
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
const timestamp = () => `${new Date().toISOString()}`; | |
const log = { | |
debug: (...args) => console.debug(timestamp(), "[DEBUG]", ...args), | |
info: (...args) => console.info(timestamp(), "[INFO]", ...args), | |
warning: (...args) => console.warn(timestamp(), "[WARNING]", ...args), | |
error: (...args) => console.error(timestamp(), "[ERROR]", ...args), | |
}; | |
// Usage | |
log.debug("a debug message"); | |
log.info("an info message"); | |
log.warning("a warning message"); | |
log.error("an error message"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment