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 |
|
8 | A Grafana Loki transport for the nodejs logging library Winston.
|
9 |
|
10 | __NOTE: Latest version only guaranteed to work with the latest version of Grafana Loki. Make sure to update Loki if you have updated this package__
|
11 |
|
12 | ## Usage
|
13 | This Winston transport is used similarly to other Winston transports. Require winston and define a new LokiTransport() inside its options when creating it.
|
14 |
|
15 | ### Options
|
16 | LokiTransport() takes a Javascript object as an input. These are the options that are available, __required in bold__:
|
17 |
|
18 | | **Parameter** | **Description** | **Example** | **Default** |
|
19 | | ------------------ | --------------------------------------------------------- | -----------------------| ------------- |
|
20 | | __`host`__ | URL for Grafana Loki | http://localhost:3100 | null |
|
21 | | `interval` | The interval at which batched logs are sent in seconds | 30 | 5 |
|
22 | | `json` | Use JSON instead of Protobuf for transport | true | false |
|
23 | | `batching` | If batching is not used, the logs are sent as they come | true | true |
|
24 | | `clearOnError` | Discard any logs that result in an error during transport | true | false |
|
25 | | `replaceTimestamp` | Replace any log timestamps with Date.now() | true | false |
|
26 |
|
27 | ### Example
|
28 | ```js
|
29 | const { createLogger, transports } = require("winston");
|
30 | const LokiTransport = require("winston-loki");
|
31 | const options = {
|
32 | ...,
|
33 | transports: [
|
34 | new LokiTransport({
|
35 | host: "http://localhost:3100"
|
36 | })
|
37 | ]
|
38 | ...
|
39 | };
|
40 | const logger = createLogger(options);
|
41 | ```
|
42 |
|
43 | ## Developing
|
44 | ```sh
|
45 | npm install
|
46 | npm link
|
47 | cd ~/your_project
|
48 | npm link winston-loki
|
49 | npm install
|
50 | ```
|
51 | And you should have a working, requirable winston-loki package under your project's node_modules.
|
52 |
|
53 | Refer to https://github.com/grafana/loki/blob/master/docs/api.md for documentation about the available endpoints, data formats etc.
|
54 |
|
55 | Grafana 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.
|
56 |
|
57 | ### Run tests
|
58 | ```sh
|
59 | npm test
|
60 | ```
|
61 |
|
62 | Write new ones under `/test`
|
63 |
|
64 | TODO: Remove *got* dependency
|