Repository navigation
Replace hand-written SLF4J logger fields by Lombok @Slf4j #602
Copy link
Copy link
Open
Description
Proposal
Replace the hand-written logger fields, such as:
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessorSimple.class.getSimpleName());by Lombok's @Slf4j annotation. Lombok is already used across the project.
@Slf4jgenerates the logger field with the SLF4J API.- Logback stays the SLF4J implementation, as it is today.
util.Logalready uses Logback to change log levels.
This removes repeated code (25 declarations in src/main). It also avoids copy-and-paste mistakes, where the class name passed to getLogger() isn't the class that declares the field.
Points to decide
- Field name.
@Slf4jcreates a field calledlogby default. Addlombok.log.fieldName = LOGGERtolombok.config, so existing code (LOGGER.warn(...)) doesn't change. - Logger name. Today loggers are named with
getSimpleName()(for exampleProcessorSimple).@Slf4juses the full class name (org.cloudsimplus.resources.ProcessorSimple).- Log levels set with
Log.setLevel(logger, level)keep working, since they get the logger object. - A
logback.xmlthat sets levels by the short names would stop matching. - The current log pattern (
%-5level %msg%n) doesn't print the logger name, so the output doesn't change. - Options:
- accept the full names (the usual convention, and it allows per-package levels such as
org.cloudsimplus.schedulers); - or use
@Slf4j(topic = "ProcessorSimple"), which repeats the class name again.
- accept the full names (the usual convention, and it allows per-package levels such as
- Log levels set with
- Interfaces can't use
@Slf4j. 13 public interfaces declare a publicLOGGERconstant, which their implementations use. They areVm,Host,Datacenter,DatacenterBroker,VmAllocationPolicy,VmScheduler,CloudletScheduler,VmScaling,FileStorage,TraceReader,Heuristic,HeuristicSolutionandVmCloner.- These constants are part of the public API. For example, the examples call
Log.setLevel(DatacenterBroker.LOGGER, Level.ERROR), and some trace readers callbroker.LOGGER.trace(...). - Options:
- keep these constants as they are and use
@Slf4jonly in classes; - or move each logger to the main abstract class (for example
DatacenterBrokerAbstract) with@Slf4j. That is a breaking change for user code that usesVm.LOGGERand the other constants.
- keep these constants as they are and use
- Removing the constants also changes which logger an implementation uses. Today
VmSimplelogs throughVm.LOGGER, so oneLog.setLevel(Vm.LOGGER, …)call controls every VM class.
- These constants are part of the public API. For example, the examples call
Tasks
- Decide points 1–3 above.
- Add
lombok.log.fieldName = LOGGERtolombok.config, if that option is chosen. - Replace the logger fields in classes by
@Slf4j, and remove the unusedLogger/LoggerFactoryimports. - Update
logback.xml/logback-test.xmland the docs, if logger names change. - Check the
cloudsimplus-examplesthat callLog.setLevel(...)on these loggers.
🤖 Generated with Claude Code
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity