# winston-loki-logger

> A Winston transport for Grafana Loki

Latest version **4.0.1** (published 2019-11-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install winston-loki-logger
pnpm add winston-loki-logger
yarn add winston-loki-logger
bun add winston-loki-logger
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 4.0.1 |
| Published | 2019-11-04 |
| First published | 2019-11-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 100.3 KB |
| Known vulnerabilities | 0 (+12 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 170 |
| Author | Jani Anttonen |
| Maintainers | ecoulon |
| Keywords | winston, winston-transport, transport, loki, grafana, logging, plugin, SRE, site reliability engineering, grafana loki |

## Links

- npm: https://www.npmjs.com/package/winston-loki-logger
- Repository: https://github.com/JaniAnttonen/winston-loki
- Homepage: https://github.com/JaniAnttonen/winston-loki#readme
- Issues: https://github.com/JaniAnttonen/winston-loki/issues
- npm.io page: https://npm.io/package/winston-loki-logger

## Dependencies (6)

- [got](https://npm.io/package/got.md) ^9.5.0
- [moment](https://npm.io/package/moment.md) ^2.24.0
- [snappy](https://npm.io/package/snappy.md) ^6.1.1
- [protobufjs](https://npm.io/package/protobufjs.md) ^6.8.8
- [async-exit-hook](https://npm.io/package/async-exit-hook.md) 2.0.1
- [winston-transport](https://npm.io/package/winston-transport.md) ^4.3.0

## Alternatives

- [cli-color](https://npm.io/package/cli-color.md) — 3.4M weekly downloads
- [log](https://npm.io/package/log.md) — 1.3M weekly downloads
- [@luma.gl/experimental](https://npm.io/package/@luma.gl/experimental.md) — 77.1K weekly downloads
- [logstash-client](https://npm.io/package/logstash-client.md) — 4.5K weekly downloads
- [@nocobase/plugin-logger](https://npm.io/package/@nocobase/plugin-logger.md) — 2.0K weekly downloads

## Recent versions

- 4.0.1 (latest) — 2019-11-04

## README

# winston-loki
[![npm version](https://badge.fury.io/js/winston-loki.svg)](https://badge.fury.io/js/winston-loki)
[![Build Status](https://travis-ci.com/JaniAnttonen/winston-loki.svg?branch=master)](https://travis-ci.com/JaniAnttonen/winston-loki)
[![Coverage Status](https://coveralls.io/repos/github/JaniAnttonen/winston-loki/badge.svg?branch=master)](https://coveralls.io/github/JaniAnttonen/winston-loki?branch=master)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)


A Grafana Loki transport for the nodejs logging library Winston.

__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__

## Usage
This Winston transport is used similarly to other Winston transports. Require winston and define a new LokiTransport() inside its options when creating it.

### Options
LokiTransport() takes a Javascript object as an input. These are the options that are available, __required in bold__:

| **Parameter**      | **Description**                                           | **Example**            | **Default**   |
| ------------------ | --------------------------------------------------------- | -----------------------| ------------- |
| __`host`__         | URL for Grafana Loki                                      | http://localhost:3100  | null          |
| `interval`         | The interval at which batched logs are sent in seconds    | 30                     | 5             |
| `json`             | Use JSON instead of Protobuf for transport                | true                   | false         |
| `batching`         | If batching is not used, the logs are sent as they come   | true                   | true          |
| `clearOnError`     | Discard any logs that result in an error during transport | true                   | false         |
| `replaceTimestamp` | Replace any log timestamps with Date.now()                | true                   | false         |

### Example
```js
const { createLogger, transports } = require("winston");
const LokiTransport = require("winston-loki");
const options = {
  ...,
  transports: [
    new LokiTransport({
      host: "http://localhost:3100"
    })
  ]
  ...
};
const logger = createLogger(options);
```

## Developing
```sh
npm install
npm link
cd ~/your_project
npm link winston-loki
npm install
```
And you should have a working, requirable winston-loki package under your project's node_modules.

Refer to https://github.com/grafana/loki/blob/master/docs/api.md for documentation about the available endpoints, data formats etc.

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.

### Run tests
```sh
npm test
```

Write new ones under `/test`

TODO: Remove *got* dependency

---
_Source: https://npm.io/package/winston-loki-logger · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
