# docker-loghose

> Collect all the logs from all docker containers

Latest version **1.6.5** (published 2019-05-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install docker-loghose
pnpm add docker-loghose
yarn add docker-loghose
bun add docker-loghose
```

Provides the command `docker-loghose`.

## 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.6.5 |
| Published | 2019-05-24 |
| First published | 2015-02-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 23.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 63 |
| Author | Matteo Collina |
| Maintainers | matteo.collina, megastef |
| Keywords | docker, log, logs, collect |

## Links

- npm: https://www.npmjs.com/package/docker-loghose
- Repository: https://github.com/mcollina/docker-loghose
- Issues: https://github.com/mcollina/docker-loghose/issues
- npm.io page: https://npm.io/package/docker-loghose

## Dependencies (6)

- [bl](https://npm.io/package/bl.md) ^1.2.0
- [pump](https://npm.io/package/pump.md) ^1.0.0
- [minimist](https://npm.io/package/minimist.md) ^1.1.1
- [through2](https://npm.io/package/through2.md) ^2.0.0
- [never-ending-stream](https://npm.io/package/never-ending-stream.md) ^2.0.0
- [docker-allcontainers](https://npm.io/package/docker-allcontainers.md) ^0.7.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
- [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.6.5 (latest) — 2019-05-24
- 1.6.4 — 2018-10-07
- 1.6.3 — 2018-05-24
- 1.6.2 — 2017-11-10
- 1.6.1 — 2017-11-10
- 1.6.0 — 2017-06-02
- 1.5.1 — 2017-05-05
- 1.4.0 — 2017-04-14
- 1.3.0 — 2016-08-25
- 1.2.0 — 2016-07-11
- 1.1.0 — 2016-06-20
- 1.0.0 — 2016-02-08
- 0.9.0 — 2016-02-04
- 0.8.0 — 2016-01-18
- 0.7.0 — 2015-08-25
- … 13 more at https://npm.io/package/docker-loghose/versions

## README

# docker-loghose

[![Build Status](https://travis-ci.org/mcollina/docker-loghose.svg?branch=master)](https://travis-ci.org/mcollina/docker-loghose)

Collect all the logs from all docker containers

## Install

As a command line tool:

```bash
npm install docker-loghose -g
```

Embedded usage

```bash
npm install docker-loghose --save
```

## Embedded Usage

```js
var loghose = require('docker-loghose')
var through = require('through2')
var opts = {
  json: false, // parse the lines that are coming as JSON
  docker: null, // here goes options for Dockerode
  events: null, // an instance of docker-allcontainers
  newline: false, // Break stream in newlines

  // Logs from the container, running docker-loghose are excluded by default.
  // It could create endless loops, when the same logs are written to stdout...
  // To get all logs set includeCurrentContainer to 'true'
  includeCurrentContainer: false, // default value: false
  
  // In a managed environment, container names may be obfuscated. 
  // If there is a label that provides a better name for logging,
  // provide the key here.
  nameLabel: 'com.amazonaws.ecs.container-name',

  // the following options limit the containers being matched
  // so we can avoid catching logs for unwanted containers
  matchByName: /hello/, // optional
  matchByImage: /matteocollina/, //optional
  skipByName: /.*pasteur.*/, //optional
  skipByImage: /.*dockerfile.*/, //optional
  attachFilter: function (id, dockerInspectInfo) {
    // Optional filter function to decide if the log stream should 
    // be attached to a container or not 
    // e.g. return /LOGGING_ENABLED=true/i.test(dockerInspectInfo.Config.Env.toString())
    return true
  }

  // Enrich all log events with the labels that are set on the container
  // Using a regular expression it's possible to limit which labels are set
  // Labels are added into the root of JSON structure, unless 'labelsKey' is defined
  addLabels: false // default
  labelsMatch: /^ecs-.*/ // defaults to .*
  labelsKey: labels // defaults to 'none'
}
var lh = loghose(opts)
lh.pipe(through.obj(function(chunk, enc, cb) {
  this.push(JSON.stringify(chunk))
  this.push('\n')
  // stop listening to specific container logs
  if (/top secret logs/.test(chunk.line)) { 
    lh.detachContainer(chunk.long_id)
    // we should not get more logs for the container with chunk.long_id
  }
  cb()
})).pipe(process.stdout)


```

## Command Line Usage

```bash
docker-loghose [--json] [--help]
               [--newline]
               [--nameLabel STRING]
               [--matchByImage REGEXP] [--matchByName REGEXP]
               [--skipByImage REGEXP] [--skipByName REGEXP]
```

## Docker Usage

```bash
docker run --rm -v /var/run/docker.sock:/var/run/docker.sock matteocollina/docker-loghose
```

## Data format

```js
{
  v: 0,
  id: "3324acd73ad5",
  long_id: "3324acd73ad573773b901d93e932be65f2bb55b8e6c03167a24c17ab3f172249"
  image: "myimage:latest",
  name: "mycontainer-name"
  time: 1454928524601,
  line: "This is a log line", // this will be an object if opts.jon is true
  labels: {
            com.amazonaws.ecs.cluster: "my-ecs-cluster"
          } // labels placed in 'labels' when "--labelsKey labels"
}
```

Acknowledgements
----------------

This project was kindly sponsored by [nearForm](http://nearform.com).


## License

MIT

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