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!

Index This | Why did the turkey cross the road?

November 2025 Edition  Hayyy Splunk Education Enthusiasts and the Eternally Curious!   We’re back with this ...

Enter the Agentic Era with Splunk AI Assistant for SPL 1.4

  &#x1f680; Your data just got a serious AI upgrade — are you ready? Say hello to the Agentic Era with the ...

Feel the Splunk Love: Real Stories from Real Customers

Hello Splunk Community,    What’s the best part of hearing how our customers use Splunk? Easy: the positive ...