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

Change how logging works to make configuration easier #119

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

FiniteReality
Copy link

There was a short discussion in the NeoForged discord about ways that configuring logging could be made easier for mod developers and users, and this is roughly what came from that discussion.

It's not the cleanest code, but the main goal is to get feedback on the basic idea of configuring logging in this way.

For modders and users, general logging configuration should be done by the system properties under logging.*:

  • logging.loglevel.* configures the log levels for the logger with the given name.
    • logging.loglevel.default configures the root logger level. Loggers will default to this level unless otherwise specified.
    • Currently, this affects both debug.log and latest.log. I know this isn't ideal, but I couldn't figure out a way to do it and I didn't want to block opening this PR forever. Perfection being the enemy of the good, and all.
    • logging.loglevel.mypackage configures all loggers in the mypackage package.
      • Further packages can be specified to refine the logging, such as logging.loglevel.mypackage.mysubpackage.
      • Per-type loggers can also be specified by passing their fully-qualified-class-name. For example, logging.loglevel.mypackage.mysubpackage.MyLoggedClass.
  • logging.marker.* configures the minimum log level for a given marker. For example, if you wanted to turn on trace logging for launch plugins, you could specify logging.marker.LAUNCHPLUGIN=TRACE.
    • This (I believe) overrides the log levels specified via logging.loglevel.*, so you can specify logging.loglevel.default=WARN and logging.marker.COOLMARKER=TRACE to turn on trace logging for any log message using the COOLMARKER marker.

Configuring the nitty-gritty of logging consists of specifying one or more --loggingConfig parameters, which is a URI to a valid log4j configuration file. These are aggregated by ModLauncher and used to populate the logging configuration fairly early on in the startup path. I imagine NeoForge/FancyModLoader would want to specify a --loggingConfig parameter to configure their marker filter defaults, or to add their custom log appenders for the server console.

As for why I decided to put these changes into ModLauncher, I felt that centralising all configuration in a single place would be ideal, and doing it early on in the startup process means that we can ensure a reliable foundation for the entire lifecycle of a launched game.

Copy link

@Minecraftschurli Minecraftschurli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, the logging.loglevel prefix looks a bit clunky to me because it contains log twice but it's fine

@Technici4n Technici4n requested a review from a team October 17, 2023 20:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants