|
|
|
|
|
by deathanatos
2581 days ago
|
|
Log messages belong on stderr, not stdout. (Despite the name, it is for "diagnostic output" (—man stdio), and using it prevents logs from co-mingling the primary output of the program, if there is one, and even if there isn't, causes all logs to be in an sensible, expected place.) You're going to want timestamps real quick. If there's one part of the log message that I use, and use a lot, it's the timestamp. When tells you valuable things like "correlates with production outage" or "this operation took way too long". The tri-value parameter for whether to emit or not emit a newline is, to me, weird. Having three possible inputs where there are only two possible outcomes just seems confusing. Are you just trying to line it up s.t. someone could pass default() and have the "normal" thing happen? (Which wouldn't, if it was a plain bool as you have it now, unless you flipped the boolean.) |
|
For servers, structured logging is a must. Each line should have a timestamp like you said. The API should include a context object that can hold information to be logged on each line (like a user ID, request ID, ...).