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!

Say goodbye to manually analyzing phishing and malware threats with Splunk Attack ...

In today’s evolving threat landscape, we understand you’re constantly bombarded with phishing and malware ...

AppDynamics is now part of Splunk Ideas

Hello Splunkers, We have exciting news for you! AppDynamics has been added to the Splunk Ideas Portal. Which ...

Advanced Splunk Data Management Strategies

Join us on Wednesday, May 14, 2025, at 11 AM PDT / 2 PM EDT for an exclusive Tech Talk that delves into ...