jmgarridopaz / bluezone

An example application implementing Hexagonal Architecture
https://jmgarridopaz.github.io/content/hexagonalarchitecture-ig/intro.html
GNU General Public License v3.0
133 stars 30 forks source link

How would logging be handled? #1

Open thced opened 1 year ago

thced commented 1 year ago

I would like to ask of your input surrounding logging, such as slf4j.

I see no logging throughout the modules, and I presume that is intentionally left out to demonstrate the concept, but for a larger project there is likely need to involve that.

How would you approach logging throughout the hexagon use cases for example? How far should one go to keep it isolated?

jmgarridopaz commented 1 year ago

Hi thanks for looking at my code and for your question.

The reason there's no logging in the example is that it's still under construction, and maybe I didn't need it yet, or maybe I decided not to include it for the sake of simplicity (for this reason sometimes I simply use the std java output to console, instead of a logging library).

According to Hexagonal Architecture, logging to a file, console or whatever external real world device would have to be abstracted to a driven port.

The question is "does it worth it?"

In my opinion it doesn't. SL4J is already an abstraction. So, making our own would lead us to have almost an identical interface. Using a logging library would hardly bring noise into our app (or would hardly corrupt our model, using DDD vocabulary).

Radical purists (me some years ago) will say to you: "Any code not shipped with the std programming language you use, is considered like a framework or like an external library. Hence it will be outside the hexagon."

Reasonable purists, like me nowadays :) will accept some libraries/tools to be used inside the hexagon. For example:

[Here I ask to myself an open question that comes to my mind right now on the fly:

Would logging be considered a driven port if the device it writes to is the memory of the machine?

Answering to myself at first sight:

I would say that logging to an in-memory data structure would be code belonging to the hexagon. So logging "per se" is not an outside world activity]