Skip to content

Instantly share code, notes, and snippets.

@ryansb
Created April 24, 2017 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryansb/6c693b61f9bff4553586210dd482cb5e to your computer and use it in GitHub Desktop.
Save ryansb/6c693b61f9bff4553586210dd482cb5e to your computer and use it in GitHub Desktop.

Is there a better way to handle having an application inside a container that's executed from outside pass logs up?

Ansible-Container has a CLI tool that invokes a conductor container (which contains Ansible, a bunch of deps, etc) and has to get & display logs from the executions inside. To make this work & display logs, we have kind of an odd setup that I'm not sure is right.

In the container

We're logging out a combination of structlog and plain Ansible output to stdout. This means not all the CLI output is parseable as JSON, so we format it inside the container to be shown on the host stdout.

Outside the container

The main CLI tool has two different loggers: plainLogger which is a pass-through that just forwards the container's stdout along. For logs about the actual Ansible Container CLI tool, we're using structlog as normal.

So in the CLI tool, we capture the stdout stream, then for each line plainLogger.info(log_iter.next().rstrip()). One of the downsides is we lose all the leveling information from inside the container doing this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment