Exframe Logger
Exframe Logger is a foundational logging module designed for the Harmony Framework, built on top of the popular Winston logging library. It provides a structured approach to application-level logging, offering standard log levels such as `debug`, `info`, `warn`, and `error`. Currently at version 3.8.7, the package generally follows a stable release cadence with patch updates for bug fixes and minor improvements. Its key differentiator is its integration within the Exframe ecosystem, providing a consistent logging experience for applications leveraging other Exframe modules. Developers looking for a robust, Winston-backed logger within a structured framework context will find it suitable, though it can also be used standalone. It ships with TypeScript types, promoting better developer experience and type safety.
Common errors
-
Error: Cannot find module 'logger'
cause Incorrect package name used in `require()` or `import` statement.fixChange `require('logger')` to `require('exframe-logger')` or `import ... from 'exframe-logger'`. -
TypeError: ExframeLogger.create is not a function
cause The module was imported incorrectly, or `create` is not directly exposed as a method on the default export.fixEnsure you are importing the default export correctly (e.g., `import ExframeLogger from 'exframe-logger'; const logger = ExframeLogger.create();`) or if `create` is a named export, use `import { create } from 'exframe-logger'; const logger = create();`. -
SyntaxError: Cannot use import statement outside a module
cause Attempting to use ES module `import` syntax in a CommonJS context (e.g., in a `.js` file without `"type": "module"` in `package.json` or without `.mjs` extension).fixEither convert your project to use ES Modules by adding `"type": "module"` to your `package.json` and updating file extensions, or use CommonJS `require()` syntax: `const ExframeLogger = require('exframe-logger'); const logger = ExframeLogger.create();`.
Warnings
- gotcha The README example `require("logger")` is misleading. The correct package name for importing is `exframe-logger`. Using `logger` directly will result in a 'module not found' error unless `logger` is a symlink or an alias in your project.
- breaking The package requires Node.js version 14.0.0 or higher. Older Node.js versions will encounter syntax errors or fail to install due to engine restrictions.
- gotcha By default, `exframe-logger` might only log 'info' level and above, depending on its internal Winston configuration. Debug messages may not appear in production or even development environments without explicit configuration.
- gotcha While built on Winston, direct access to underlying Winston transports or advanced configurations might require understanding Exframe Logger's abstraction layer. Don't assume direct Winston API compatibility without consulting documentation.
Install
-
npm install exframe-logger -
yarn add exframe-logger -
pnpm add exframe-logger
Imports
- Logger
const Logger = require("logger").create();import ExframeLogger from 'exframe-logger'; const logger = ExframeLogger.create();
- create
import ExframeLogger from 'exframe-logger'; const logger = ExframeLogger.create(); // not strictly wrong, but potentially less direct if 'create' is a named export
import { create } from 'exframe-logger'; const logger = create(); - ExframeLoggerConfig
import type { ExframeLoggerConfig } from 'exframe-logger';
Quickstart
import ExframeLogger from 'exframe-logger';
// Create a logger instance with default configuration (or pass an object for custom options)
const logger = ExframeLogger.create();
// Log messages at different levels
logger.info('Application started successfully.');
logger.debug('Database connection string: ' + process.env.DB_CONNECTION_STRING ?? 'default_connection');
logger.warn('Potential performance bottleneck detected.', { component: 'auth-service', durationMs: 1200 });
try {
throw new Error('Failed to process user request');
} catch (error) {
logger.error('An unhandled error occurred.', {
errorMessage: error.message,
stack: error.stack,
userId: 'user-123'
});
}