Skip to content

Commit

Permalink
Added option to disable signale instances. Fixes #41
Browse files Browse the repository at this point in the history
  • Loading branch information
klaudiosinani committed Jun 10, 2018
1 parent 6e57095 commit 567f468
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions signale.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class Signale {
this._interactive = options.interactive || false;
this._config = Object.assign(this.packageConfiguration, options.config);
this._customTypes = Object.assign({}, options.types);
this._disabled = options.disabled || false;
this._scopeName = options.scope || '';
this._timers = options.timers || new Map();
this._types = this._mergeTypes(defaultTypes, this._customTypes);
Expand All @@ -48,13 +49,18 @@ class Signale {
get currentOptions() {
return Object.assign({}, {
config: this._config,
disabled: this._disabled,
types: this._customTypes,
interactive: this._interactive,
timers: this._timers,
stream: this._stream
});
}

get isEnabled() {
return !this._disabled;
}

get date() {
return new Date().toLocaleDateString();
}
Expand Down Expand Up @@ -237,9 +243,11 @@ class Signale {
}

_log(message, streams = this._stream) {
this._formatStream(streams).forEach(stream => {
this._write(stream, message);
});
if (this.isEnabled) {
this._formatStream(streams).forEach(stream => {
this._write(stream, message);
});
}
}

_logger(type, ...messageObj) {
Expand All @@ -250,6 +258,14 @@ class Signale {
this.configuration = configObj;
}

disable() {
this._disabled = true;
}

enable() {
this._disabled = false;
}

scope(...name) {
if (name.length === 0) {
throw new Error('No scope name was defined.');
Expand Down

0 comments on commit 567f468

Please sign in to comment.