Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shazron opened this issue Jul 31, 2023 · 0 comments
Open

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

shazron opened this issue Jul 31, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@shazron
Copy link
Member

shazron commented Jul 31, 2023

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')
}
@shazron shazron added the enhancement New feature or request label Jul 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant