
Or we could instead use 2>&1 which is a fancy syntaxįor saying "redirect standard error to the same Standard error to the same file, we could do ls docs > output.txt 2> output.txt If we wanted to redirect both standard output and cat bees.txt ants.txt > insects.txt 2> error.txt Insects.txt, and redirecting standard error to a file called error.txt. We can redirect multiple streams at once! In this example, we areĬoncatenating two files, redirecting standard output to a file called To specify 1> to redirect standard output: ( date 1> now.txt = date > now.txt) all together The > operator actually defaults to using 1 as theįile descriptor number, which is why we don't need In both cases, you see the entire log buth with highlighted search term like this: The -f switch could be omitted if no live grep is wanted. If the container logs to stderr, you can pipe them as Edoardo already wrote for a simple grep: docker logs -f 2>&1 | grep -line-buffered -i -E -color "select count\(\*\)|$" * is escaped to disable its special glob functionality, where (, and ) are masked to avoid their regex meaning as group, which is enabled by -E switch.-color highlights the matched parts (seems the default behaviour on my Ubuntu 16.04 LTS, but maybe not on other distributions, so I included it here to be safe).-E is an extended regex pattern, required to apply our pattern that allow us returning also the non matching results.greps -line-buffered switch flushes the output on every line, which is required to grep in real time when docker logs -f is used.


Please leave a comment here, on the Docker registry or GitHub.Additionally, I found it usefull to highlight some terms that I'm searching for in the logs. Heka does produce a small amount of logs when starting and those do end up in logentries, but it's only a couple of lines so not too bad. On top of that, there's a small shell script (sed wrapper actually) set as an entry point that replaces a token placeholder in Heka's configuration with the one provided by user.ĭecision to use progrium/busybox as a base image wasn't the smartest one due to the scary notice about it probably being deprecated in the near future. Local ok, payload = pcall(code, read_message("Payload")) Using built in JSON decoder, all we had to do was: This token must be present in every log line sent, otherwise logentries will reject it.ĭeconstruction of the JSON logs generated by Docker and inserting the token is done by a simple script written in Lua, which Heka supports out of the box. Sending logs to logentries requires user to create a log which is defined by a token. We were already using it for a similar task and based on the positive experience decided to stick with it.Īfter configuring Heka to watch container logs and send data to logentries using TCP with TLS we were almost done. Heka adds another 37MB when extracted, but it's well worth it. We could use the official busybox image which is half the size, but in the end it wouldn't make much of a difference. This gave us a starting size of just 5MB. To keep things relatively small we decided to use progrium/busybox image as our base. $ docker run -d -v /var/lib/docker:/var/lib/docker:ro tray/heka-logentries:latestįor the curious, head over to our GitHub repo and check the content.

Send all container logs on the host to logentries log with the token : Heka project has been marked deprecated, which makes these instructions obsolete.
