Improve defensiveness of sample logger func

JSON encoding may fail for a number of reasons. Guard against invalid input.
Merge pull request #1 from mattp-/patch-1

Improve defensiveness of sample logger func