Permit ~ characters in URL detection.
Catch substitution errors with eval..

I don't recall why this is needed, but my memory says that an invalid
regex would cause an 'exception' (and the regex here is user-input).
h4x: Manually encode log message in UTF-8.

I'm not sure if this is being done correctly. This is just dirty tree
remains from months ago. I think I assumed the logger would handle this
automagically, but discovered that the logs were corrupted. Still I'm
not sure the encoding is happening at the right place.