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] Autogenerate nicer data names by default, not just raw element names #7167

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

SamCarlberg
Copy link
Member

@SamCarlberg SamCarlberg commented Oct 5, 2024

eg "getFoo()" will now be logged as "Foo", or "m_leftMotor" as "Left Motor"

It is now a compilation error to reuse the same logged name for multiple elements (since whatever is declared last would overwrite anything logged before it)

Do not log record fields (just use the accessors). This also fixes an issue where records could never be logged due to identical member and accessor names

Also skips toString, hashCode, and clone methods when generating loggers

eg "getFoo()" would now be logged as "Get Foo", or "m_leftMotor" as "Left Motor"

It is now a compilation error to reuse the same logged name for multiple elements (since whatever is declared last would overwrite anything logged before it)

Do not log record fields (just use the accessors). This also fixes an issue where records could never be logged due to identical member and accessor names
@SamCarlberg SamCarlberg added the component: epilogue Annotation-based logging library label Oct 5, 2024
@SamCarlberg SamCarlberg requested a review from a team as a code owner October 5, 2024 02:34
@oh-yes-0-fps
Copy link
Contributor

oh-yes-0-fps commented Oct 5, 2024

I believe changing the case of the field names is worse than logging the raw names. It could make it harder to quickly search for things in the advantage scope search bar. Removing suffixes isn't a terrible idea though.

@BR88C
Copy link
Contributor

BR88C commented Oct 5, 2024

Could there be an option to opt out of the renaming behavior globally, or at the very least, an option to opt out when annotating a class with @Logged? I could see the desire from teams to use either behavior. While this solution does rename fields predictably, I could see it being confusing for some students as opposed to using the raw name. For what it's worth, I also believe that the existing name override when annotating a field or method individually was a sufficient solution.

Starlight220

This comment was marked as duplicate.

@BR88C
Copy link
Contributor

BR88C commented Oct 5, 2024

perhaps the old behavior can be retained via a global configuration setting?

From what I understand, since field names are fetched only during compilation, this would still have to be an option within the @Logged annotation that would propagate to subsequent annotated classes, and can't be specified in EpilogueConfiguration. This is what I meant when I said "global", which was misleading.

Upon further consideration I don't think propagation is viable, as there is a possibility for loggers needing both implementations of renamed fields and raw field names depending on where the user is opting out within the dependency tree of loggers, and if there is any overlap. So opting out (or opting in) per-class seems like the only alternative, though maybe there's a different solution I'm not seeing.

@katzuv
Copy link
Contributor

katzuv commented Oct 5, 2024

I believe changing the case of the field names is worse than logging the raw names. It could make it harder to quickly search for things in the advantage scope search bar.

IIRC AdvantageScope uses fuzzy search, so it shouldn't be a problem.

@SamCarlberg
Copy link
Member Author

From what I understand, since field names are fetched only during compilation, this would still have to be an option within the @Logged annotation that would propagate to subsequent annotated classes, and can't be specified in EpilogueConfiguration. This is what I meant when I said "global", which was misleading.

Yep, EpilogueConfiguration is a runtime-only thing. Any compilation configurations would need to be baked into the compile gradle task, such as by setting environment variables that the annotation process can read. Otherwise, it'd have to be configurable in the annotations themselves. Something like a an auto-name strategy like this could work, though it could only be configured on a per-class basis

@Logged(autoName = ELEMENT_NAME)
class D {
  double m_d; // logged as "m_d"

  double getD() { ... } // logged as "getD"
}

@Logged(autoName = FOR_HUMANS)
class I {
  int m_i; // logged as "I"

  int getI() { ... } // Also logged as "I" - name collision and compilation error
}

@spacey-sooty
Copy link
Contributor

eg "getFoo()" will now be logged as "Get Foo", or "m_leftMotor" as "Left Motor"

I don't the idea of having "Get" in log entries, could this change getFoo() to Foo?

@SamCarlberg
Copy link
Member Author

eg "getFoo()" will now be logged as "Get Foo", or "m_leftMotor" as "Left Motor"

I don't the idea of having "Get" in log entries, could this change getFoo() to Foo?

That's an error in my description - this does already remove the leading "get" from accessor methods. That's part of the reason why I made it an error to use the same name for multiple elements, otherwise a m_foo field and getFoo() accessor would both be logged as "Foo"

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

Successfully merging this pull request may close these issues.

6 participants