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 | ## Usage
|
11 | This 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
|
14 | LokiTransport() 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 | | `replaceTimestamp` | Replace any log timestamps with Date.now() | true | false |
|
24 |
|
25 | ### Example
|
26 | ```js
|
27 | const { createLogger, transports } = require("winston");
|
28 | const LokiTransport = require("winston-loki");
|
29 | const options = {
|
30 | ...,
|
31 | transports: [
|
32 | new LokiTransport({
|
33 | host: "http://localhost:3100"
|
34 | })
|
35 | ]
|
36 | ...
|
37 | };
|
38 | const logger = createLogger(options);
|
39 | ```
|
40 |
|
41 | ## Developing
|
42 | ```sh
|
43 | npm install
|
44 | npm link
|
45 | cd ~/your_project
|
46 | npm link winston-loki
|
47 | npm install
|
48 | ```
|
49 | And you should have a working, requirable winston-loki package under your project's node_modules.
|
50 |
|
51 | Refer to https://github.com/grafana/loki/blob/master/docs/api.md for documentation about the available endpoints, data formats etc.
|
52 |
|
53 | 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.
|
54 |
|
55 | ### Run tests
|
56 | ```sh
|
57 | npm test
|
58 | ```
|
59 |
|
60 | Write new ones under `/test`
|
61 |
|
62 | TODO: Remove *got* dependency
|