Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@adobe/aio-lib-core-logging

Package Overview
Dependencies
Maintainers
58
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@adobe/aio-lib-core-logging - npm Package Compare versions

Comparing version 0.0.4 to 1.0.0

4

package.json
{
"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)
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc