@xeefour/winston-elastic
v1.1.1
Published
The `@xeefour/winston-elastic` module provides a customizable logger using the [Winston](https://github.com/winstonjs/winston) library. This logger supports writing logs to daily rotated files and displaying them in the console. It also formats logs accor
Downloads
7
Readme
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
- Import the
@xeefour/winston-elastic
function from this module. - Call the function with the desired configuration options.
- 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.