Created
December 23, 2020 10:07
-
-
Save raphtlw/d9243e297cff6b7e4847372b3cecbca5 to your computer and use it in GitHub Desktop.
Simple logging boilerplate for Javascript
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
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