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
TecLogin the package
- Replace the producer method for the logger with one producer method annotated with
@DomainLogand another annotated with
@TecLog. To differentiate between the loggers, add two different prefixes to the String parameter of the
getLoggermethod: once, String
- Annotate the logger of the
- Inject a logger in the
CampaignServiceBeanand annotate it with
@TecLog. Use this logger to issue a message in the method
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
Eventsby adding the qualifier
- Send the message at the appropriate place in the
- Create an observer method
CampaignListProducer. Since this method cannot yet be fully implemented, it should be used solely to issue a message via a logger.
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.