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** |
|
17 | | ---------------- | --------------------------------------------------------- | -------------------------------- |
|
18 | | __`host`__ | URL for Grafana Loki | http://localhost:3100 |
|
19 | | `interval` | The interval at which batched logs are sent in seconds | 30 |
|
20 | | `json` | Use JSON instead of Protobuf for transport | true |
|
21 | | `batching` | If batching is not used, the logs are sent as they come | true |
|
22 | | `clearOnError` | Discard any logs that result in an error during transport | true |
|
23 |
|
24 | ### Example
|
25 | ```js
|
26 | const { createLogger, transports } = require("winston");
|
27 | const LokiTransport = require("winston-loki");
|
28 | const options = {
|
29 | ...,
|
30 | transports: [
|
31 | new LokiTransport({
|
32 | host: "http://localhost:3100"
|
33 | })
|
34 | ]
|
35 | ...
|
36 | };
|
37 | const logger = createLogger(options);
|
38 | ```
|
39 |
|
40 | ## Developing
|
41 | ```sh
|
42 | npm install
|
43 | npm link
|
44 | cd ~/your_project
|
45 | npm link winston-loki
|
46 | npm install
|
47 | ```
|
48 | And you should have a working, requirable winston-loki package under your project's node_modules.
|
49 |
|
50 | Refer to https://github.com/grafana/loki/blob/master/docs/api.md for documentation about the available endpoints, data formats etc.
|
51 |
|
52 | 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.
|
53 |
|
54 | ### Run tests
|
55 | ```sh
|
56 | npm test
|
57 | ```
|
58 |
|
59 | Write new ones under `/test`
|
60 |
|
61 | TODO: Remove *got* dependency
|