Skip to content

Commit

Permalink
fix: Correct constructor to handle 0 values in config
Browse files Browse the repository at this point in the history
  • Loading branch information
samestrin committed Sep 30, 2024
1 parent 4d35c60 commit 793f7fd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/acl.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,28 @@ class ACL {
*/
constructor(config = {}) {
// Logging level settings
this.logLevel = config.logLevel || 1;
this.logLevel = typeof config.logLevel === "number" ? config.logLevel : 1;

// File logging options
this.outputFilename = config.outputFilename || null;
this.outputFilenameLogLevel =
config.outputFilenameLogLevel || this.logLevel;
this.outputFilenameLogLevel = config.outputFilenameLogLevel ?? 1;

// Include timestamps in log messages
this.includeTimestamps = config.includeTimestamps !== false;

// Memory usage settings
this.includeMemoryUsage = config.includeMemoryUsage || false;
this.memoryCheckFrequency = config.memoryCheckFrequency || 10;
this.memoryDisplayMode = config.memoryDisplayMode || 1;
this.memoryCheckFrequency = config.memoryCheckFrequency ?? 10; // Accept 0 values
this.memoryDisplayMode = config.memoryDisplayMode ?? 1; // Accept 0 values

// Caller info settings
this.includeCallerInfo = config.includeCallerInfo || false;
this.callerInfoLevel = config.callerInfoLevel || 2; // Default to warn and above
this.callerInfoDisplayMode = config.callerInfoDisplayMode || 1;
this.callerInfoLevel = config.callerInfoLevel ?? 2; // Accept 0 values
this.callerInfoDisplayMode = config.callerInfoDisplayMode ?? 1; // Accept 0 values

// Inline caller info settings
this.includeInlineCallerInfo = !!config.includeInlineCallerInfo;
this.inlineCallerInfoLevel = config.inlineCallerInfoLevel || 1;
this.inlineCallerInfoLevel = config.inlineCallerInfoLevel ?? 1; // Accept 0 values

// Include stack trace in error and fatal messages
this.includeStackTrace = !!config.includeStackTrace;
Expand Down Expand Up @@ -235,14 +234,17 @@ class ACL {
* @returns {boolean} - Whether to log to console.
*/
shouldLogToConsole(condition, level) {
console.log(this.logLevel, condition, level);
if (
this.logLevel === 0 ||
(typeof condition === "boolean" && !condition) ||
(this.logLevel === 2 && level < 2) ||
(this.logLevel === 3 && level < 3)
) {
console.log("shouldLogToConsole", "false");
return false;
}
console.log("shouldLogToConsole", "true");
return true;
}

Expand Down

0 comments on commit 793f7fd

Please sign in to comment.