# binder-logging

> Module for consistent logging across Binder components

Latest version **1.0.3** (published 2016-04-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install binder-logging
pnpm add binder-logging
yarn add binder-logging
bun add binder-logging
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2016-04-25 |
| First published | 2016-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 14 |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | yes |
| Author | Andrew Osheroff |
| Maintainers | andrewosh |
| Keywords | binder, logging |

## Links

- npm: https://www.npmjs.com/package/binder-logging
- Repository: https://github.com/binder-project/binder-logging
- Issues: https://github.com/binder-project/binder-logging/issues
- npm.io page: https://npm.io/package/binder-logging

## Dependencies (14)

- [brfs](https://npm.io/package/brfs.md) ^1.4.3
- [pump](https://npm.io/package/pump.md) ^1.0.1
- [lodash](https://npm.io/package/lodash.md) ^4.0.0
- [pumpify](https://npm.io/package/pumpify.md) ^1.3.3
- [request](https://npm.io/package/request.md) ^2.67.0
- [winston](https://npm.io/package/winston.md) ^2.1.1
- [fs-extra](https://npm.io/package/fs-extra.md) ^0.26.5
- [websocket](https://npm.io/package/websocket.md) ^1.0.22
- [event-stream](https://npm.io/package/event-stream.md) ^3.3.2
- [elasticsearch](https://npm.io/package/elasticsearch.md) ^10.1.2
- [object-assign](https://npm.io/package/object-assign.md) ^4.0.1
- [nodejs-websocket](https://npm.io/package/nodejs-websocket.md) ^1.5.0
- [socket.io-client](https://npm.io/package/socket.io-client.md) ^1.4.4
- [winston-logstash](https://npm.io/package/winston-logstash.md) ^0.2.11

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

- 1.0.3 (latest) — 2016-04-25
- 1.0.2 — 2016-04-25
- 1.0.1 — 2016-04-21
- 1.0.0 — 2016-03-25

## README

# binder-logging
Consistent logging reader/writer functions for all Node-based Binder modules

Takes a configuration file (the default version in `conf/example.main`) that specifies how to
 1. connect to a Logstash server for log writing
 2. connect to Elasticsearch/Kibana servers for log reading
 3. stream build logs from a websocket

The example configuration file included in the module has these defaults:
```
{
  "host": "localhost",
  "testing": true,
  "logstash": {
    "port": 8050,
    "configDir": "~/binder-control/services/logging/logstash/"
  },

  "elasticsearch": {
    "port": 8052,
    "dir": "/data/binder/elasticsearch"
  },

  "kibana": {
    "port": 8053
  },

  "streaming": {
    "port": 2121
  }
}
```
`binder-control` can launch Docker containers for Elasticsearch, Logstash and Kibana (with the same default values) through the `binder-control start-service logging` command. If you'd prefer to use existing logging infrastructure, specify the custom host/port in the config file. 

If `testing` is enabled, the Winston logger will output to both Logstash and stdout (only Logstash otherwise).

### install
```
npm install binder-logging
```

### reader
`lib/reader.js` contains functions that wrap Elasticsearch queries to make it simpler to search through Binder logs. If you'd prefer to monitor a realtime stream of build logs, the `streamLogs` function is available (which will connect to Logstash's WebSocket output).

##### `BinderLogReader.getLogs(opts, cb)` 
Get all historical logs, optionally matching an app name and optionally between before/after times
 - `app` string - app name to filter on
 - `before` string - ISO8601 GMT timestamp
 - `after` string - ISO8601 GMT timestamp
 - `cb` function - callback(err, msgs)

##### `BinderLogReader.streamLogs(opts)`
Stream logs for a given app (mandatory option), optionally since an `after` timestamp. Returns a through stream
- `app` string - app name to filter on
- `after` string - ISO8601 GMT timestamp

#### usage
```
var getReader = require('binder-logging/lib/reader')
var reader = getReader({ host: '<custom logging host>' })
```

### writer
`lib/writer.js` exposes a `getInstance` function that will return a Winston logger given a logger name. This logger exposes the standard logging api (`logger.info`, `logger.error`, ...).

##### `getInstance(name)`
Returns a Winston logger that's connected to the Binder logging stack
- `name` string - logger name (one logger will be created per name, per process)

#### usage
```
var getLogger = require('binder-logging/lib/writer')
var logger = getLogger('<logger name>')
logger.info('this is an info message')
```

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