Should Libraries Log or Propagate Errors?

9 points by veqq


My assumption was always: Applications log (and err), libraries err.

Today, I was shocked to learn that various ecosystems love logging things in libraries (such that silencing those logs is even an important task). My view of logs has been around wide discrete events OR (for small scale personal things) writing errs in a file.

I was particularly surprised to learn this was an important consideration of making Go's slog, since you can easily propagate and enrich errors... Why not just err (and handle them by e.g. adding to the log context then retrying)? Or pass extra details in the return package?

What workflows etc. make this desirable? All I've been able to think of is the ability to change the log level and silence random extra information.

vulcan

What if a library wants to report something other than an error? e.g. if it wants to log that an upstream service is degraded, but still functional (thus not necessarily an error).