# bunyan-mssql-streamer

> bunyan stream for MSSQL with customizable mapping

Latest version **0.14.0** (published 2018-10-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install bunyan-mssql-streamer
pnpm add bunyan-mssql-streamer
yarn add bunyan-mssql-streamer
bun add bunyan-mssql-streamer
```

## 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.14.0 |
| Published | 2018-10-17 |
| First published | 2018-10-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 28 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | Nguyen Viet |
| Maintainers | stereohorse |
| Keywords | bunyan, mssql |

## Links

- npm: https://www.npmjs.com/package/bunyan-mssql-streamer
- npm.io page: https://npm.io/package/bunyan-mssql-streamer

## Dependencies (4)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [mssql](https://npm.io/package/mssql.md) ^4.2.1
- [bunyan](https://npm.io/package/bunyan.md) ^1.8.12
- [source-map-support](https://npm.io/package/source-map-support.md) ^0.5.9

## 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
- [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
- [child-process-debug](https://npm.io/package/child-process-debug.md) — 695 weekly downloads

## Recent versions

- 0.14.0 (latest) — 2018-10-17
- 0.13.1 — 2018-10-15
- 0.13.0 — 2018-10-15
- 0.11.1 — 2018-10-14
- 0.11.0 — 2018-10-14
- 0.10.0 — 2018-10-14
- 0.9.0 — 2018-10-10
- 0.8.0 — 2018-10-10
- 0.7.0 — 2018-10-10
- 0.6.2 — 2018-10-10
- 0.6.1 — 2018-10-10
- 0.6.0 — 2018-10-10
- 0.5.0 — 2018-10-10
- 0.3.0 — 2018-10-10
- 0.2.0 — 2018-10-10

## README

# :floppy_disk: bunyan-mssql-streamer

Exports logs from bunyan logger to MS SQL.
See docs about [bunyan streams](https://github.com/trentm/node-bunyan#streams) for details.

This library wil be used in conjunction with restify's
[requestLogger](http://restify.com/docs/plugins-api/#requestlogger) and
[auditLogger](http://restify.com/docs/plugins-api/#auditlogger)
to log Errors and Requests/Responses to MS SQL.

## Install

```bash
> yarn add bunyan-mssql-streamer
```

## Usage

There are 3 steps of setup

```typescript
// 1. create bunyan logger as usual
const rootLogger = bunyan.createLogger({
    name: "my-logger",
    level: TRACE
});

// 2. create MS SQL Logger
const sqlLogger = new MsSqlLogger({
    rootLogger: rootLogger,
    mssql: {
        server: "localhost",
        database: "dbo",
        user: "sa"
        // etc [1]
    }
});

// 3. add logger stream to root logger
rootLogger.addStream({
    name: "mssql",
    stream: sqlLogger.createMappingStream({
        // ms sql table to store logs
        table: "dbo.Errors",

        // only records with this tag will be logged
        tag: "error",

        // tag will be seached in path "context.tag"
        tagField: "$context.tag",

        // map log records fields to sql table column
        mapping: {
            Exception: "$err.message",
            StackTrace: "$err.stack",
            Level: "ERROR",
            MachineName: log => resolveHost(log.machineIp)
            // etc [2]
        }
    }),
    level: ERROR
});
```

You may add as many streams as you need.
They will use single connection pool to DB.

\[1\]: see [tediousjs/node-mssql](https://github.com/tediousjs/node-mssql#general-same-for-all-drivers) for MS SQL configs

\[2\]: specify mapping as `"table column name": "log record path spec"`.
If path spec begins with `$`, it will be treated as JSON path.
You may also use a function as source field in mapping. That function will receive log record as first argument.

## Dev workflows

### Run tests

Fast tests

```bash
> yarn unittest
```

Slow tests

```bash
> yarn integtest
```

All tests

```bash
> yarn test
```

### Release new version

```bash
> yarn release
```

This command will

1. increment version in `package.json`
2. generate `CHANGELOG.md`
3. commit that chages with tag

See [standard-version](https://github.com/conventional-changelog/standard-version) for details.

### Publish to NPM

```bash
> npm publish
```

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