Skip to content

Instantly share code, notes, and snippets.

@Jamie-
Created June 19, 2020 23:19
Show Gist options
  • Save Jamie-/4b7bd23c462c6f7838295f503e9c94ab to your computer and use it in GitHub Desktop.
Save Jamie-/4b7bd23c462c6f7838295f503e9c94ab to your computer and use it in GitHub Desktop.
Simple custom JS logging formating
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