Whitespace before the | is allowed (even tabs and newlines!), so you may want to check for that also. If $log has a trailing | or leading <,
removing your >> may also be not what you want, but those cases you probably ought to treat as input errors, along with
|- (which also can have whitespace between the two chars).