npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

docker-loghose

v1.6.5

Published

Collect all the logs from all docker containers

Downloads

3,853

Readme

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

docker-loghose [--json] [--help]
               [--newline]
               [--nameLabel STRING]
               [--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
  labels: {
            com.amazonaws.ecs.cluster: "my-ecs-cluster"
          } // labels placed in 'labels' when "--labelsKey labels"
}

Acknowledgements

This project was kindly sponsored by nearForm.

License

MIT