multi-logger
A simple configurable multi level logger.
Install
npm i multi-loggerjs
Usage
Default Usage
const logger = ; let multiLogger = ; multiLogger;multiLogger;multiLogger;multiLogger;multiLogger;
Configuration
const logger = ; const options = dateFormat: "MMMM Do YYYY" timeFormat: "h:mm:ss" showFullPath: true showDate: true showTime: true showExternalCallerInfo: true; let multiLogger = options;multiLogger;
multi-logger is using for date and time formats.
Custom Loggers & Modifications
const logger = ;const foregrounds = loggerforegrounds;const backgrounds = loggerbackgrounds;const levels = loggerlevels; const options = loggers: info: badge: "ℹ" foreground: foregroundsMagenta background: backgroundsDefault isUnderlined: false text: foreground: foregroundsLightCyan background: backgroundsDefault isUnderlined: true label: "Info" level: levelsTrace status: level: levelsTrace badge: "☺" label: "Status" foreground: foregroundsLightGreen background: backgroundsDefault isUnderlined: true text: foreground: foregroundsWhite background: backgroundsLightRed isUnderlined: true ; let multiLogger = options;multiLogger;multiLoggerstatus"New logger!";
Available Foregrounds and Backgrounds
Available foregrounds and backgrounds are as follows; Default, Black, Red, Green, Yellow, Blue, Magenta, Cyan, LightGray, DarkGray, LightRed, LightGreen, LightYellow, LightBlue, LightMagenta, LightCyan, White.
Foregrounds | Backgrounds |
---|---|
Log Levels
Available log levels are as follows;
- Trace: 0
- Debug: 1
- Information: 2
- Warning: 3
- Error: 4
- Fatal: 5
Logging Rules
Each logger can write to different sources according to the environment defined configuration. By default the loggers use console for production and development with log level Trace. Each environment can use multiple sources for logging.
const logger = ; const options = rules: production: writeTo: file: level: levelsError folderPath: "C:\\Repositories\\multi-logger\\test\\logs" fileName: "error.txt" size: 1024 minLevel: levelsWarning folderPath: "C:\\Repositories\\multi-logger\\test\\logs" fileName: "warning.txt" size: 1024 mongoDb: minLevel: levelsWarning connectionString: "mongodb://localhost:27017/multi-logger-demo" development: writeTo: console: minLevel: levelsTrace ; const multiLogger = options;multiLogger;
Logging Rules Attributes
level
- Single log level for the matching rule.minLevel
- Minimal log level for the matching rule.folderPath
- Folder path for the matching rule (Applies only if the rule is "file").fileName
- File name for the matching rule (Applies only if the rule is "file").size
- Maximum file size in bayts for the matching rule. Creates a new file if the maximum size is reached (Applies only if the rule is "file").connectionString
- The connection string needed for the matching rule (Applies only if the rule is "mongoDb").
If level and minLevel is defined for the same rule minLevel will be taking to account.