adobe / adobe/aio-lib-core-logging
add ability to set log level after logger is constructed
- Dominant language
- JavaScript
- Stars
- 3
- Forks
- 8
- PR merge metrics
- No merged PRs in 30d
Description
## Description
Right now you have to set the log level via the constructor like so:
```javascript
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
```javascript
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.
```javascript
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')
}
```
Contributor guide
Research direction
Start at the package entry point used by require('@adobe/aio-lib-core-logging') and inspect how the constructor currently applies the log level. The issue names no source files or tests; done means a constructed logger can accept a later LOG_LEVEL value and subsequent debug calls follow that level.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100