Getting Data In

Merge lines from rotated file

chclemence
Explorer

Hello,

I have some difficulties to ingest properly logs from rotated file, where the rotation is fully handled by an application, without any settings about its log files.

In some cases, it rotates the log file in the middle of an event, and before the timestamp.

Like this:

file.log.1

[category][event][reason][host][timestamp]...

[category][event][reason][host][timestamp]...

[category][event][reason]

Note: there is no new line or carriage return at tne end of the file

file.log

[host][timestamp]...

[category][event][reason][host][timestamp]...

[category][event][reason][host][timestamp]...

I have some events with an additional line in plain text (no brackets), so at first I let the line merger do its job, but for the splitted line between the 2 log files, it does not work as the first line does not contain the timestamp, and it is added to the previous event.

So, I disabled line merging and started to build a line breaker, resulting in this:

(?:\[[^]]*\][\r\n]*){24}\[[^]]*\](?:[^\[\]]*)([\r\n]+)

This is because the log line is made of 25 blocks between brackets, and optionally a second line.

It works very good on a test file when the splitted line is in the same file, but once the 2 parts of the line are in different files ... it does not work anymore 😞

Do you have any advice on how I could handle that ?

Labels (3)
0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...