Live data from Hacker News

Logging as a code smell

dave.autonoma.ca

31–40 of 54 posts

Re: Logging as a code smell

#31

(1) This seems more than a bit Java-specific. (2) Not all kinds of software can afford to depend on an event-publishing infrastructure. One obvious example is the event-publishing infrastructure itself. Less obviously, all of its transitive dependencies down to storage, networking, and operating systems. (3) After dismissing logging and explaining a more complex event model, the author says in their own project he st…

I wish I had read this comment before reading the post.

Re: Logging as a code smell

#32
It's a good point but I think the author sort of drove past the key insight. This is called structured logging. Having some kind of consistent schema of log messages is much better than plain strings for analysis later. It's just building a loose schema of events/log types, and picking a serialization format for said schema. JSON is popular because it remains human readable as well. I agree though, it really is very useful, not much harder than logging strings, and it's easy to evolve an existing system to gradually add structure to logs.

Re: Logging as a code smell

#34

It's a good point but I think the author sort of drove past the key insight. This is called structured logging. Having some kind of consistent schema of log messages is much better than plain strings for analysis later. It's just building a loose schema of events/log types, and picking a serialization format for said schema. JSON is popular because it remains human readable as well. I agree though, it really is very…

Serilog (.NET, not Java) has been doing structured logging well for years.

Re: Logging as a code smell

#35

> Logging is an example of code duplication. Is it? What am I missing here?

I think the idea is you have: (1) Some code that does a thing (2) Another line of code that logs that the thing happened And, like in-lined documentation, the code can diverge from the text that says what it does.

So the author proposes we replace it with:

(1) Some code that does a thing

(2) Another line of code that sends an event that the thing happened

Re: Logging as a code smell

#36
post #14

Earlier quoted context omitted.

when my code is not working how i expect it to, i print a ton of equal signs, then the value on a knew line, then a new row of equal signs. never used loggin before.

You my friend need to experience an interactive debugger.

You my friend need to experience a production heisenbug.

Re: Logging as a code smell

#37
I agree logging is a bit of a code smell, but I prefer Mark Seemann's take: https://blog.ploeh.dk/2020/03/23/repeatable-execution/

TL;DR: Log impure actions. If you minimize and group side effects, you don't need to log as much. Pure functions can be recomputed any time if you know their inputs.

Event buses can be useful, but it's hard to look at an event being published and know what it does and whether it's important. Whereas the importance of a logger call is usually pretty clear. Logs are rarely load-bearing, but an event can mean anything.

Re: Logging as a code smell

#38
post #8
post #4

I'm not sure this article does a good enough job of explaining why it's a code smell. Aside from the event bus code looking slightly better, I don't see any big advantages. One disadvantage is that if you have a big class with lots of different events, you now have to import all of your events rather than just importing the singular logger. Typically I only resort to logging in situations where I don't want to propag…

Awful hard to attach a debugger to a production system?

I hope so

Re: Logging as a code smell

#39

Earlier quoted context omitted.

What if you don’t have physical access to a production system?

That's an organizational problem, not a technical one.

That developers don't have live access is dictated by industry rules in some cases.

Not a problem but rather a fact of life.

Re: Logging as a code smell

#40
The author is severely confused. What he's calling logs are actually debug traces. You don't want to use events for those.

> eases the transition to internationalized log messages

You don't internationalize debug traces any more than you internationalize your function names or programming language words. You barely even fix spelling mistakes in trace messages. Often, you build software without them at all: "compile them out".

One excellent reason not to use events for trace messages is that you may sometimes want every last trace message leading up to a crash to be recorded, which won't happen if they go through an event system where they sit in a queue which is no longer being serviced since everything died.

Oh, and your shiny event system could have issues, debugging which could benefit from trace messages.

Post reply on HN