Splunk Search

Can you help me with my field extractions?

pdantuuri0411
Explorer

I have logs from the same source type called log4j in Splunk. The format for the logs is a little different. For example the log formats for data and loglevel are as follows

Log 1 ---- "14:13:00,777 DEBUG"
Log 2 ---- "2019-01-17 14:03:02,013 INFO"

I extracted the field 'loglevel' by adding an entry \s+(?P loglevel [^ ]+)\s from console to the source type and it works perfectly for the example in log 1. However, it doesn't work for Log 2 because of the date, and it considers the time(14:03:02,013) as the log level.

Please advise about what entry should be added to have the loglevel extracted for both the examples.

0 Karma

Vijeta
Influencer

This rex expression works for me

| makeresults | eval log1="14:13:00,777 DEBUG"| appendpipe[|eval log1="2019-01-17 14:03:02,013 INFO"]|rex field=log1 "^(\S+\s+){1,3}(?<loglevel>\S+)"
0 Karma

pdantuuri0411
Explorer

@Vijeta, appreciate the quick response.

As I mentioned in my question, the only option I have is to add a field(eg - \s+(?P[^ ]+)\s) in the sourcetype from console. So the answer you provided doesnt work for me. I cannot add rejex.

0 Karma

Vijeta
Influencer

@pdantuuri0411 - you can try with ^(\S+\s+){1,3}(?\S+)

0 Karma
Get Updates on the Splunk Community!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...