So, in this case, I've got error <Grok::PatternError: pattern %{log_prefix} not defined>. Of course I understand why. Is there any suggestion how I can do this correctly? Thanks.
You should put the values in static fields and create the dynamic fields with the add_field option of the grok filter.
The code need to be like this i think:
grok {
match => { "log.file.path" => "(?<log_prefix>((?<=logs\/)(\w*)(?=\/)|(?<=logs\/)(\w*)(?=.*\.)))" }
}
grok {
match => { "message" => "%{DATESTAMP:tmp1}] (?<tmp2>production\.[A-Z]{3,9}|local\.[A-Z]{3,9}): (?<tmp3>(.|\r|\n)*)"}
#add_field executed only if the filter is successful
add_field => {
"dev.%{log_prefix}.timestamp" => "%{tmp1}"
"dev.%{log_prefix}.loglevel" => "%{tmp2}"
"dev.%{log_prefix}.message" => "%{tmp3}"
}
}
Hi. Thanks for your solution. I've found another one for me. But it's similar. Instead of using "add_fields" I decided to use "mutate" filter to rename temporary fields.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.