Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How would logging be handled? #1

Open
thced opened this issue Nov 16, 2022 · 1 comment
Open

How would logging be handled? #1

thced opened this issue Nov 16, 2022 · 1 comment

Comments

@thced
Copy link

thced commented Nov 16, 2022

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
Copy link
Owner

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:

  • Lombok and mappers (to avoid boilerplate code)
  • Custom libraries with common shared concepts, or defining complex data types from primitive data types (for example "money" = number + currency)
  • Logging library

[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]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants