Skip to content

Replace hand-written SLF4J logger fields by Lombok @Slf4j #602

Open

Description

@manoelcampos

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.

  • @Slf4j generates the logger field with the SLF4J API.
  • Logback stays the SLF4J implementation, as it is today. util.Log already 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

  1. Field name. @Slf4j creates a field called log by default. Add lombok.log.fieldName = LOGGER to lombok.config, so existing code (LOGGER.warn(...)) doesn't change.
  2. Logger name. Today loggers are named with getSimpleName() (for example ProcessorSimple). @Slf4j uses 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.xml that 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.
  3. Interfaces can't use @Slf4j. 13 public interfaces declare a public LOGGER constant, which their implementations use. They are Vm, Host, Datacenter, DatacenterBroker, VmAllocationPolicy, VmScheduler, CloudletScheduler, VmScaling, FileStorage, TraceReader, Heuristic, HeuristicSolution and VmCloner.
    • These constants are part of the public API. For example, the examples call Log.setLevel(DatacenterBroker.LOGGER, Level.ERROR), and some trace readers call broker.LOGGER.trace(...).
    • Options:
      • keep these constants as they are and use @Slf4j only 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 uses Vm.LOGGER and the other constants.
    • Removing the constants also changes which logger an implementation uses. Today VmSimple logs through Vm.LOGGER, so one Log.setLevel(Vm.LOGGER, …) call controls every VM class.

Tasks

  • Decide points 1–3 above.
  • Add lombok.log.fieldName = LOGGER to lombok.config, if that option is chosen.
  • Replace the logger fields in classes by @Slf4j, and remove the unused Logger/LoggerFactory imports.
  • Update logback.xml/logback-test.xml and the docs, if logger names change.
  • Check the cloudsimplus-examples that call Log.setLevel(...) on these loggers.

🤖 Generated with Claude Code

Activity

  1. self-assigned this
    on Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions