1.0.0 • Published 2 years ago

winston-simple-logger v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

winston-simple-logger

A simple and convenient wrapper around Winston to simplify the repetitive tasks of setting up logs, formatters and transports.

It also includes a simple API to read back the logs.

How to use

let loggerOpts = {    
	overwriteConsole: true,    
	rotateLogs: true,
	logsDir: "/path/to/logs-dir",
	dateFormat: 'YYYY-MM-DD',
	maxFiles: '30D',
	fileTransports: [
		{
			filename: 'error.log',
			level: 'error',
		},
		{
			filename:'info.log',
			level: 'info',
		},
	],
};
const logger = require('morgan-simple-logger')(loggerOpts);

Options

  • overwriteConsole: If set to true, all console.logs are converted into morgan logs. In short, console.log is monkey patched.

  • rotateLogs: this enables log rotation with default 'maxFiles' value of '14d'. Note: This option only works when fileTransports is also set.

  • logsDir: Directory in which to save your logs. If not set, it defaults to require.main.path.

  • dateFormat: The date pattern to use during log rotation. Note: This option only works when fileTransports and rotateLogs are also set.

  • maxFiles: Ensures that log files that are older than 14 days are automatically deleted.

  • fileTransports: an array of the various file transports to use. These need only indicate two fields; filename and level. The wrapper automagically formats the file names and wraps with the right winston file transports for you.