UNPKG

2.89 kBMarkdownView Raw
1# winston-loki
2[![npm version](https://badge.fury.io/js/winston-loki.svg)](https://badge.fury.io/js/winston-loki)
3[![Build Status](https://travis-ci.com/JaniAnttonen/winston-loki.svg?branch=master)](https://travis-ci.com/JaniAnttonen/winston-loki)
4[![Coverage Status](https://coveralls.io/repos/github/JaniAnttonen/winston-loki/badge.svg?branch=master)](https://coveralls.io/github/JaniAnttonen/winston-loki?branch=master)
5[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
6
7
8A Grafana Loki transport for the nodejs logging library Winston.
9
10## Usage
11This Winston transport is used similarly to other Winston transports. Require winston and define a new LokiTransport() inside its options when creating it.
12
13### Options
14LokiTransport() takes a Javascript object as an input. These are the options that are available, __required in bold__:
15
16| **Parameter** | **Description** | **Example** | **Default** |
17| ------------------ | --------------------------------------------------------- | -----------------------| ------------- |
18| __`host`__ | URL for Grafana Loki | http://localhost:3100 | null |
19| `interval` | The interval at which batched logs are sent in seconds | 30 | 5 |
20| `json` | Use JSON instead of Protobuf for transport | true | false |
21| `batching` | If batching is not used, the logs are sent as they come | true | true |
22| `clearOnError` | Discard any logs that result in an error during transport | true | false |
23| `replaceOnError` | Replace timestamps and retry on error | true | false |
24| `replaceTimestamp` | Replace any log timestamps with Date.now() | true | false |
25
26### Example
27```js
28const { createLogger, transports } = require("winston");
29const LokiTransport = require("winston-loki");
30const options = {
31 ...,
32 transports: [
33 new LokiTransport({
34 host: "http://localhost:3100"
35 })
36 ]
37 ...
38};
39const logger = createLogger(options);
40```
41
42## Developing
43```sh
44npm install
45npm link
46cd ~/your_project
47npm link winston-loki
48npm install
49```
50And you should have a working, requirable winston-loki package under your project's node_modules.
51
52Refer to https://github.com/grafana/loki/blob/master/docs/api.md for documentation about the available endpoints, data formats etc.
53
54Grafana Loki *doesn't have any official releases or version numbers* as of now, so if the API is changed, it's going to be fun, but it's working as of now.
55
56### Run tests
57```sh
58npm test
59```
60
61Write new ones under `/test`
62
63TODO: Remove *got* dependency