Skip to content

Instantly share code, notes, and snippets.

@pauloconnor
Last active December 1, 2022 09:33
Show Gist options
  • Star 32 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pauloconnor/4707710 to your computer and use it in GitHub Desktop.
Save pauloconnor/4707710 to your computer and use it in GitHub Desktop.
Logstash Mutate Filter for stripping Linux color codes from log files
# Get rid of color codes
mutate {
gsub => ["message", "\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]", ""]
}
@JasonIamAUnixAdmin
Copy link

FYI to get this to work I needed to pull out the @ but thanks!

@julianogalgaro
Copy link

Thanks!

@Wolfant
Copy link

Wolfant commented Jul 13, 2017

really usefull thanks

@immatt2015
Copy link

Thanks

@Darwiner
Copy link

Also removed @ from @message for compatibility with newer logstash versions. Otherwise, works perfectly. Thanks!

@seancheung
Copy link

seancheung commented Mar 5, 2018

This also strips text in between

EDIT: turns out to be my bad. :) This works fine!

@matutter
Copy link

I've been looking for this for hours, thanks!

@guyav
Copy link

guyav commented Oct 31, 2018

Thanks!
As mentioned in previous comments, I had to remove the @ to get it working on Logstash 6.4.2.

@ns-smehra
Copy link

How does this work though ?

@konart
Copy link

konart commented May 8, 2020

How does this work though ?

Well it literally removes ANSI color codes from the message field with gsub.

@abhinav1107
Copy link

works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment