Skip to content

Commit 2b6b9d8

Browse files
zarendZach Arend
andauthored
fix(logging): handle file rotation of splunkd_sterr.log (#684)
Fix issue with logging of standard error messages where standard error logs would be lost when logging large amount of data to stadard error. Splunk logs to splunkd_stdout.log as the Unix standard error device. This file is rotated. According to [What Splunk software logs about itself](https://docs.splunk.com/Documentation/Splunk/9.2.1/Troubleshooting/WhatSplunklogsaboutitself), "The historical rotation for most internal logs is 5 files of 25MB each". docker-splunk container tails the output of splunkd_stdout.log to standard output. The existing behavior is that the container receives Splunk's standard error messages until splunkd_stdout.log is about 25MB. When the log files passes 25MB, Splunk rotates the log file by rename splunkd_stdout.log to something like splunkd_stoudt1.log and creating a new splunkd_stdout.log. By default, tail follows the file descriptor of argument file. I believe that if the file is renamed, it continutes to track the file descriptor of argument file, if that is available. This is not the behavior we want for file rotation, since we always want to follow the information that goes to splunkd_stdout.log and not splunkd_stdout1.log, splunkd_stdout2.log, etc. Fix standard error logs not surfacing by passing `-F` option to unix tail command. This causes tail to keep retrying to open argument file name if it becomes unavailable. Change in behavior to print standard error logs to standard out for entire lifetime of the program, instead of stopping after the first file rotation. Fix #626 Co-authored-by: Zach Arend <imzach@amazon.com>
1 parent 9b55b69 commit 2b6b9d8

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

splunk/common-files/entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ watch_for_failure(){
6262
# Any crashes/errors while Splunk is running should get logged to splunkd_stderr.log and sent to the container's stdout
6363
if [ -z "$SPLUNK_TAIL_FILE" ]; then
6464
echo Ansible playbook complete, will begin streaming splunkd_stderr.log
65-
${RUN_AS_SPLUNK} tail -n 0 -f ${SPLUNK_HOME}/var/log/splunk/splunkd_stderr.log &
65+
${RUN_AS_SPLUNK} tail -n 0 -F ${SPLUNK_HOME}/var/log/splunk/splunkd_stderr.log &
6666
else
6767
echo Ansible playbook complete, will begin streaming ${SPLUNK_TAIL_FILE}
68-
${RUN_AS_SPLUNK} tail -n 0 -f ${SPLUNK_TAIL_FILE} &
68+
${RUN_AS_SPLUNK} tail -n 0 -F ${SPLUNK_TAIL_FILE} &
6969
fi
7070
if [[ "$DISABLE_ENTIRE_SHELL_ACCESS" == "true" ]]; then
7171
disable_entire_shell_access_for_container

uf/common-files/entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ watch_for_failure(){
6363
fi
6464
# Any crashes/errors while Splunk is running should get logged to splunkd_stderr.log and sent to the container's stdout
6565
if [ -z "$SPLUNK_TAIL_FILE" ]; then
66-
${RUN_AS_SPLUNK} tail -n 0 -f ${SPLUNK_HOME}/var/log/splunk/splunkd_stderr.log &
66+
${RUN_AS_SPLUNK} tail -n 0 -F ${SPLUNK_HOME}/var/log/splunk/splunkd_stderr.log &
6767
else
68-
${RUN_AS_SPLUNK} tail -n 0 -f ${SPLUNK_TAIL_FILE} &
68+
${RUN_AS_SPLUNK} tail -n 0 -F ${SPLUNK_TAIL_FILE} &
6969
fi
7070
wait
7171
}

0 commit comments

Comments
 (0)