7.1 Differentiate Between a Domain and Technical Log
In section 3.4, we used a producer method to introduce a logger. In practice, it’s not unusual for developers to create two or more different loggers. We might, for example, create one for operational messages (e.g. Campaign added) and one for technical messages (e.g. Database not accessible).
To implement this for an application, proceed as follows:
- Create two qualifiers called
DomainLog
andTecLog
in the packagepress.turngeek.mycampaign.util
. - Replace the producer method for the logger with one producer method annotated with
@DomainLog
and another annotated with@TecLog
. To differentiate between the loggers, add two different prefixes to the String parameter of thegetLogger
method: once, String“DomainLog:”
and once,“TecLog:”
. - Annotate the logger of the
DonateMoneyController
bean with@DomainLog
. - Inject a logger in the
CampaignServiceBean
and annotate it with@TecLog
. Use this logger to issue a message in the methodgetAllCampaigns
.
7.2 Add a Message for the Updating of a Campaign
In chapter 4, we learned how to send application-wide messages. Currently, messages are sent whenever a campaign is added or deleted. We might also need a message to be sent when a campaign is updated.
To help us achieve a better understanding of CDI events, we can try sending this message now as practise. Proceed as follows:
- Modify the class
Events
by adding the qualifierUpdated
. - Send the message at the appropriate place in the
EditCampaignController
. - Create an observer method
onCampaignUpdated
in theCampaignListProducer
. Since this method cannot yet be fully implemented, it should be used solely to issue a message via a logger.
Discussion
Use the message board below to give the authors your feedback or to discuss this page’s topic with other readers (in English please!). Please don’t expect the authors to answer directly, but they might update the content of this site according to your feedback.