Files

51 lines
961 B
TypeScript
Raw Permalink Normal View History

2018-04-12 18:02:48 +02:00
import * as plugins from './smartdebug.plugins';
2015-11-15 20:35:13 +01:00
2017-09-18 15:19:18 +02:00
export class SmartDebug {
2018-04-12 18:02:48 +02:00
private _debugEnabled: boolean = false;
2018-04-12 19:29:24 +02:00
constructor(debugTopic?: string) {
if (
process.env.SMARTDEBUG === 'true' ||
(debugTopic && process.env.SMARTDEBUG_TOPIC === debugTopic)
) {
this.enableDebugging();
}
}
get debugEnabled() {
2018-04-12 18:02:48 +02:00
return this._debugEnabled;
}
2017-09-18 15:19:18 +02:00
/**
* enables debugging output
*/
2018-04-12 18:02:48 +02:00
public enableDebugging() {
2018-04-12 19:29:24 +02:00
console.log('Enabled Debugging!');
2018-04-12 18:02:48 +02:00
this._debugEnabled = true;
}
/**
* disables debugging
*/
public disableDebugging() {
this._debugEnabled = false;
2017-09-18 15:19:18 +02:00
}
/**
* logs a message based on the contraints of the SmartDebug instance
*/
2018-04-12 18:02:48 +02:00
public log(logObject: any) {
if (this._debugEnabled) {
// tslint:disable-next-line:no-console
console.log(logObject);
2015-11-15 20:35:13 +01:00
}
2017-09-18 15:19:18 +02:00
}
2015-11-15 20:35:13 +01:00
2018-04-12 18:02:48 +02:00
/**
2018-04-12 19:29:24 +02:00
* a function returning
2018-04-12 18:02:48 +02:00
*/
public isDebugMode() {
return this._debugEnabled;
}
2017-09-18 15:19:18 +02:00
}