Best practice for logging when Kong runs in Docker?

8,185 views
Skip to first unread message

Martin Danielsson

unread,
May 13, 2016, 3:51:50 AM5/13/16
to Kong
Hello,

Before I go ahead and do something stupid, I'd like to throw in the following question:

When Kong runs in a docker container (which it does happily and nicely), I would normally like it to just log everything to stdout and stderr (logs/errors) so that my docker log driver, such as a driver for fluentd or some other logging mechanism can take over. Then I'd have decoupled my API configuration from the logging.

I guess I could do this with some bash magic and tail commands, but perhaps somebody already has a recipe for this, or perhaps there is a way to just configure Kong to do this out of the box?

Best regards,
Martin 

data...@gmail.com

unread,
May 20, 2016, 10:00:40 AM5/20/16
to Kong
Any news on this?
I have exactly the same request.

Kind regards,
Stephan

Martin Danielsson

unread,
May 21, 2016, 9:03:33 AM5/21/16
to Kong
No. Unfortunately not. We'll look into this next week or so. If we find something suitable which can be used as recipe we will post it here as well.

Best regards,
Martin

Martin Danielsson

unread,
Jun 1, 2016, 4:45:20 AM6/1/16
to Kong
Related question: Is it okay to use file-log plugins for multiple APIs which all write to the same file?

Marco

unread,
Jun 1, 2016, 8:47:40 PM6/1/16
to Martin Danielsson, Kong
Martin - That technically shouldn't be a problem, but I haven't tried it personally.


 Marco Palladino | CTO @ Mashape | mashape.com+1 (415) 361-3858

--
You received this message because you are subscribed to the Google Groups "Kong" group.
To unsubscribe from this group and stop receiving emails from it, send an email to konglayer+...@googlegroups.com.
To post to this group, send email to kong...@googlegroups.com.
Visit this group at https://groups.google.com/group/konglayer.
To view this discussion on the web visit https://groups.google.com/d/msgid/konglayer/ea5b4342-b344-424d-8d43-5522f0836acb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Message has been deleted

data...@gmail.com

unread,
Jun 9, 2016, 9:41:12 AM6/9/16
to Kong
I've tried the following

1.
In kong.yml
Change :
error_log logs/error.log error;
access_log logs/access.log;

To:
error_log /dev/stderr error;
access_log /dev/stdout;

2.
ln -sf /dev/stderr /usr/local/kong/logs/error.log
ln -sf /dev/stdout /usr/local/kong/logs/access.
log


My docker runs with the syslog driver and works great for nginx and other types of dockers.
In both cases above I get no logging to my syslog on the server.

Any tips are welcome.

Kind regards,
Stephan

Martin Danielsson

unread,
Jun 9, 2016, 10:41:30 AM6/9/16
to Kong, data...@gmail.com
Does what you describe here work or does it not work?

I haven't tried it.

/Martin

data...@gmail.com

unread,
Jun 11, 2016, 6:13:01 PM6/11/16
to Kong
Unfortunately it does not work. I see nothing in the syslog logs on the docker host.

tomasz....@gmail.com

unread,
Dec 23, 2016, 5:29:22 AM12/23/16
to Kong
Oh god, it's December now and still no good solution posted here. Shame.

data...@gmail.com

unread,
Dec 28, 2016, 4:11:01 AM12/28/16
to Kong, tomasz....@gmail.com
Actually we run Kong 0.9.3 and output our logs to syslog. This works pretty smooth.
I have to adjust the rights every time I deploy the Kong Docker, so output is possible (/dev/console is normally root, but Kong runs as nginx since 0.9.3).

docker exec kong chmod a+rw /dev/console

I am in the process of upgrading to 0.9.6 (there is no official 0.9.7 Kong docker yet) but now get this:
Error: /usr/local/share/lua/5.1/kong/cmd/start.lua:23: nginx is already running in /usr/local/kong

Chris Knowles

unread,
Mar 4, 2017, 12:49:49 AM3/4/17
to Kong
I posted https://github.com/Mashape/docker-kong/pull/71 in case anyone is still looking around for a solution until Docker sort out their issues.

heitorm...@gmail.com

unread,
May 30, 2017, 12:28:56 PM5/30/17
to Kong
A coworker solved this issue with a couple of bash tricks:

Dockerfile:

FROM ...
...
...
...
RUN mkdir
-p /opt/logs \
   
&& ln -sf /tmp/logpipe /opt/logs/api-gateway.log

ENTRYPOINT
["/entrypoint.sh"]
CMD
["/usr/local/bin/kong", "start", "-c", "/etc/kong/kong.conf", "--nginx-conf", "/etc/kong/custom_nginx.template"]


We run our containers through a custom entrypoint called entrypoint.sh. Just before running kong, we do this:

rm -f /tmp/logpipe
mkfifo
-m 666 /tmp/logpipe
cat
<> /tmp/logpipe 1>&2 &


Explanation:

mkdir -p /opt/logs                            # creates /opt/logs folder
ln -sf /tmp/logpipe /opt/logs/api-gateway.log # creates a symbolic link from the /opt/logs/api-gateway.log file to /tmp/logpipe
rm
-f /tmp/logpipe                            # removes logpipe file
mkfifo
-m 666 /tmp/logpipe                    # creates a pipe which is refered by the /opt/logs/api-gateway.log file.
cat
<> /tmp/logpipe 1>&2 &                    # this line pipes everything that goes through /tmp/logpipe, which is a data stream generated by kong logging to /opt/logs/api-gateway.log (symlink), to 1>&2 (/dev/stdout and /dev/stderr).

pamiel

unread,
Jul 13, 2017, 5:08:22 AM7/13/17
to Kong
using /dev/stdout and /dev/stderr did not work for me as well, but using /proc/1/fd/1 and /proc/1/fd/2 is working perfectly: all Kong logs are sent to stdout and stderr.

At the end, my Kong configuration file contains the following lines:
proxy_access_log = /proc/1/fd/1
proxy_error_log = /proc/1/fd/2
admin_access_log = /proc/1/fd/1
admin_error_log = /proc/1/fd/2

kjst...@gmail.com

unread,
Oct 23, 2017, 12:33:45 PM10/23/17
to Kong
Kong now supports docker logs via env vars pointing to stdout/stderr in 0.11.0 - https://github.com/Kong/docker-kong/issues/40

jju...@g.clemson.edu

unread,
Oct 29, 2017, 10:01:37 PM10/29/17
to Kong
Are there any major advantages to doing:

"
-e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \ -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \ -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \ -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
"

versus letting it log to a file within its own container? I believe in cloud environment like Mesos/OpenShift you can now use CLI's or tools like oc get logs > logFile.txt for quick debugging into issues right? Is that the biggest advantage to just piping out it out to the standard error/log? Just asking a newbie question since running app's in a container based env is still a learning process :) . 

On Friday, May 13, 2016 at 3:51:50 AM UTC-4, Martin Danielsson wrote:
Reply all
Reply to author
Forward
0 new messages