# domain-logger

> Create a simple logger, with domain context for logging

Latest version **0.0.4** (published 2020-12-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install domain-logger
pnpm add domain-logger
yarn add domain-logger
bun add domain-logger
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2020-12-14 |
| First published | 2020-12-11 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 5.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Jon McLean |
| Maintainers | jmclean-cnexus |
| Keywords | logger, winston, microservice, domain-driven-design |

## Links

- npm: https://www.npmjs.com/package/domain-logger
- Repository: https://github.com/carbon-nexus/domain-logger
- Homepage: https://github.com/carbon-nexus/domain-logger#readme
- Issues: https://github.com/carbon-nexus/domain-logger/issues
- npm.io page: https://npm.io/package/domain-logger

## Dependencies (1)

- [winston](https://npm.io/package/winston.md) ^3.3.3

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

- 0.0.4 (latest) — 2020-12-14
- 0.0.3 — 2020-12-11
- 0.0.2 — 2020-12-11
- 0.0.1 — 2020-12-11

## README

<!-- Badges START -->
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](/.github/CODE_OF_CONDUCT.md)
<!-- Badges END -->

# domain-logger
Create a simple logger, with domain context for logging

## Motivation
Creating a logger is a standard practice for any application; in some cases you may want to propagate those logs to a file or even HTTP for other logging solutions (ie Splunk or Elasticsearch) to index for easy searching. 

This module is intended to be lightweight anf focused on Domain Driven Design. In simplest definition, every microservice is bound to a domain/sub-domain. Furthermore, a microservice should have some transaction ID for easy tracking of an entire workflow. With this logger, your can quickly pass in `domain`, `subDomain` and `context` (where context is the transaction ID or whatever makes sense for your microservive). 

If you need to configure an [HTTP](https://github.com/winstonjs/winston/blob/master/docs/transports.md#http-transport) transport, you would do so by supplying Winston arguments to the logger instantiation. A sample is found within the usage section

## Current Support
Winston v3.x

## Installation
```
npm i domain-logger
``` 
or
```
yarn add domain-logger
```

## Usage
Implicit Console transport:

```typescript
let logger = Logger({
    domain: "dom",
    subDomain: "sub",
});
logger.info("This is a test")
```

Explicit HTTP transport (no Console Transport):

```typescript
let logger = Logger({
    domain: "dom",
    subDomain: "sub",
    transports: {
        http: [
            {
                host: "localhost",
                port: 80,
            }    
        ]
    }
});
```

options to be supplied to the logger:

```typescript
interface DomainLoggerOptions {
    domain: string;
    subDomain: string;
    transports?: DomainTransports
    context?: string;
}

interface DomainTransports { 
    console?: ConsoleTransportOptions[],
    file?: FileTransportOptions[],
    stream?: StreamTransportOptions[],
    http?: HttpTransportOptions[]
}
```

### Sample Output 

```
logger.info("This is a test")
// ---------Output---------
//
//  {
//    domain: "dom",
//    level: "info",
//    message: "This is a test",
//    subDomain: "sub"
//  }
```

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