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:
|
15 |
|
16 | >`host`
|
17 |
|
18 | The URL of the Grafana Loki server.
|
19 | It should contain everything from the protocol to the port.
|
20 |
|
21 | >`interval`
|
22 |
|
23 | *optional*
|
24 |
|
25 | The interval at which the transport sends batched logs to Loki. **In seconds.**
|
26 |
|
27 | >`json`
|
28 |
|
29 | *optional*
|
30 |
|
31 | Switch to JSON transport instead of Protobuf.
|
32 |
|
33 | ### Example
|
34 | ```js
|
35 | const { createLogger, transports } = require("winston");
|
36 | const LokiTransport = require("winston-loki");
|
37 | const options = {
|
38 | ...,
|
39 | transports: [
|
40 | new LokiTransport({
|
41 | host: "http://localhost:3100"
|
42 | })
|
43 | ]
|
44 | ...
|
45 | };
|
46 | const logger = createLogger(options);
|
47 | ```
|
48 |
|
49 | ## Developing
|
50 | ```sh
|
51 | npm install
|
52 | npm link
|
53 | cd ~/your_project
|
54 | npm link winston-loki
|
55 | npm install
|
56 | ```
|
57 | And you should have a working, requirable winston-loki package under your project's node_modules.
|
58 |
|
59 | Refer to https://github.com/grafana/loki/blob/master/docs/api.md for documentation about the available endpoints, data formats etc.
|
60 |
|
61 | 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.
|
62 |
|
63 | ### Run tests
|
64 | ```sh
|
65 | npm test
|
66 | ```
|
67 |
|
68 | Write new ones under `/test`
|
69 |
|
70 | TODO: Remove *got* dependency
|