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
78
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 1.1.1 to 1.1.2

2

package.json
{
"name": "@adobe/aio-lib-core-logging",
"version": "1.1.1",
"version": "1.1.2",
"description": "Logger framework for the Adobe I/O SDK",

@@ -5,0 +5,0 @@ "main": "src/AioLogger.js",

@@ -20,3 +20,11 @@ /*

debug.log = this.getDestination()
debug.enable(this.getDebugLevel())
// make sure to always take into account the latest DEBUG env var
debug.enable(process.env.DEBUG)
if (debug.enabled(this.config.label)) {
// => if we are here it means process.env.DEBUG === this.config.label
// (`${this.config.label}*` will also match the condition but it will set all log levels anyways)
// if let's say process.env.DEBUG === `${this.config.label}:debug` then we won't get
// into this branch and only debug logs will be shown
debug.enable(this.getDebugLevel())
}
this.errorLogger = debug(config.label).extend('error')

@@ -65,3 +73,3 @@ this.warnLogger = debug(config.label).extend('warn')

}
return process.env.DEBUG ? process.env.DEBUG + ',' + debugLevel : debugLevel
return process.env.DEBUG + ',' + debugLevel
}

@@ -68,0 +76,0 @@

@@ -15,4 +15,6 @@ /*

afterEach(() => {
jest.clearAllMocks()
global.console = { log: jest.fn() }
beforeEach(() => {
global.console.log.mockClear()
delete process.env.__OW_ACTION_NAME

@@ -65,17 +67,2 @@ delete process.env.DEBUG

test('Debug', () => {
process.env.DEBUG = '*'
global.console = { log: jest.fn() }
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(6)
})
test('Winston', async () => {

@@ -133,5 +120,70 @@ process.env.__OW_ACTION_NAME = 'fake-action'

expect(global.console.log).toHaveBeenCalledTimes(1)
delete process.env.DEBUG
})
test('with Debug and level being error', () => {
test('with Debug and DEBUG=*', () => {
process.env.DEBUG = '*'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(6)
})
test('with Debug and DEBUG=App:*', () => {
process.env.DEBUG = 'App:*'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(6)
})
test('with Debug and DEBUG=App*', () => {
process.env.DEBUG = 'App*'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(6)
})
test('with Debug and DEBUG=Ap*', () => {
process.env.DEBUG = 'Ap*'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(6)
})
test('with Debug and DEBUG=App and AIO_LOG_LEVEL', () => {
process.env.DEBUG = 'App'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
// info, warn, error
expect(global.console.log).toHaveBeenCalledTimes(3)
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('error'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('warn'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('info'))
})
test('with Debug and DEBUG=App and AIO_LOG_LEVEL=error', () => {
process.env.DEBUG = 'App'
process.env.AIO_LOG_LEVEL = 'error'

@@ -141,35 +193,152 @@ const aioLogger = AioLogger('App', { provider: 'debug' })

aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(1)
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('error'))
})
test('with Debug and level being warn', () => {
test('with Debug and DEBUG=App and AIO_LOG_LEVEL=warn', () => {
process.env.DEBUG = 'App'
process.env.AIO_LOG_LEVEL = 'warn'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
expect(global.console.log).toHaveBeenCalledTimes(1)
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(2)
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('error'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('warn'))
})
test('with Debug and level being verbose', () => {
test('with Debug and DEBUG=App and AIO_LOG_LEVEL=info', () => {
process.env.DEBUG = 'App'
process.env.AIO_LOG_LEVEL = 'info'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(3)
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('error'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('warn'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('info'))
})
test('with Debug and DEBUG=App and default AIO_LOG_LEVEL=verbose', () => {
process.env.DEBUG = 'App'
process.env.AIO_LOG_LEVEL = 'verbose'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
expect(global.console.log).toHaveBeenCalledTimes(1)
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(4)
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('error'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('warn'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('info'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('verbose'))
})
test('with Debug and level being debug', () => {
test('with Debug and DEBUG=App and AIO_LOG_LEVEL=debug', () => {
process.env.DEBUG = 'App'
process.env.AIO_LOG_LEVEL = 'debug'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
expect(global.console.log).toHaveBeenCalledTimes(2)
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(5)
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('error'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('warn'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('info'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('verbose'))
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('debug'))
})
test('with Debug and level being silly', () => {
test('with Debug and DEBUG=App:debug and AIO_LOG_LEVEL=error', () => {
// here the log level is ignored and only debug logs will be shown
process.env.DEBUG = 'App:debug'
process.env.AIO_LOG_LEVEL = 'error'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(1)
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('debug'))
})
test('with Debug and DEBUG=App:warn and AIO_LOG_LEVEL=silly', () => {
// here the log level is ignored and only error logs will be shown
process.env.DEBUG = 'App:warn'
process.env.AIO_LOG_LEVEL = 'silly'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
expect(global.console.log).toHaveBeenCalledTimes(2)
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(1)
expect(global.console.log).toHaveBeenCalledWith(expect.stringContaining('warn'))
})
test('debug with string substitution', () => {
test('with Debug and DEBUG=App and AIO_LOG_LEVEL=silly', () => {
process.env.DEBUG = 'App'
process.env.AIO_LOG_LEVEL = 'silly'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(6)
})
test('with Debug and DEBUG=Ap', () => {
process.env.DEBUG = 'Ap'
process.env.AIO_LOG_LEVEL = 'silly'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(0)
})
test('with Debug and DEBUG=Appnot', () => {
process.env.DEBUG = 'Apnot'
process.env.AIO_LOG_LEVEL = 'silly'
const aioLogger = AioLogger('App', { provider: 'debug' })
aioLogger.error('message')
aioLogger.warn('message')
aioLogger.info('message')
aioLogger.verbose('message')
aioLogger.debug('message')
aioLogger.silly('message')
aioLogger.close()
expect(global.console.log).toHaveBeenCalledTimes(0)
})
test('debug with string substitution and DEBUG=App', () => {
process.env.DEBUG = 'App'
process.env.AIO_LOG_LEVEL = 'debug'

@@ -183,3 +352,5 @@ const aioLogger = AioLogger('App', { provider: 'debug' })

test('winston debug with string substitution', async () => {
test('winston debug with string substitution and file transport', async () => {
// change-me: do not hit real file system and do not wait
fs.removeSync('./logfile.txt')

@@ -190,12 +361,9 @@ fs.closeSync(fs.openSync('./logfile.txt', 'w'))

aioLogger.close()
function getLog () {
return new Promise((resolve, reject) => {
setTimeout(function () {
const log = fs.readFileSync('./logfile.txt', 'utf8')
fs.removeSync('./logfile.txt')
resolve(log)
}, 1000)
})
async function getLog () {
await new Promise((resolve, reject) => setTimeout(resolve, 100))
const log = fs.readFileSync('./logfile.txt', 'utf8')
fs.removeSync('./logfile.txt')
return log
}
expect(await getLog()).toContain('message hello world 123')
})
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