Skip to content

Instantly share code, notes, and snippets.

@raphtlw
Created December 23, 2020 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raphtlw/d9243e297cff6b7e4847372b3cecbca5 to your computer and use it in GitHub Desktop.
Save raphtlw/d9243e297cff6b7e4847372b3cecbca5 to your computer and use it in GitHub Desktop.
Simple logging boilerplate for Javascript
export class Log {
private static getTime() {
const date = new Date()
return `[${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}]`
}
static d(_: unknown) {
const message = `${this.getTime()} [debug] ${_}`
console.log(message)
}
static i(_: unknown) {
const message = `${this.getTime()} [info] ${_}`
console.log(message)
}
static w(_: unknown) {
const message = `${this.getTime()} [warning] ${_}`
console.log(message)
}
static e(_: unknown) {
const message = `${this.getTime()} [ERROR] ${_}`
console.log(message)
}
static f(_: unknown) {
const message = `${this.getTime()} [FATAL] ${_}`
console.log(message)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment