Repository navigation
Releases
Releases · Abadima/Logena
The Fools' Update
Added
- All log levels now accept an optional
appNameparameter to override the preset application name for that specific log level call. - Color palette expansion: Added 32 new extended ANSI 256-color variants (light/dark shades, semantic colors like
success,failure,warning,info,debug,accent). - Package exports map: Explicit
exportsfield inpackage.jsonfor clearer ESM/CommonJS resolution. - Automated regression test suite: New
tests/directory with comprehensive edge-case coverage for robustness validation. - Optional ASCII kitty meow on errors: Added
meowOnErrorconfig and optionalerrorCatAsciioverride. - Variadic log arguments:
Logena.info/warn/error/debugnow support multiple values in one call (e.g.,Logena.info("x", { a: 1 }, 123, true)). - Broader object/value support: Logging methods now accept object-first and mixed-type payloads directly.
minLevel?: LevelNameadded toset()config. Accepted values:"debug"(default, logs everything),"info","warn","error". Levels below the threshold are suppressed before any argument parsing or formatting.noColor?: booleanadded toset()config. Whentrue, all ANSI escape codes are stripped from every output field (timestamp, appName bracket, level label, message). Ideal for CI pipelines, file sinks, or any consumer that interprets raw bytes.serializeObjects?: booleanadded toset()config. Whenfalse, non-string non-Error values emit type shorthands:[Object],[Array],"null", orString(value). Zero JSON parse cost — safe for high-throughput paths where object shape is irrelevant.LevelNametype exported: Consumers can importimport type { LevelName } from "logena"for typedminLevelarguments.
Fixed
- Partial colors config crash: Guard undefined spread in
set()method whencolors.levelsis not provided; now safely merges partial color configurations. - Unsafe color key fallback: All color lookups (timestamp, appName, message, levels) now safely fallback to valid defaults when keys are missing or invalid.
- JSON stringify circular reference crash: Wrap object serialization in try/catch; gracefully fallback to
String(message)for circular or non-serializable payloads. - Build dependency mismatch: Added missing ESLint TypeScript parser/plugin dev dependencies used by
eslint.config.mjs. - Test script reliability:
npm testnow runs JS regression tests directly fromtests/edge-cases.js. - Error-aware
stringifyPart():instanceof Erroris checked beforeserializeObjectsand beforeJSON.stringify. The full stack trace (which already contains the message) is emitted directly —JSON.stringifyon an Error produces{}, which was silently wrong.
Performance
- Prefix cache:
rebuildCache()precomputes the full ANSI-colored[ AppName ] LEVEL:prefix for all four levels onset()and class initialisation.formatMessagenow performs zero color lookups per call — average latency dropped ~43% (561 ns → 319 ns across benchmark rounds). - Timestamp formatting: Replaced two regex operations (
replace("T", " ")+/\..+/) with a fixed-lengthiso.slice()— zero allocations, O(1). - Early debug guard:
debug()bails out before any argument parsing whendebugModeis false, producing zero allocations for disabled debug logs. - Compact JSON serialisation:
JSON.stringify(part)replacesJSON.stringify(part, null, 2)instringifyPart— faster serialisation and less memory. - In-place color mutation in
set(): Replaced a 3-object spread (colors + levels + intermediate) with targeted property assignments;rebuildCache()is called once afterward. - Per-second timestamp cache:
_formatTimestamp()now stores the formatted string and an integer second counter.Math.floor(Date.now() / 1000)(~50 ns) gates a ~1 500 nsnew Date().toISOString()call, yielding a large net saving during same-second log bursts. The cache is invalidated exactly once per wall-clock second. - Eliminated
.toLowerCase()in hot path:formatMessageparameter is now typed"info" | "warn" | "error" | "debug"and each log method passes the lowercase literal directly. Removes one string allocation per log call. - Cached ANSI reset code (
_reset):rebuildCache()storesterminalColors.reset(or""in noColor mode) into_reset.formatMessageand_formatTimestampread this field instead of the module-level constant, making the noColor branch branch-free at log time. - Numeric
minLevelfiltering: Integer comparison (LEVEL_MAP[level] < this.minLevel) added beforeparseLogArguments. Zero cost when default (minLevel = 0); silences entire level bands with a single branch that V8 can predict perfectly.
Changed
- README examples: Updated documentation to clearly show TypeScript default import, named import, and CommonJS require patterns all working correctly.
- Logger resilience: Lenient fallback behavior for invalid color values — logging continues gracefully instead of breaking on misconfiguration.
- README features and set() docs: Documented optional kitty meow behavior and config options.
- Internal cleanup: Removed temporary
// LOGENA-FIX:inline comments after stabilizing fixes.
Internals
noColorinrebuildCache(): WhennoColoris true,rebuildCachetakes an early-exit path that writes plain-text prefix strings and sets_reset = "". This ensuresformatMessagenever branches on noColor at runtime.- New static fields:
_reset,_cachedTimestamp,_cachedTimestampSec,minLevel,noColor,serializeObjects. All initialized at class declaration with safe defaults.
Full Changelog: v1.0.2...v1.1.0
First (Working) Release
Changed:
- Class name from
LoggertoLogena. logger.jsfrom/distto project root.package.jsonto reflect changes.- Minimum NodeJS version to
14.0.0, let's be fr, we don't need to be that strict.
Fixed:
- Class methods, now they're actually accessible from the class instance.
Full Changelog: v1.0.0...v1.0.2
First Release
Added
- Initial release of the
Loggerclass. - Added
terminalColorsobject for terminal text styling. - Implemented
Loggerclass with the following methods:set(config: { debug?: boolean, appName?: string, useTimestamps?: boolean, colors?: { timestamp?: keyof typeof terminalColors.textColors, appName?: keyof typeof terminalColors.textColors, message?: keyof typeof terminalColors.textColors, levels?: { info?: keyof typeof terminalColors.textColors, warn?: keyof typeof terminalColors.textColors, error?: keyof typeof terminalColors.textColors, debug?: keyof typeof terminalColors.textColors } } }): void- Configure the logger settings.info(message: string | object): void- Log an info message to the console.warn(message: string | object): void- Log a warning to the console.error(message: string | object): void- Log an error to the console.debug(message: string | object): void- Log a debug message to the console (only ifdebugModeis enabled).
Full Changelog: https://github.com/Abadima/Logena/commits/v1.0.0