Skip to content

Commit

Permalink
Add env variables to control logging level (#1213)
Browse files Browse the repository at this point in the history
  • Loading branch information
hectorhdzg authored Sep 25, 2023
1 parent aaafbfd commit 1721de1
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Library/JsonConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class JsonConfig implements IJsonConfig {
jsonString = fs.readFileSync(tempDir, "utf8");
}
catch (err) {
Logging.info("Failed to read JSON config file: ", err);
Logging.warn("Failed to read JSON config file: ", err);
}
}

Expand Down Expand Up @@ -238,7 +238,7 @@ export class JsonConfig implements IJsonConfig {
this.quickPulseHost = jsonConfig.quickPulseHost;
}
catch (err) {
Logging.info("Invalid JSON config file: ", err);
Logging.warn("Invalid JSON config file: ", err);
}
}
}
8 changes: 6 additions & 2 deletions Library/Logging.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import InternalAzureLogger = require("./InternalAzureLogger");


const ENV_enableDebugLogging = "APPLICATION_INSIGHTS_ENABLE_DEBUG_LOGS";
const ENV_disableWarningLogging = "APPLICATION_INSIGHTS_DISABLE_WARNING_LOGS";

class Logging {
public static enableDebug = false;
public static disableWarnings = false;
public static enableDebug = (process.env[ENV_enableDebugLogging]) ? true : false;
public static disableWarnings = (process.env[ENV_disableWarningLogging]) ? true : false;

private static TAG = "ApplicationInsights:";

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ appInsights.setup("<YOUR_CONNECTION_STRING>")
.start();
```
Logs could be put into local file using `APPLICATIONINSIGHTS_LOG_DESTINATION` environment variable, supported values are `file` and `file+console`, a file named `applicationinsights.log` will be generated on tmp folder by default, including all logs, `/tmp` for *nix and `USERDIR/AppData/Local/Temp` for Windows. Log directory could be configured using `APPLICATIONINSIGHTS_LOGDIR` environment variable.
Debug Logs could be enabled as well using APPLICATION_INSIGHTS_ENABLE_DEBUG_LOGS environment variable, and APPLICATION_INSIGHTS_DISABLE_WARNING_LOGS environment variable to disable warnings. Logs could be put into local file using `APPLICATIONINSIGHTS_LOG_DESTINATION` environment variable, supported values are `file` and `file+console`, a file named `applicationinsights.log` will be generated on tmp folder by default, including all logs, `/tmp` for *nix and `USERDIR/AppData/Local/Temp` for Windows. Log directory could be configured using `APPLICATIONINSIGHTS_LOGDIR` environment variable.
```javascript
process.env.APPLICATIONINSIGHTS_LOG_DESTINATION = "file";
Expand Down

0 comments on commit 1721de1

Please sign in to comment.