1.0.9 • Published 3 years ago
@zzck.dev/logger v1.0.9
Yet another Logger
Features:
- Embedded highlightning
- Easy to use
- Not async (for now)
- Easily can be created as many loggers as you want with different settings
- Can be setup using config file (in progress)
- TS compatible
Get started
Simple usage
import { GetLogger } from "@zzck.dev/logger";
const mainLogger = GetLogger("main")
mainLogger.info('Info message')
mainLogger.warn('Warn message')
mainLogger.log('Log message')
mainLogger.error('Error message')
mainLogger.debug('DebugDisabled message')
/* By default debug is disabled */
mainLogger.config.debugEnabled = true
mainLogger.debug('DebugEnabled message')
Output:
Logger configuration
import { GetLogger } from "@zzck.dev/logger";
const configExample = GetLogger('ConfigExample')
configExample.config = {
name: "AnotherConfigExample",
infoEnabled: false,
logEnabled: false,
debugEnabled: true,
delim: '@'
}
configExample.info('Info message')
configExample.warn('Warn message')
configExample.log('Log message')
configExample.error('Error message')
configExample.debug('Debug message')
Output:
Advanced usage
Internally GetLogger
creates a singleton instance of LoggerManager which after spawns loggers. Following logic is incapsulated in GetLogger
function:
let _manager = null
function GetLogger(name: string): ConsoleLogger {
if (_manager == null) _manager = new ConsoleLoggerManager()
return _manager.Get(name)
}
So if you want to control the lifetime of logger manager object you can create it by yourself, as on the following example:
import { ConsoleLoggerManager } from "@zzck.dev/logger";
const manager = new ConsoleLoggerManager()
const logger = manager.Get("logger")
logger.error("2+2=5")
Output: