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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...