Log Level Managers
New in LogLayer v8.
Log level managers in LogLayer are responsible for managing log level settings across logger instances. They provide a way to control how log levels are inherited and propagated between parent and child loggers.
Do you need to specify a log level manager?
Log level managers are an advanced feature of LogLayer.
Unless you need to manage log levels in a specific way, you can use the default log level manager, which is already automatically used when creating a new LogLayer instance.
Available Log Level Managers
| Name | Package | Description |
|---|---|---|
| Default | Children inherit log level from parent, but changes from parent do not propagate down | |
| Global | Changes apply to all loggers globally | |
| One Way | Parent changes affect children, but child changes do not affect parents | |
| Linked | Parent and child changes affect each other bidirectionally |
Log Level Manager Management
Using a custom log level manager
You can set a custom log level manager using the withLogLevelManager() method.
Example usage:
import { GlobalLogLevelManager } from '@loglayer/log-level-manager-global';
const logger = new LogLayer({
transport: new ConsoleTransport({
logger: console
})
}).withLogLevelManager(new GlobalLogLevelManager());TIP
Use the withLogLevelManager() method right after creating the LogLayer instance. Using it after log levels have already been set may result in unexpected behavior.
Obtaining the current log level manager
You can get the current log level manager instance using the getLogLevelManager() method:
const logLevelManager = logger.getLogLevelManager();You can also type the return value when getting a specific log level manager implementation:
const globalLogLevelManager = logger.getLogLevelManager<GlobalLogLevelManager>();