Open bubbajames-docker opened 4 years ago
Would it be possible to pass Jobber's logPath file handle to the Command's stdout
and stderr
instead of creating temporary files which buffer command's output for return in resultSinks?
https://github.com/dshearer/jobber/blob/658675e6fb73986cfae790142f76b8c7202e78c6/common/exec.go#L107
// make temp files for stdout/stderr
stdout, err := ioutil.TempFile(TempDirPath(), "")
if err != nil {
return nil, err
}
stderr, err := ioutil.TempFile(TempDirPath(), "")
if err != nil {
cleanUpTempfile(stdout)
return nil, err
}
// give them to cmd
cmd.Stdout = stdout
cmd.Stderr = stderr
Then in job file, define Command's log
entry such that stdout
and/or stderr
are directed to same file as prefs.logPath
.
prefs:
logPath: /var/log/jobber/jobber.log
runLog:
type: file
path: /var/log/jobber/jobber-runs.log
maxFileLen: 100m
maxHistories: 2
jobs:
sitemap:
cmd: /usr/local/bin/generateSitemap.sh
time: '*/30 0 3'
onError: Continue
log:
- stdout
- stderr
The above approach still allows use of resultSinks
with stdout
and/or stderr
by using the io.MultiWriter()
call passing common.Logger.Writer()
or common.ErrLogger.Writer()
and temporary file handle.
I would need this feature as well
I have jobber configured and running in a docker container. My jobs log 100's of JSON lines to stderr/stdout. If I configure the job to redirect output to a file, everything works nicely except I must attach a shell to inspect logs.
I would like the output of my scripts to be written to container's stdout/stderr (similar to how Jobber's run log is done) so that logs may be inspected using
docker logs -f <container_name>
or forwarded to ELK stack using Docker syslog log driver.Result Sinks Using the
resultSinks:
withtype: stdout
is not an option as the output is buffered then wrapped with Jobber status. If 100's of log entries occur during script execution, the resulting output is too long to send to remote syslog listener (aka logstash). I would like EACH log entry to be written individually and forwarded to a syslog listener for processing.Sample Log Entry as received by ELK (SHORTEST OF ALL COMMANDS) stderr contains four syslog entries prefixed with
2020-10-02T02:29:03+00:00 INFO (6):
Other options tried:
Symlink log file to /dev/stderr
Any assistance in how to accomplish the above would be greatly appreciated.