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