Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Add enabled property to Log plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
hamitb committed Oct 1, 2019
1 parent 86b7f2c commit 13048d4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/index.ts
Expand Up @@ -65,8 +65,9 @@ module.exports = (options: any) => {
const logPlugin = new Log(config.logConfig);
Logger.getLogManager().addListener(logPlugin);
}

config.plugins.push(Log.getInstance());
const logInstance = Log.getInstance();
logInstance.enable();
config.plugins.push(logInstance);
}

if (!(Utils.getConfiguration(envVariableKeys.THUNDRA_DISABLE_XRAY) === 'true') && config.xrayConfig.enabled) {
Expand Down
14 changes: 13 additions & 1 deletion src/plugins/Log.ts
Expand Up @@ -14,6 +14,7 @@ class Log {

options: LogConfig;
reporter: any;
enabled: boolean;
pluginContext: PluginContext;
apiKey: any;
logData: LogData;
Expand All @@ -33,7 +34,7 @@ class Log {
if (options) {
this.tracer = options.tracer;
}

this.enabled = false;
Log.instance = this;
this.config = options;
}
Expand Down Expand Up @@ -96,6 +97,9 @@ class Log {
}

reportLog(logInfo: any): void {
if (!this.enabled) {
return;
}
const logData = new LogData();
const activeSpan = this.tracer ? this.tracer.getActiveSpan() : undefined;
const spanId = activeSpan ? activeSpan.spanContext.spanId : '';
Expand Down Expand Up @@ -143,6 +147,14 @@ class Log {
});
}

enable(): void {
this.enabled = true;
}

disable(): void {
this.enabled = false;
}

destroy(): void {
if (Utils.getConfiguration(envVariableKeys.THUNDRA_LAMBDA_LOG_CONSOLE_DISABLE) !== 'true') {
this.unShimConsole();
Expand Down

0 comments on commit 13048d4

Please sign in to comment.