Skip to content

mmariani/docker-loghose

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

85 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

docker-loghose

Build Status

Collect all the logs from all docker containers

## Install

As a command line tool:

npm install docker-loghose -g

Embedded usage

npm install docker-loghose --save

Embedded Usage

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
  // 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
}
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

docker-loghose [--json] [--help]
               [--newline]
               [--matchByImage REGEXP] [--matchByName REGEXP]
               [--skipByImage REGEXP] [--skipByName REGEXP]

Docker Usage

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

Data format

{
  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
}

Acknowledgements

This project was kindly sponsored by nearForm.

License

MIT

About

Collect all the logs from all docker containers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%