@Matteo Merli

I've been playing around with where to put the atInfo() and event ID
and had the following thoughts.
Putting atInfo(Enum<?> event) at the point of event creation is a
suggestion so that if that event is not enabled at that level, then a
dummy attribute accumulator will be returned and the logging itself
becomes a noop.

One thought I had about this was that happy and error cases use the
same log event. However, this doesn't work out. Take the example of
LOOKUP and LOOKUP_ERROR. It's quite foreseeable that someone would
want to enable logs for the error case and not the happy case. If we
use the same LOOKUP event for both, then all error cases need to be
logged at a level above the happy case. So the happy case is INFO,
error cases are WARN or ERROR. But then this doesn't help with
removing the attribute accumulator work, just the logging work. The
attributes need to be collected in all cases because we don't know a
priori whether the event will result in a happy case or an error case.

All thoughts I've had about it have ended in the same conclusion.
Either you need to collect the attributes every time, or you have to
collect all the attributes every time at the point you send the log.
The latter case is illustrated in case A at
https://gist.github.com/ivankelly/d029da1ae1e75699662131a3aef216a0.
It's not very pleasant.

So, if we want structured logging we need to accept the cost of
accumulating attributes. I expect the cost of this to be low. CPU
wise, it's adding objects to an ArrayList, which is fast as long as
the initial array is sized sensibly. Suppliers should deal with the
cases where generating the object is costly. Memory wise, it's
allocation of the event object and an array list. These allocations
all happen in the control plane and are very short lived. If it does
prove to cause GC pressure, the event objects can easily be pooled.

Let me know what you think. The current state of the API looks as
follows (javadoc missing of course)
https://gist.github.com/ivankelly/300cbef832bcbc14ffc6620bd50e8b12


-Ivan

Reply via email to