@glowing-fishstick/logger
v0.2.0
Published
Winston-based structured logging module for glowing-fishstick applications
Downloads
17
Maintainers
Readme
@glowing-fishstick/logger
Winston-based structured logging module for glowing-fishstick applications. Provides a configured Winston logger with dev/prod modes and an Express request-logging middleware. All exports use native Winston call signature: logger.info(message, meta).
Install
npm install @glowing-fishstick/loggerNo additional peer dependencies are required. winston is bundled as a runtime dependency.
Exports
| Export | Description |
| --------------------- | -------------------------------------------------------------------------------------- |
| createLogger | Creates a Winston logger with dev/prod modes; optional JSON file transport, redaction. |
| createRequestLogger | Express middleware for structured request/response logging with request ID tracking. |
Configuration
createLogger(options?)
Creates a configured Winston logger instance.
Options (LoggerOptions):
| Property | Type | Default | Description |
| ------------ | --------------------- | --------------------------------- | -------------------------------------------------------------------------------------------------------- |
| name | string | 'app' | Logger name (emitted as name in meta; also used for file naming). |
| level | string | 'info' (or LOG_LEVEL env var) | Minimum log level: error | warn | info | http | verbose | debug | silly. |
| logDir | string | process.cwd()/logs | Directory for log files (only when enableFile is true). |
| enableFile | boolean | false | Enable JSON file transport in non-production mode. |
| redact | string[] | [] | Dotted paths inside meta to mask with '[REDACTED]' (e.g. ['req.headers.authorization', 'password']). |
| transports | winston.transport[] | (none) | Override transports entirely. When provided, Console/File defaults are NOT constructed. Tests use this. |
Returns: Winston Logger instance.
- Development (
NODE_ENV !== 'production'): colorized printf console output. WhenenableFile=true, a JSON file transport is also added at<logDir>/<name>.log. - Production: JSON to stdout only (for container log collectors).
- Test (
NODE_ENV='test'): colorize is disabled to keep test output clean.
createRequestLogger(logger, options?)
Creates an Express middleware for request/response logging.
Arguments:
logger— Winston logger instance (fromcreateLogger()).options(RequestLoggerOptions):generateRequestId(boolean, defaulttrue) — Auto-generate UUIDs; also reads fromx-request-idheader.
Returns: Express RequestHandler middleware that logs incoming requests and outgoing responses with timing, status, and request ID.
Usage
Application logger
import { createLogger } from '@glowing-fishstick/logger';
const logger = createLogger({ name: 'my-api', level: 'info' });
logger.info('Server starting');
logger.error('Something went wrong', { err });In development, logs are colorized and printed to stdout. In production (NODE_ENV=production), JSON is written to stdout only.
Redaction
const logger = createLogger({
name: 'my-api',
redact: ['req.headers.authorization', 'password'],
});
logger.info('login attempt', { req: { headers: { authorization: 'Bearer abc' } } });
// → req.headers.authorization is replaced with '[REDACTED]'Custom transports (tests)
import winston from 'winston';
import { createLogger } from '@glowing-fishstick/logger';
const logger = createLogger({
name: 'test',
transports: [new winston.transports.Console({ silent: true })],
});Express request middleware
import express from 'express';
import { createLogger, createRequestLogger } from '@glowing-fishstick/logger';
const logger = createLogger({ name: 'my-api' });
const app = express();
app.use(createRequestLogger(logger));Each request logs method, path, and response status with duration. Request IDs are read from x-request-id or auto-generated.
License
MIT
