I'm using a scripted input for an application. The script writes warnings to stderr, which makes them show up in splunkd.log. I want to save the messages, but I don't want to mix them with the logs in splunkd.log. How can I set up separate logging for my script? And where should the log file be saved?
If I had to, I suppose I would create a new file/file descriptor near the beginning of your script and redirect the stderr descriptor to it. I'd just write it to $SPLUNK_HOME/var/log/splunk/
. The environment variable $SPLUNK_HOME
should be available in your script when it is called by Splunk. You will need to do stuff like add your own timestamp to each line, as the output won't be captured and prepended by Splunk. A big disadvantage here though is you won't be rotating or cleaning up your own log without a lot of work.
What I'd really do is, I'd leave it in splunkd.log and just make sure the beginning of my logged stderr output line have the name of my script so I can find and filter them easily in Splunk itself.
If I had to, I suppose I would create a new file/file descriptor near the beginning of your script and redirect the stderr descriptor to it. I'd just write it to $SPLUNK_HOME/var/log/splunk/
. The environment variable $SPLUNK_HOME
should be available in your script when it is called by Splunk. You will need to do stuff like add your own timestamp to each line, as the output won't be captured and prepended by Splunk. A big disadvantage here though is you won't be rotating or cleaning up your own log without a lot of work.
What I'd really do is, I'd leave it in splunkd.log and just make sure the beginning of my logged stderr output line have the name of my script so I can find and filter them easily in Splunk itself.