@bitdiver/model
Advanced tools
Comparing version 1.3.4 to 1.3.5
@@ -26,5 +26,7 @@ 'use strict'; | ||
class LogAdapter { | ||
constructor() { | ||
constructor(opts = {}) { | ||
// default is not to write to console | ||
this.writeConsole = false; | ||
this.logAdapterLogLevel = opts.logLevel ? opts.logLevel : LEVEL_DEBUG; | ||
} | ||
@@ -39,2 +41,29 @@ | ||
/** | ||
* Gets a numeric loglevel by loglevel symbol | ||
* @param loglevel {string} the loglevel to calc the numeric value for | ||
* @param logLevel {number} the numeric value | ||
*/ | ||
_getLogLevel(logLevel) { | ||
if (LEVEL_DEBUG === logLevel) { | ||
return 1; | ||
} else if (LEVEL_INFO === logLevel) { | ||
return 2; | ||
} else if (LEVEL_WARNING === logLevel) { | ||
return 3; | ||
} else if (LEVEL_ERROR === logLevel) { | ||
return 4; | ||
} else if (LEVEL_FATAL === logLevel) { | ||
return 5; | ||
} | ||
} | ||
/** | ||
* Function which determines if a log message should be logged | ||
* @param messageLogLevel {string} the message loglevel | ||
*/ | ||
_messageShouldBeLogged(messageLogLevel) { | ||
return this._getLogLevel(messageLogLevel) >= this._getLogLevel(this.logAdapterLogLevel); | ||
} | ||
/** | ||
* @param data {object} The object with the data to be logged and the needed meta data | ||
@@ -74,17 +103,20 @@ * const logMessage = { | ||
// Set the time of the log | ||
meta.logTime = Date.now(); | ||
const messageShouldBeLogged = this._messageShouldBeLogged(logLevel, this.logAdapterLogLevel); | ||
if (messageShouldBeLogged) { | ||
// Set the time of the log | ||
meta.logTime = Date.now(); | ||
// set the loglevel | ||
meta.logLevel = logMessage.logLevel; | ||
// set the loglevel | ||
meta.logLevel = logMessage.logLevel; | ||
if (meta.step !== undefined && meta.step.id !== undefined) { | ||
// this is a step log | ||
return this._logStep(meta, data, logLevel); | ||
} else if (meta.tc !== undefined && meta.tc.id !== undefined) { | ||
// This is a testcase log | ||
return this._logTestcase(meta, data, logLevel); | ||
if (meta.step !== undefined && meta.step.id !== undefined) { | ||
// this is a step log | ||
return this._logStep(meta, data, logLevel); | ||
} else if (meta.tc !== undefined && meta.tc.id !== undefined) { | ||
// This is a testcase log | ||
return this._logTestcase(meta, data, logLevel); | ||
} | ||
// This is a run log | ||
return this._logRun(meta, data, logLevel); | ||
} | ||
// This is a run log | ||
return this._logRun(meta, data, logLevel); | ||
} | ||
@@ -91,0 +123,0 @@ |
@@ -51,4 +51,4 @@ 'use strict'; | ||
class LogAdapterMemory extends _LogAdapter.LogAdapter { | ||
constructor() { | ||
super(); | ||
constructor(opts = {}) { | ||
super(opts); | ||
this.logs = {}; | ||
@@ -55,0 +55,0 @@ } |
{ | ||
"name": "@bitdiver/model", | ||
"version": "1.3.4", | ||
"version": "1.3.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -8,4 +8,8 @@ import { | ||
const logAdapterMemory = getLogAdapterMemory() | ||
const LOG_ADAPTER_LOG_LEVEL = 'debug' | ||
const logAdapterMemory = getLogAdapterMemory({ | ||
logLevel: LOG_ADAPTER_LOG_LEVEL, | ||
}) | ||
test('Logging: info', () => { | ||
@@ -12,0 +16,0 @@ const step = getStep() |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
235319
28
1008
1