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

Add an option to send logs to STDOUT #383

Open
toadjaune opened this issue Feb 18, 2019 · 3 comments
Open

Add an option to send logs to STDOUT #383

toadjaune opened this issue Feb 18, 2019 · 3 comments

Comments

@toadjaune
Copy link

When using docker with a container orchestrator (kubernetes, in my case), most logging infrastructures will expect your containers to send their logs through STDOUT/STDERR.

In this image, we miss most interesting logs (typically, access logs) because they go directly to files. Moreover, the location where they go is a volume, which makes it way harder to symlink the logfiles to another location (such as /dev/stdout or /proc/1/fd/1).

It would be really convenient to have an environment variable that would allow all logs to be sent to STDOUT.

@toadjaune
Copy link
Author

As a side note, if anyone has the same issue, I personally worked around it with the following supervisord service :

[program:logs]
priority=10
directory=/var/log
command=/logs-startup-script.sh
user=redmine
autostart=true
autorestart=true
stopsignal=QUIT
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stdout
stderr_logfile_maxbytes=0

And the following script in /logs-startup-script.sh :

#!/bin/bash

# Ensure every log file actually exists
echo "Creating logfiles"
mkdir -p $REDMINE_LOG_DIR/nginx
mkdir -p $REDMINE_LOG_DIR/redmine
mkdir -p $REDMINE_LOG_DIR/supervisor
touch $REDMINE_LOG_DIR/nginx/access.log
touch $REDMINE_LOG_DIR/nginx/error.log
touch $REDMINE_LOG_DIR/nginx/redmine_access.log
touch $REDMINE_LOG_DIR/nginx/redmine_error.log
touch $REDMINE_LOG_DIR/redmine/cron_rake.log
touch $REDMINE_LOG_DIR/redmine/unicorn.stdout.log
touch $REDMINE_LOG_DIR/redmine/unicorn.stderr.log
touch $REDMINE_LOG_DIR/supervisor/cron.log
touch $REDMINE_LOG_DIR/supervisor/nginx.log
touch $REDMINE_LOG_DIR/supervisor/supervisord.log
touch $REDMINE_LOG_DIR/supervisor/unicorn.log

# Manually re-route all logs to stdout/stderr with a tail command
# NB : Some of these files are actually never logged to
tail -f \
  $REDMINE_LOG_DIR/nginx/access.log \
  $REDMINE_LOG_DIR/nginx/error.log \
  $REDMINE_LOG_DIR/nginx/redmine_access.log \
  $REDMINE_LOG_DIR/nginx/redmine_error.log \
  $REDMINE_LOG_DIR/redmine/cron_rake.log \
  $REDMINE_LOG_DIR/redmine/unicorn.stdout.log \
  $REDMINE_LOG_DIR/redmine/unicorn.stderr.log \
  $REDMINE_LOG_DIR/supervisor/cron.log \
  $REDMINE_LOG_DIR/supervisor/nginx.log \
  $REDMINE_LOG_DIR/supervisor/supervisord.log \
  $REDMINE_LOG_DIR/supervisor/unicorn.log

The resulting logs are a bit ugly, but it works. A proper setup probably would prefix log lines by the name of the service they are coming from, or something similar.

@jcormier
Copy link
Collaborator

jcormier commented Feb 18, 2019 via email

@toadjaune
Copy link
Author

I'll try to make one if I can find some time for that ;)

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

No branches or pull requests

2 participants