Setting the charset is you (a human) telling logstash what the encoding of your input text is at the time it was read. The default encoding in Ruby 1.9 for sockets/files is ASCII-8BIT (basically, 1 byte per character).

Socket#read will, by default, read strings with ASCII-8BIT, even if you send UTF-8 frowny face (☹) the read would produce a 3-character text of bytes e2 98 b9. Now, if you print this text, you will get:

```
>> puts a.inspect
"\xE2\x98\xB9"
```

Which is wrong, right? Shouldn't we have expected a single character string - ☹ ?

Now, if we force_encoding("UTF-8") to tell ruby "Hey, this string thing is actually UTF-8, so interpret the bytes you're storing as UTF-8"

```
>> puts a.inspect
"☹"
```

So, this `raw.force_encoding...` line is exactly for this purpose. You are telling logstash "the bytes you are reading, they are {some charset}"

Once you've set that, logstash will convert *that charset* into UTF-8.

Otherwise, with your patch, you're simply saying 

"If the raw string's encoding is not utf-8, convert it to UTF-8"

And in this case, you can see what happens:

```
>> puts raw.inspect
"\xE2\x98\xB9"
=> nil
>> p raw.encode("UTF-8", :invalid => :replace, :undef => :replace)
"���"
```

Suddenly what started as ☹ is now ���. And that's no good! :)