Most of us write logs in a manner like

  • my_db_object was not found
  • my_value is empty

A “better” way is to show the intent rather than the result of the comparison/condition.

This can be done by following a pattern that’s used in rust, by using

X should be Y or expected X to be Y

We can rewrite the above logs as

  • my_db_object should be present
  • my_value should not be empty

It may seem that both are relatively equal. But the former ones do not directly show what was expected. Rather, they show the result of some comparison/conditional.

The latter ones directly show what was intended, and that is enough to tell what should be done.

Former log: my_value is empty

  1. brain go: Oh X is empty
  2. brain also go: should X have been empty? or should it have been populated?

Latter log: my_value should not be empty

  1. Brain go: Oh X should not be empty