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

[epilogue] Use more specific loggers at runtime, if available #7093

Open
SamCarlberg opened this issue Sep 19, 2024 · 0 comments
Open

[epilogue] Use more specific loggers at runtime, if available #7093

SamCarlberg opened this issue Sep 19, 2024 · 0 comments
Labels
component: epilogue Annotation-based logging library

Comments

@SamCarlberg
Copy link
Member

The IO layer pattern is a fairly common solution for splitting real robot code from simulation code. Currently, Epilogue logging only uses the declared types of fields and methods, so data specific to a "real" IO implementation would not be loggable (or the base IO interface would need to expose functions for retrieving all the hardware-specific data). Doing a runtime switch to check for a more specific logger would be ideal

@Logged
interface IO {
  void setVoltage(Voltage v);
  AngularVelocity getSpeed();
}

@Logged
class RealIO implements IO {
  @Logged // Would not be included in logs for an IO object! Only for objects declared as a RealIO!
  public Current getStatorCurrent() { ... }

  ...
}

// Currently would be logged using the logger for the IO interface
IO io = new RealIO(); 

// Currently would be logged using the logger for the RealIO class
RealIO realIO = (RealIO) io;

This would be an update to the LoggableHandler class to inject if conditions into the generated code that check the logged object's class against known logger implementations for subtypes of the declared type. If the object's class is a subtype that has an @Logged annotation, then it should be logged using that class's generated logger instead of the generic logger for the element's declared type. Generated code should look something like this:

public void tryUpdate(DataLogger dataLogger, Foo object) {
  var io = (Foo.IO) $IO.get(object);
  if (io.getClass().equals(Foo.RealIO.class)) {
    Epilogue.FOO_REAL_IO_LOGGER.tryUpdate(dataLogger.getSubLogger("IO"), (Foo.RealIO) io);
  } else {
    // Fall back to the generic logger
    Epilogue.FOO_IO_LOGGER.tryUpdate(dataLogger.getSubLogger("IO"), io);
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: epilogue Annotation-based logging library
Projects
None yet
Development

No branches or pull requests

1 participant