I don't know what is your full config. For me, I have tested with your requirement, it's worked at me.
Below is my config:
input {
file {
type => "A"
path => "/path/to/file/A/server.log.1"
}
file {
type => "B"
path => "/path/to/file/B/server.log.2"
}
}
filter{
if [type] == "A" {
grok {
match => [ "message", "field1: %{WORD:field1}" ]
break_on_match => false
add_tag => "field1_message"
}
}
if [type] == "B" {
grok {
match => [ "message", "field2: %{WORD:field2}" ]
break_on_match => false
add_tag => "field2_message"
}
}
}
output {
stdout {
codec => "rubydebug"
}
}
This is the input for server.log.1
field1: hello
And the corresponding output is
{
"message" => "field1: hello",
"@version" => "1",
"@timestamp" => "2014-10-17T03:18:34.421Z",
"type" => "A",
"host" => "ABC",
"path" => "/path/to/file/A/server.log.1",
"field1" => "hello",
"tags" => [
[0] "field1_message"
]
}
The second input for server.log.2
field2: world
And the output is
{
"message" => "field2: world",
"@version" => "1",
"@timestamp" => "2014-10-17T03:18:33.451Z",
"type" => "B",
"host" => "ABC",
"path" => "/path/to/file/B/server.log.2",
"field2" => "world",
"tags" => [
[0] "field2_message"
]
}
Hope this can help you, I am using logstash version 1.4.1.