Skip to content

Instantly share code, notes, and snippets.

@TheCase
Last active June 20, 2024 14:00
Show Gist options
  • Save TheCase/b0389757fb58fe45244317042a3405f0 to your computer and use it in GitHub Desktop.
Save TheCase/b0389757fb58fe45244317042a3405f0 to your computer and use it in GitHub Desktop.
Filbeats - remove ansi control characters for colored logs
- script:
when:
regexp:
message: "[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]"
lang: javascript
id: remove_ansi_color
source: >
function process(event) {
var msg = event.Get("message")
var regex = /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g
event.Put("message", msg.replace(regex, ''))
event.Tag("ansi_color_removed")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment