<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Logging to Job Inspector from Custom Search Command in Getting Data In</title>
    <link>https://community.splunk.com/t5/Getting-Data-In/Logging-to-Job-Inspector-from-Custom-Search-Command/m-p/486425#M83283</link>
    <description>&lt;P&gt;Hi folks.&lt;BR /&gt;
I have a custom search command and I am using  &lt;CODE&gt;self.logger&lt;/CODE&gt; to log messages from the command. Please see my  &lt;CODE&gt;logging.conf&lt;/CODE&gt; attached.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[loggers]
# root is mandatory.
keys = root, CustomSearchCommand

[handlers]
keys = ConsoleHandler

[formatters]
keys = SimpleFormatter

[logger_root]
level = INFO
handlers = ConsoleHandler

[logger_CustomSearchCommand]
level = INFO
handlers = ConsoleHandler
# qualname is mandatory.
qualname = CustomSearchCommand
# propagate is disabled in order not to log same events twice.
propagate = 0

[handler_ConsoleHandler]
class = StreamHandler
# sys.stdout causes weird errors.
args = (sys.stderr,)
level = INFO
formatter = SimpleFormatter

[formatter_SimpleFormatter]
format = %(asctime)s - %(process)s - %(name)s - %(levelname)s - %(message)s
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;First of all, I don't understand why Splunk doesn't allow us to use  &lt;CODE&gt;sys.stdout&lt;/CODE&gt; in  &lt;CODE&gt;ConsoleHandler&lt;/CODE&gt;, it just keeps failing with a very strange error message:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;11-18-2019 16:49:38.169 ERROR ChunkedExternProcessor - Failed attempting to parse transport header: 2019-11-18 16:49:38,168 - 23427 - CustomSeachCommand - INFO - &amp;lt;ORIGINAL LOG MESSAGE&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;At the same time, using  &lt;CODE&gt;sys.stderr&lt;/CODE&gt; in  &lt;CODE&gt;ConsoleHandler&lt;/CODE&gt; works fine, though the output doesn't look good:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;11-18-2019 16:40:46.346 ERROR ChunkedExternProcessor - stderr: 2019-11-18 16:40:46,345 - 22025 - CustomSearchCommand - INFO - &amp;lt;ORIGINAL LOG MESSAGE&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So why does Splunk always log messages from child processes as errors? It's clear that each final log record consists of two parts:  &lt;CODE&gt;11-18-2019 16:40:46.346 ERROR ChunkedExternProcessor - stderr:&lt;/CODE&gt; (from the parent process, I guess) and  &lt;CODE&gt;2019-11-18 16:40:46,345 - 22025 - CustomSearchCommand - INFO - &amp;lt;ORIGINAL LOG MESSAGE&amp;gt;&lt;/CODE&gt; (from the child process, executing my custom search command).  By the way, I'm inheriting my own command from  &lt;CODE&gt;StreamingCommand&lt;/CODE&gt; and using  &lt;CODE&gt;chunked = true&lt;/CODE&gt;.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Nov 2019 14:50:54 GMT</pubDate>
    <dc:creator>gdavoian</dc:creator>
    <dc:date>2019-11-18T14:50:54Z</dc:date>
    <item>
      <title>Logging to Job Inspector from Custom Search Command</title>
      <link>https://community.splunk.com/t5/Getting-Data-In/Logging-to-Job-Inspector-from-Custom-Search-Command/m-p/486425#M83283</link>
      <description>&lt;P&gt;Hi folks.&lt;BR /&gt;
I have a custom search command and I am using  &lt;CODE&gt;self.logger&lt;/CODE&gt; to log messages from the command. Please see my  &lt;CODE&gt;logging.conf&lt;/CODE&gt; attached.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[loggers]
# root is mandatory.
keys = root, CustomSearchCommand

[handlers]
keys = ConsoleHandler

[formatters]
keys = SimpleFormatter

[logger_root]
level = INFO
handlers = ConsoleHandler

[logger_CustomSearchCommand]
level = INFO
handlers = ConsoleHandler
# qualname is mandatory.
qualname = CustomSearchCommand
# propagate is disabled in order not to log same events twice.
propagate = 0

[handler_ConsoleHandler]
class = StreamHandler
# sys.stdout causes weird errors.
args = (sys.stderr,)
level = INFO
formatter = SimpleFormatter

[formatter_SimpleFormatter]
format = %(asctime)s - %(process)s - %(name)s - %(levelname)s - %(message)s
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;First of all, I don't understand why Splunk doesn't allow us to use  &lt;CODE&gt;sys.stdout&lt;/CODE&gt; in  &lt;CODE&gt;ConsoleHandler&lt;/CODE&gt;, it just keeps failing with a very strange error message:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;11-18-2019 16:49:38.169 ERROR ChunkedExternProcessor - Failed attempting to parse transport header: 2019-11-18 16:49:38,168 - 23427 - CustomSeachCommand - INFO - &amp;lt;ORIGINAL LOG MESSAGE&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;At the same time, using  &lt;CODE&gt;sys.stderr&lt;/CODE&gt; in  &lt;CODE&gt;ConsoleHandler&lt;/CODE&gt; works fine, though the output doesn't look good:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;11-18-2019 16:40:46.346 ERROR ChunkedExternProcessor - stderr: 2019-11-18 16:40:46,345 - 22025 - CustomSearchCommand - INFO - &amp;lt;ORIGINAL LOG MESSAGE&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So why does Splunk always log messages from child processes as errors? It's clear that each final log record consists of two parts:  &lt;CODE&gt;11-18-2019 16:40:46.346 ERROR ChunkedExternProcessor - stderr:&lt;/CODE&gt; (from the parent process, I guess) and  &lt;CODE&gt;2019-11-18 16:40:46,345 - 22025 - CustomSearchCommand - INFO - &amp;lt;ORIGINAL LOG MESSAGE&amp;gt;&lt;/CODE&gt; (from the child process, executing my custom search command).  By the way, I'm inheriting my own command from  &lt;CODE&gt;StreamingCommand&lt;/CODE&gt; and using  &lt;CODE&gt;chunked = true&lt;/CODE&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Nov 2019 14:50:54 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Getting-Data-In/Logging-to-Job-Inspector-from-Custom-Search-Command/m-p/486425#M83283</guid>
      <dc:creator>gdavoian</dc:creator>
      <dc:date>2019-11-18T14:50:54Z</dc:date>
    </item>
  </channel>
</rss>

