@adobe/aio-lib-core-logging
Advanced tools
Comparing version 0.0.4 to 1.0.0
{ | ||
"name": "@adobe/aio-lib-core-logging", | ||
"version": "0.0.4", | ||
"version": "1.0.0", | ||
"description": "Logger framework for the Adobe I/O SDK", | ||
@@ -27,3 +27,3 @@ "main": "src/AioLogger.js", | ||
"eslint-plugin-import": "^2.18.2", | ||
"eslint-plugin-jest": "^22.15.2", | ||
"eslint-plugin-jest": "^23.0.2", | ||
"eslint-plugin-node": "^10.0.0", | ||
@@ -30,0 +30,0 @@ "eslint-plugin-promise": "^4.2.1", |
@@ -43,2 +43,4 @@ # aio-lib-core-logging | ||
The log level can also be overridden using the env variable AIO_LOG_LEVEL | ||
### Using custom logger | ||
@@ -45,0 +47,0 @@ |
@@ -54,3 +54,3 @@ /* | ||
this.config = {} | ||
this.config.level = config.level || DEFAULT_LEVEL | ||
this.config.level = process.env.AIO_LOG_LEVEL || config.level || DEFAULT_LEVEL | ||
this.config.provider = config.provider || DEFAULT_PROVIDER | ||
@@ -57,0 +57,0 @@ // config.logSourceAction will only be TRUE if both __OW_ACTION_NAME env var is set |
@@ -19,2 +19,3 @@ /* | ||
debug.log = this.getDestination() | ||
debug.enable(this.getDebugLevel()) | ||
this.errorLogger = debug(config.label).extend('error') | ||
@@ -40,2 +41,28 @@ this.warnLogger = debug(config.label).extend('warn') | ||
getDebugLevel () { | ||
let debugLevel | ||
const label = this.config.label | ||
switch (this.config.level) { | ||
case 'error' : | ||
debugLevel = label + ':error' | ||
break | ||
case 'warn' : | ||
debugLevel = label + ':error,' + label + ':warn' | ||
break | ||
case 'info' : | ||
debugLevel = label + ':error,' + label + ':warn,' + label + ':info' | ||
break | ||
case 'verbose' : | ||
debugLevel = label + ':error,' + label + ':warn,' + label + ':info,' + label + ':verbose' | ||
break | ||
case 'debug' : | ||
debugLevel = label + ':error,' + label + ':warn,' + label + ':info,' + label + ':verbose,' + label + ':debug' | ||
break | ||
case 'silly' : | ||
debugLevel = label + ':*' | ||
break | ||
} | ||
return process.env.DEBUG ? process.env.DEBUG + ',' + debugLevel : debugLevel | ||
} | ||
close () { | ||
@@ -42,0 +69,0 @@ // TODO |
@@ -19,2 +19,3 @@ /* | ||
delete process.env.DEBUG | ||
delete process.env.AIO_LOG_LEVEL | ||
}) | ||
@@ -52,2 +53,12 @@ | ||
}) | ||
test('when AIO_LOG_LEVEL is used', () => { | ||
process.env.AIO_LOG_LEVEL = 'debug' | ||
const aioLogger = AioLogger('App', { logSourceAction: false }) | ||
expect(aioLogger.config.provider).toEqual('winston') | ||
expect(aioLogger.config.level).toEqual('debug') | ||
expect(aioLogger.config.logSourceAction).toEqual(false) | ||
expect(aioLogger.config.transports).toEqual(undefined) | ||
expect(aioLogger.config.silent).toEqual(false) | ||
}) | ||
}) | ||
@@ -108,9 +119,53 @@ | ||
expect.hasAssertions() | ||
try { | ||
AioLogger('App', { provider: '__a_surely_not_supported_provider1234' }) | ||
} catch (e) { | ||
expect(e.message).toEqual(expect.stringContaining('__a_surely_not_supported_provider1234')) | ||
expect(e.message).toEqual(expect.stringContaining('winston')) | ||
expect(e.message).toEqual(expect.stringContaining('debug')) | ||
} | ||
const provider = '__a_surely_not_supported_provider1234' | ||
const expectedError = new Error(`log provider ${provider} is not supported, use one of [winston, debug]`) | ||
const func = () => AioLogger('App', { provider }) | ||
expect(func).toThrow(expectedError) | ||
}) | ||
test('with Winston', () => { | ||
process.env.AIO_LOG_LEVEL = 'error' | ||
const aioLogger = AioLogger('App') | ||
aioLogger.error('message') | ||
aioLogger.info('message') | ||
expect(global.console.log).toHaveBeenCalledTimes(1) | ||
delete process.env.DEBUG | ||
}) | ||
test('with Debug and level being error', () => { | ||
process.env.AIO_LOG_LEVEL = 'error' | ||
const aioLogger = AioLogger('App', { provider: 'debug' }) | ||
aioLogger.error('message') | ||
aioLogger.warn('message') | ||
expect(global.console.log).toHaveBeenCalledTimes(1) | ||
}) | ||
test('with Debug and level being warn', () => { | ||
process.env.AIO_LOG_LEVEL = 'warn' | ||
const aioLogger = AioLogger('App', { provider: 'debug' }) | ||
aioLogger.warn('message') | ||
aioLogger.info('message') | ||
expect(global.console.log).toHaveBeenCalledTimes(1) | ||
}) | ||
test('with Debug and level being verbose', () => { | ||
process.env.AIO_LOG_LEVEL = 'verbose' | ||
const aioLogger = AioLogger('App', { provider: 'debug' }) | ||
aioLogger.verbose('message') | ||
aioLogger.debug('message') | ||
expect(global.console.log).toHaveBeenCalledTimes(1) | ||
}) | ||
test('with Debug and level being debug', () => { | ||
process.env.AIO_LOG_LEVEL = 'debug' | ||
const aioLogger = AioLogger('App', { provider: 'debug' }) | ||
aioLogger.verbose('message') | ||
aioLogger.debug('message') | ||
aioLogger.silly('message') | ||
expect(global.console.log).toHaveBeenCalledTimes(2) | ||
}) | ||
test('with Debug and level being silly', () => { | ||
process.env.AIO_LOG_LEVEL = 'silly' | ||
const aioLogger = AioLogger('App', { provider: 'debug' }) | ||
aioLogger.debug('message') | ||
aioLogger.silly('message') | ||
expect(global.console.log).toHaveBeenCalledTimes(2) | ||
}) |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
45613
426
1
87
21
1