Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One log per container #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@ forwarded with:
* `--skipByName REGEXP`: do not forward logs/stats for the containers whose name matches the given REGEXP.
* `--skipByImage REGEXP`: do not forward logs/stats for the containers whose image matches the given REGEXP.

You can pass the `--containersTokensFilepath` flag if you want different containers logs
to be published to different log sets.
The configuration file needs to respect the following format:
```json
{
"repoName1": "logentries_token",
"repoName2": "logentries_token"
}
```

### Running container in a restricted environment.
Some environments(such as Google Compute Engine) does not allow to access the docker socket without special privileges. You will get EACCES(`Error: read EACCES`) error if you try to run the container.
To run the container in such environments add --privileged to the `docker run` command.
Expand Down
21 changes: 17 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,31 @@ function connect(opts) {
return stream;
}


function start(opts) {
var logsToken = opts.logstoken || opts.token;
var statsToken = opts.statstoken || opts.token;
var eventsToken = opts.eventstoken || opts.token;
var out;
var noRestart = function() {};

var containersTokens = null;
if (opts.containersTokensFilepath) {
containersTokens = require(opts.containersTokensFilepath);
}

var filter = through.obj(function(obj, enc, cb) {
addAll(opts.add, obj);
var token = '';

if (obj.line) {
if (obj.line && obj.image && containersTokens) {
var regex = /(.+):\w+/g;
var match = regex.exec(obj.image);

if (match != null) {
var repoName = match[1];
token = containersTokens[repoName];
}
} else if (obj.line) {
token = logsToken;
}
else if (obj.type) {
Expand Down Expand Up @@ -69,7 +81,7 @@ function start(opts) {

opts.events = events;

if (opts.logs !== false && logsToken) {
if (opts.logs !== false && (logsToken || containersTokens)) {
loghose = logFactory(opts);
loghose.pipe(filter);
streamsOpened++;
Expand Down Expand Up @@ -175,14 +187,15 @@ function cli() {
}
});

if (argv.help || !(argv.token || argv.logstoken || argv.statstoken || argv.eventstoken)) {
if (argv.help || !(argv.token || argv.logstoken || argv.statstoken || argv.eventstoken || argv.containersTokensFilepath)) {
console.log('Usage: docker-logentries [-l LOGSTOKEN] [-k STATSTOKEN] [-e EVENTSTOKEN]\n' +
' [-t TOKEN] [--secure] [--json]\n' +
' [--no-newline] [--no-stats] [--no-logs] [--no-dockerEvents]\n' +
' [-i STATSINTERVAL] [-a KEY=VALUE]\n' +
' [--matchByImage REGEXP] [--matchByName REGEXP]\n' +
' [--skipByImage REGEXP] [--skipByName REGEXP]\n' +
' [--server HOSTNAME] [--port PORT]\n' +
' [--containersTokensFilepath CONTAINERSTOKENFILEPATH]\n' +
' [--help]');

process.exit(1);
Expand Down