Getting Data In

Separate logging for input script

erydberg
Splunk Employee
Splunk Employee

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?

Tags (1)
1 Solution

gkanapathy
Splunk Employee
Splunk Employee

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.

View solution in original post

gkanapathy
Splunk Employee
Splunk Employee

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.

Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...