简体   繁体   中英

logstash - split a message by newlines

logstash

trying to split a message by newlines ( "\n" ) with no success so far. I need to retrieve the last line only.

Logstash code:

mutate{
    split => ["traceback", "\n"]
    add_field => {"traceback_last_line" => "%{[traceback][-1]}"}
}

Input:

[traceback] = 
  "File "<doctest...>", line 10, in <module>
    lumberjack()
  File "<doctest...>", line 4, in lumberjack
    bright_side_of_death()
IndexError: tuple index out of range"

I Used gsub to replace '\n' and then, the usual sequence of mutate.split

    mutate {
       copy => { "traceback" => "traceback_tmp" }
    }
    mutate {
       gsub => ["traceback_tmp", "\n", "::"]
    }
    mutate {
       split => {"traceback_tmp" => "::"}
       add_field => ["traceback_summary", "%{[traceback_tmp][-1]}"]
       remove_field => ["traceback_tmp"]
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM