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!

Unlock Database Monitoring with Splunk Observability Cloud

  In today’s fast-paced digital landscape, even minor database slowdowns can disrupt user experiences and ...

Purpose in Action: How Splunk Is Helping Power an Inclusive Future for All

At Cisco, purpose isn’t a tagline—it’s a commitment. Cisco’s FY25 Purpose Report outlines how the company is ...

[Upcoming Webinar] Demo Day: Transforming IT Operations with Splunk

Join us for a live Demo Day at the Cisco Store on January 21st 10:00am - 11:00am PST In the fast-paced world ...