1.1.1 • Published 12 months ago

@xeefour/winston-elastic v1.1.1

Weekly downloads
-
License
ISC
Repository
-
Last release
12 months ago

Module Documentation: @xeefour/winston-elastic

Description

The @xeefour/winston-elastic module provides a customizable logger using the Winston library. This logger supports writing logs to daily rotated files and displaying them in the console. It also formats logs according to the Elastic Common Schema (ECS).

Installation

Ensure that you have Node.js installed. Then, install the required dependencies:

npm install @xeefour/winston-elastic

Usage

  1. Import the @xeefour/winston-elastic function from this module.
  2. Call the function with the desired configuration options.
  3. Use the returned logger to log messages.

Example

const winstonLogger = require("@xeefour/winston-elastic");

// Create a logger with custom options
const logger = winstonLogger();

// Or add option
const logger = winstonLogger({
  datePattern: "YYYY-MM-DD-HH",
  maxSize: "20m",
  maxFiles: "14d",
  zippedArchive: true,
  appName: "app",
  level: "info",
  displayLog: true,
  dirname: "logs",
});
// Log an example message
logger.info("Hello, world!");

// Other log levels: logger.error(), logger.warn(), logger.debug(), etc.

Configuration Options

  • datePattern: The pattern for daily rotated log files (default: "YYYY-MM-DD-HH").
  • maxSize: Maximum size of each log file (default: "20m").
  • maxFiles: Maximum number of log files to keep (default: "14d").
  • zippedArchive: Whether to compress old log files (default: true).
  • appName: The name of your application (used as a label in logs default: null).
  • level: The minimum log level to display (default: "info").
  • displayLog: Whether to display logs in the console (default: true).
  • dirname: The directory where log files will be stored (added option).

Log Format

Logs are formatted according to ECS. Each log entry includes a timestamp, log level, and message.

License

This module is released under the MIT License.

1.1.1

12 months ago

1.0.2

12 months ago

1.1.0

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago