Last active
August 27, 2020 07:12
-
-
Save TomasKostadinov/14b2c3845a524ed911044f1316bde6b2 to your computer and use it in GitHub Desktop.
Typescript Log Class
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
export interface Configuration { | |
logging?: boolean; | |
} |
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
import {Configuration} from '../interfaces/configuration.interface'; | |
export default class Loggy { | |
constructor(private readonly config: Configuration) { | |
} | |
public log(...data: unknown[]) { | |
if (!this.config?.logging) return; | |
console.log('📗', ...data); | |
} | |
public info(...data: unknown[]) { | |
if (!this.config?.logging) return; | |
console.info('📘', ...data); | |
} | |
public warn(...data: unknown[]) { | |
if (!this.config?.logging) return; | |
console.warn('📙', ...data); | |
} | |
public error(...data: unknown[]) { | |
if (!this.config?.logging) return; | |
console.error('📕', ...data, '\x1b[0m'); | |
} | |
} |
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
Vars.loggy = new Loggy(config); |
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
import Loggy from './functions/loggy.func'; | |
export abstract class Vars { | |
public static loggy: Loggy; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment