Can you actually modify the contents of the actual log statement through the logback.xml? My understanding is that the “onkyoPower state updated to OFF” is actually generated by the thing logging and logback.xml mainly controls the rest of the logging statement (e.g. date stamp, originator, etc) and not the statement itself. That would be cool though if you can.
I would approach this using the Logging Persistenec binding. That way you can separate out just the items you want to have logged (rather than everything published to the event bus) if you want to and control the format of the statement. It separates out the item name as the logger name and the state as the msg so you can use logging:pattern=logger=%msg.
If the Logging Persistence bundle can produce the right format, splunk can read it and forward it for indexing. That and a nice how-to in the wiki would be helpful!
Take a look at Splunk’s Field Extraction/Field Transformation functionality. With simple REGEX you can extract the source material even when it’s not in key=value format.
That also works when you’re using Splunk Cloud, which is where I’m using it (for work)
If you’ve got access to the Splunk’s indexer layer, you can also do the relevant extraction at that layer, after the forwarders send it over (in the native format)
It’ll save you a lot of fiddling trying to get the log into the right format, and it’ll come in handy if you want to extract from the regular openHAB.log file (it’s even less structured)
Thank you very much for all your help, I’ve got it!
I’ve struggled with splunk quite a bit, I was able to do the regex but somehow was still unable to do a search with the newly extracted fields so I did it in OpenHAB:
This is the new appender:
<appender name="SPLUNKFILE" class="ch.qos.logback.core.FileAppender">
<file>${openhab.logdir:-logs}/splunk.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS Z} openhabitem %replace(%replace(%msg){' received command ', '="'}){' state updated to ', '="'}"%n</pattern>
</encoder>
</appender>
So far, not bad. The only remaining problem is that somehow splunk seems to lock the file, meaning if OpenHAB needs a restart it cannot write to the file anymore. But I’m sure that I’ll be able to figure out this problem