# winston-logger-kafka

> Winston based logger with Kafka transport

Latest version **0.1.2** (published 2022-12-10) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2022-12-10 |
| First published | 2021-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 9 |
| Unpacked size | 16.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Dmitry Amanov |
| Maintainers | doctor3030 |

## Links

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

## Dependencies (9)

- [uuid](https://npm.io/package/uuid.md) ^8.3.2
- [kafkajs](https://npm.io/package/kafkajs.md) ^1.15.0
- [logform](https://npm.io/package/logform.md) ^2.4.2
- [ts-node](https://npm.io/package/ts-node.md) ^10.4.0
- [winston](https://npm.io/package/winston.md) ^3.3.3
- [typescript](https://npm.io/package/typescript.md) ^4.5.4
- [@types/node](https://npm.io/package/@types/node.md) ^17.0.0
- [@types/uuid](https://npm.io/package/@types/uuid.md) ^8.3.3
- [winston-daily-rotate-file](https://npm.io/package/winston-daily-rotate-file.md) ^4.5.5

## Recent versions

- 0.1.2 (latest) — 2022-12-10
- 0.1.1 — 2022-12-10
- 0.1.0 — 2022-12-10
- 0.0.13 — 2022-10-07
- 0.0.12 — 2022-04-13
- 0.0.11 — 2022-04-06
- 0.0.10 — 2022-01-02
- 0.0.9 — 2021-12-26
- 0.0.8 — 2021-12-24
- 0.0.7 — 2021-12-24
- 0.0.6 — 2021-12-24
- 0.0.5 — 2021-12-24
- 0.0.4 — 2021-12-24
- 0.0.3 — 2021-12-24
- 0.0.2 — 2021-12-24
- … 1 more at https://npm.io/package/winston-logger-kafka/versions

## README

# Simple winston-based logger with Kafka transport

This logger is a simple wrap around [winston](https://www.npmjs.com/package/winston). There are standard winston transports plus [daily rotate file](https://www.npmjs.com/package/winston-daily-rotate-file) and [Kafka](https://www.npmjs.com/package/kafkajs) transports.
The Kafka transport is built around [kafkajs](https://www.npmjs.com/package/kafkajs).
> **_NOTE:_**  Transports are called Sinks in this module.
## Installation

```
npm install winston-logger-kafka
```

## Usage
First, you must supply a basic properties for the logger:
- **module:** A name of your service.
- **component:** A name of your service component.
- **level:** A log level.

### getDefaultLogger() method
The quickest way to create logger is to use **getDefaultLogger** method that returns a winston logger with console transport:
```typescript
import * as Logger from "winston-logger-kafka";

const config: Logger.LoggerConfig = {
    level: Logger.Levels.INFO
};

const logger = Logger.getDefaultLogger(config);

logger.info('Hello!')
```

### getLogger() method
Use this method to create logger with custom transports:

```typescript
import * as Logger from "winston-logger-kafka";

const config: Logger.LoggerConfig = {
    level: Logger.Levels.INFO
};

const sinks = [
    new Logger.ConsoleSink,
    new Logger.FileSink({
        filename: './logs/%DATE%_log_file.log',
        datePattern: 'YYYY-MM-DD-HH',
        zippedArchive: false,
        maxSize: '20m',
        frequency: '14d',
    }),
    new Logger.KafkaSink({
        clientConfig: {brockers: ['localhost:9092']},
        producerConfig: { allowAutoTopicCreation: false },
        sinkTopic: 'test_topic',
    })
]

const logger = Logger.getLogger(config, sinks);

logger.info('Hello!')
```
> **_NOTE:_**  Standard sink options are the same as options of corresponding winston transport.

## Use standalone kafka transport
You can also use kafka transport with pure winston:
```typescript
import {KafkaTransport, KafkaTransportConfig} from "winston-logger-kafka";

const kafka_transport_conf = {
    clientConfig: {brockers: ['localhost:9092']},
    producerConfig: { allowAutoTopicCreation: false },
    sinkTopic: 'test_topic',
}

const logger = winston.createLogger({
    level: 'info',
    format: winston.format.json(),
    defaultMeta: { service: 'user-service' },
    transports: [
        new winston.transports.File({ filename: 'error.log', level: 'error' }),
        new KafkaTransport(kafka_transport_conf)
    ],
});
```

## getChildLogger method
Get logger for a child class:
```typescript

const childLoggerConf = {
    level: Logger.Levels.INFO
};

const childLogger = Logger.getChildLogger(parentlogger, childLoggerConf);
```

## LICENSE
MIT

##### AUTHOR: [Dmitry Amanov](https://github.com/doctor3030)

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