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.

Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...