tango-es6-logger
v1.0.8
Published
Simple ES6 JavaScript Logger
Maintainers
Readme
tango-es6-logger
A lightweight, dependency-free logger for Node.js projects built using ES6 modules.
tango-es6-logger provides a minimal, explicit logging API with configurable log levels and output modes (console or file). It is intentionally simple, predictable, and easy to reason about.
✨ Features
Six log levels
TRACE < DEBUG < INFO < WARN < ERROR < FATALProcess-wide log level control
Only messages at or above the configured level are generated.Multiple output modes
- Console
- File
ES6 module support
- Clean
importsyntax - No CommonJS boilerplate
- Clean
Zero runtime dependencies
Colorized console output for improved readability
📦 Installation
npm install tango-es6-logger🚀 Quick Start
import logLevel from 'tango-es6-logger';
import * as logger from 'tango-es6-logger';
logger.setGlobalLogLevel(logLevel.DEBUG);
logger.setLogMode(logger.logMode.CONSOLE);
logger.logIt(logLevel.INFO, 'Application started');🧪 Examples
Example 1 — Log to a File
logger.setGlobalLogLevel(logLevel.TRACE);
logger.setLogMode(logger.logMode.FILE, 'myLogFile.txt');
logger.logIt(logLevel.WARN, 'This message will be written to myLogFile.txt');Example 2 — Log Suppression via Log Level
logger.setGlobalLogLevel(logLevel.ERROR);
logger.setLogMode(logger.logMode.CONSOLE);
logger.logIt(
logLevel.TRACE,
'This message will not be generated because TRACE < ERROR'
);Example 3 — Console Logging
logger.setGlobalLogLevel(logLevel.DEBUG);
logger.setLogMode(logger.logMode.CONSOLE);
logger.logIt(
logLevel.DEBUG,
'This message will appear because DEBUG >= DEBUG'
);🧠 Logging Model
A log message is generated only if:
messageLogLevel >= globalLogLevelThis is not filtering.
Messages below the configured log level are never created, not merely hidden.
📚 Public API
tango-es6-logger exposes:
- 2 enums
- 3 functions
Enums
logLevel (default export)
TRACE | DEBUG | INFO | WARN | ERROR | FATALUsed to:
- Set the configured log level
- Specify the level of individual log messages
logMode
CONSOLE | FILEUsed to define where log messages are written.
Functions
setLogMode(logMode[, filePathAndName])
logger.setLogMode(logger.logMode.CONSOLE);
logger.setLogMode(logger.logMode.FILE, 'logs/app.log');- Sets where log messages are written
- When using
FILE, a file path must be provided - Invalid configurations fail immediately
- Can be called multiple times — the most recent call wins
setGlobalLogLevel(logLevel)
logger.setGlobalLogLevel(logLevel.WARN);- Defines the minimum log level that will be generated
- Can be changed at runtime
- Returns the effective log level that was set
logIt(messageLogLevel, message)
logger.logIt(logLevel.INFO, 'Processing request');- Requests generation of a log entry
- The message is generated only if
messageLogLevel >= globalLogLevel - Returns
trueif the message was generated, otherwisefalse
📌 Defaults
If not explicitly set:
logModedefaults toCONSOLEglobalLogLeveldefaults toTRACE
📥 Importing Notes
Because logLevel is used frequently, it is exported as the default export:
import logLevel from 'tango-es6-logger';
logLevel.WARN;All other exports are named:
import * as logger from 'tango-es6-logger';
logger.setGlobalLogLevel(logLevel.TRACE);
logger.setLogMode(logger.logMode.CONSOLE);
logger.logIt(logLevel.DEBUG, 'Debug message');🕒 Log Output Format
- Each log entry is prefixed with the current date and time (ISO-8601)
- Console output includes foreground and background colors for clarity
Standard Output vs Standard Error
When logMode is set to CONSOLE, log messages are routed to either
standard output (stdout) or standard error (stderr)
based on the log level.
The mapping is intentional and consistent:
| Log Level | Output Stream | |----------|---------------| | TRACE | stdout | | DEBUG | stdout | | INFO | stdout | | WARN | stderr | | ERROR | stderr | | FATAL | stderr |
This behavior aligns with common operational practices in Unix-like environments, containers, CI pipelines, and process supervisors.
It allows informational output to be consumed normally while enabling warnings and errors to be captured, redirected, or filtered independently.
This routing applies only when logMode is set to CONSOLE.
🎯 Design Philosophy
tango-es6-logger is intentionally minimal.
- Explicit configuration over implicit behavior
- Log messages are generated, not filtered
- Predictable, process-wide state
- No global namespace pollution
- No unnecessary abstractions
