Skip to content

base-log-factory

npm package

NPM versionNPM DownloadsTypeScript

🚀 A flexible and simple JS logging library that allows logging or collecting logs in different environments by configuring various Appenders. Suitable for browser, NodeJS and other environments.


🌟 Core Features

  • Multi-level Logging
    Supports TRACE/DEBUG/INFO/WARN/ERROR/FATAL/OFF seven-level logging granularity for precise control over log output.

  • Flexible Appender Configuration
    Built-in ConsoleAppender (console output), FileAppender (size-based rotation), and DateFileAppender (date-based rotation). Supports custom Appender extensions.

  • Rich Log Formatting
    Provides BasicLayout (basic format) and PatternLayout (Log4j-like flexible format). Supports custom placeholders.

  • Context Management
    Supports MDC (Mapped Diagnostic Context) to carry context data like request IDs and user information in logs.


🛠 Core Concepts Explained

1. Logging Levels (with Color Coding)

LevelValueDescriptionRecommended Use Cases
TRACE6Trace-level detailed logsDebugging code logic with detailed flow tracking
DEBUG5Debug informationDebugging outputs during development
INFO4Routine operational infoCritical node records in normal workflow
WARN3Warning eventsNon-fatal but notable issues (e.g., resource shortages)
ERROR2Error eventsRecording failed operations or exceptions
FATAL1Critical failure eventsSystem-critical errors causing crashes
OFF0Disable all loggingDisable logging entirely

2. Appender Type Comparison

TypeFeaturesTypical Use Cases
ConsoleAppenderReal-time output to consoleDevelopment debugging phase
FileAppenderSize-based rotation (e.g., app.log.1)Production environment logging persistence
DateFileAppenderDate-based rotation (e.g., app.2023-08-01.log)Archiving logs by date requirements