winston-array-transport
v1.1.11
Published
write logs to js Array
Downloads
128,813
Maintainers
Readme
winston-array-transport
write winston logs directly to javascript Array.
🇺🇦 Help Ukraine
I woke up on my 26th birthday at 5 am from the blows of russian missiles. They attacked the city of Kyiv, where I live, as well as the cities in which my family and friends live. Now my country is a war zone.
We fight for democratic values, freedom, for our future! Once again Ukrainians have to stand against evil, terror, against genocide. The outcome of this war will determine what path human history is taking from now on.
💛💙 Help Ukraine! We need your support! There are dozen ways to help us, just do it!
Table of Contents
Motivation
There are a lot of cases where you need to parse and analyze your logs. For example, to access them during tests. This package provides transport that allows simply push logs to js array, so you don't need any runtime parsers anymore.
Requirements
To use library you need to have node and npm installed in your machine:
- node
>=10
- npm
>=6
Package is continuously tested on darwin, linux and win32 platforms. All active and maintenance LTS node releases are supported.
Installation
To install the library run the following command
npm i --save winston-array-transport
Usage
The package can be used alongside any other winston transport.
import ArrayTransport from 'winston-array-transport';
import { createLogger } from 'winston';
const logs = [];
const transport = new ArrayTransport({ array: logs, json: true, level: 'info' });
export const logger = createLogger({
transports : [ transport ]
});
Configuration
Next options can be configured while transport creation:
- name - name of a transport,
ArrayTransport
by default; - eol - end of line ,
os.EOL
by default; - array - array, where all logs will be stored;
- parser - function, that will be applied to log messages;
- json - if set to
true
,JSON.parse
parser will be used; - limit - allows to limit amount of logs to
n
last items;
Contribute
Make the changes to the code and tests. Then commit to your branch. Be sure to follow the commit message conventions. Read Contributing Guidelines for details.