Registry / observability / simple-node-logger

simple-node-logger

JSON →
library21.8.12jsnpmunverified

Simple Node Logger is a multi-level logging library for Node.js, providing robust support for console, file, and rolling file appenders. Currently at version 21.8.12, it offers flexible configuration options including custom timestamp formats, dynamic log level changes (trace, debug, info, warn, error, fatal), and the ability to integrate with process error events. Its key differentiators include a modular log manager for creating multiple loggers and appenders, support for domain and category columns in logs, and built-in statistics tracking for log statements. The library is designed for ease of use in small to large production environments, focusing on core logging functionalities without excessive complexity, and ships with TypeScript definitions for improved developer experience. While the documentation primarily shows CommonJS `require` patterns, it includes type definitions, suggesting compatibility with modern TypeScript setups.

npm install simple-node-logger
INSTALL
IMPORT
SIG · SIMPLE-NODE-LOGGER
S
simple-node-logger
observabilityjavascriptv21.8.12
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createSimpleLogger
const log = require('simple-node-logger').createSimpleLogger();
import { createSimpleLogger } from 'simple-node-logger';
The package is CommonJS (`type: "commonjs"`). Direct named ESM imports might not work without esModuleInterop or a bundler. For TypeScript, use `import SimpleNodeLogger = require('simple-node-logger');` then `SimpleNodeLogger.createSimpleLogger();` or enable `esModuleInterop` in tsconfig.json to allow `import { createSimpleLogger } from 'simple-node-logger';`.
SimpleNodeLogger (full module)
const SimpleNodeLogger = require('simple-node-logger'); const log = SimpleNodeLogger.createSimpleLogger();
import SimpleNodeLogger from 'simple-node-logger';
This imports the entire module object in CommonJS. In ESM, `import * as SimpleNodeLogger from 'simple-node-logger';` would be the equivalent, though the default export is not the primary API.
createRollingFileLogger
const { createRollingFileLogger } = require('simple-node-logger');
import { createRollingFileLogger } from 'simple-node-logger';
Direct destructuring of named exports from a CommonJS `require` is common. For TypeScript, if `esModuleInterop` is enabled, `import { createRollingFileLogger } from 'simple-node-logger';` might work, otherwise use the full module import pattern.

Demonstrates setting up a rolling file logger with a custom timestamp format, setting the log level at runtime, and logging messages at various levels.

import * as simpleNodeLogger from 'simple-node-logger'; const opts = { logFilePath: 'my_application.log', timestampFormat: 'YYYY-MM-DD HH:mm:ss.SSS', logDirectory: './logs', // Ensure this directory exists fileNamePattern: 'roll-<DATE>.log', dateFormat: 'YYYY.MM.DD' }; // Create a custom logger with a rolling file appender and custom timestamp const log = simpleNodeLogger.createRollingFileLogger(opts); // Set log level to 'info' at runtime log.setLevel('info'); log.trace('This is a trace message.'); log.debug('This is a debug message.'); log.info('Application started at %s', new Date().toISOString()); log.warn('A non-critical warning occurred.'); log.error('An error happened: %o', new Error('Something went wrong')); log.fatal('Application encountered a fatal error, shutting down.');
Debug
Known issues
gotchaWhen using file appenders (e.g., `createSimpleFileLogger` or `createRollingFileLogger`), the specified `logDirectory` or path for `logFilePath` must exist and be writable by the Node.js process. The library does not automatically create missing directories.
fix
Ensure the target log directory exists before initializing the logger, e.g., `require('fs').mkdirSync('./logs', { recursive: true });`
affects: >=1.0.0
gotchaThe package is primarily CommonJS (`type: "commonjs"` in package.json). While it ships TypeScript types, direct named ESM `import { ... } from 'simple-node-logger';` statements might require specific `tsconfig.json` settings (`esModuleInterop: true`) or a bundler to resolve correctly in an ESM environment. Otherwise, use `import * as SimpleNodeLogger from 'simple-node-logger';` or CommonJS `require` syntax.
fix
For TypeScript projects, set `"esModuleInterop": true` in `tsconfig.json` or use `import SimpleNodeLogger = require('simple-node-logger');` for CommonJS-style imports. For pure ESM environments, `import * as SimpleNodeLogger from 'simple-node-logger';` may be necessary.
affects: >=1.0.0
gotchaChanging the log level dynamically using `log.setLevel('level')` affects that specific logger instance. If multiple loggers are created or if appenders are configured independently, ensure the level is set on the correct logger or manager instance.
fix
Verify that `setLevel` is called on the intended logger instance (e.g., `log.setLevel('warn')`) or on the `LogManager` if managing multiple loggers centrally.
affects: >=1.0.0
Errors
Common errors & fixes
Error: EACCES: permission denied, open '/path/to/log/file.log'
The Node.js process does not have sufficient write permissions to the specified log file or directory.
fix
Grant write permissions to the user running the Node.js process for the log directory, or change the `logDirectory`/`logFilePath` to a writable location. On Linux/macOS, use `chmod -R 775 /path/to/log`.
Error: ENOENT: no such file or directory, open '/path/to/nonexistent/directory/file.log'
The `logDirectory` or parent directory for `logFilePath` specified in the logger options does not exist.
fix
Create the log directory before initializing the logger. Example: `require('fs').mkdirSync('/path/to/nonexistent/directory', { recursive: true });`
TypeError: simple_node_logger_1.createSimpleLogger is not a function
This typically occurs in TypeScript/ESM projects when `import { createSimpleLogger } from 'simple-node-logger';` is used without `esModuleInterop: true` in `tsconfig.json` for a CommonJS module, or when directly trying to destructure a CJS module as if it were an ESM module.
fix
Enable `esModuleInterop: true` in `tsconfig.json`. Alternatively, use `import * as SimpleNodeLogger from 'simple-node-logger';` and then `SimpleNodeLogger.createSimpleLogger();`, or stick to the CommonJS `const { createSimpleLogger } = require('simple-node-logger');` if not in a pure ESM environment.
Upgrade
Version history
21.8.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
2
Resources
simple-node-logger — npm install simple-node-logger · libregistry