Skip to content

add ability to set log level after logger is constructed #44

Description

@shazron

Description

Right now you have to set the log level via the constructor like so:

const aioLogger = require('@adobe/aio-lib-core-logging')('App', { level: 'info' })

function main (params) {
     // you can't set the log level here, it is already fixed to `info` above
    // thus .debug won't output anything
     aioLogger.debug('this will not output anything')
}

Proposed setLogLevel feature

const aioLogger = require('@adobe/aio-lib-core-logging')('App')

function main (params) {
    // the log level is by default `info` and you can't change it after construction,
    // unless you add this feature like so
    aioLogger.setLogLevel(params.LOG_LEVEL)
   // if params.LOG_LEVEL was 'debug', now debug logs will show in the output
   aioLogger.debug('this will output if params.LOG_LEVEL is debug')
}

Workaround

The workaround is to create the logger with the log level, in your function scope.

const coreLogger = require('@adobe/aio-lib-core-logging')

function main (params) {
    const  aioLogger = coreLogger('App', { level: params.LOG_LEVEL })
   // if params.LOG_LEVEL was 'debug', debug logs will show in the output
    aioLogger.debug('this will output if params.LOG_LEVEL is debug')
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions