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

Logger context properties #1473

Merged
merged 25 commits into from
May 16, 2023
Merged

Logger context properties #1473

merged 25 commits into from
May 16, 2023

Conversation

rgoers
Copy link
Member

@rgoers rgoers commented May 9, 2023

This implements the Properties Enhancement .

I still need to update the documentation in the manual, but I will do that in a separate PR.

This commit is quite large I suspect a lot of the changes are due to merging the spotless changes in from main, but this still hit a very large number of classes.

As a guide here are the major items:

  1. PropertiesUtil was modified to a) stop doing most of the normalization junk b) support getting properties from JSON as well as properties, c) allow multiple properties/json files to be located during scanning, d) allow LoggerContext specific files to be located either in META-INF/log4j2.{contextName}.properties|json or META-INF/log4j2.context.properties|json.
  2. Most PropertySources now extend ContextAwarePropertySource and support separating the properties into multiple Properties objects based on which context they belong to.
  3. LoggerContext now has a reference to a PropertiesUtil.
  4. System and Environment properties can apply at the system-wide level or LoggerContext scope. Properties in those files should follow the naming convention of "log4j2.{contextName}.{component}.{key}". For system-wide scope the context name is "*".
  5. Maven doesn't support "" in a property name since the non-deprecated syntax has the property name as an XML element. As such, system properties may be defined without the log4j2., in which case they will be treated having system-wide scope.
  6. Properties in context specific files can ONLY apply to that context so all properties in those files must leave off the "log4j2.{contextName} prefix.
  7. All Log4j properties are defined as enums in classes that implement PropertyKey. Unfortunately @SetSystemProperty cannot use the enum so a static constant for each enum is also defined but is only used for that purpose.
  8. PropertiesUtil now has a ThreadLocal that holds the LoggerContext's PropertiesUtil during configuration, thus allowing all that stuff to not need access to the LoggerContext or be injected with a PropertiesUtil (which almost certainly would create a circularity anyway). PropertiesUtil.getProperties() checks the ThreadLocal and uses that if it is not null.
  9. Both LoggerContextFactory getContext methods and LoggerContext's reconfigure method set the ThreadLocal while configuration is occuring.
  10. All tests and all classes using properties were modified to reference LoggingSystemPropertyKey (log4j-api) or Log4jPropertyKey (log4j-core).
  11. A file named log4j2.propertyMapping.json can now be defined in any jar. This file contains property aliases for the new key names. This is only used when looking up keys, such as log4j.level, which it maps to StatusLogger.level. Note that this does not allow properties to be defined in files or as system properties with these names.

rgoers and others added 25 commits April 30, 2023 21:48
Bumps [actions/checkout](https://github.com/actions/checkout) from 3.4.0 to 3.5.2.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@24cb908...8e5e7e5)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [actions/setup-python](https://github.com/actions/setup-python) from 4.3.0 to 4.6.0.
- [Release notes](https://github.com/actions/setup-python/releases)
- [Commits](actions/setup-python@13ae5bb...57ded4d)

---
updated-dependencies:
- dependency-name: actions/setup-python
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Sometimes Spotless will not detect that a header already exists, e.g. if
it is after a package declaration.
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.1.28 to 2.3.1.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@cc7986c...8662eab)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 2.3.1 to 2.3.2.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](github/codeql-action@8662eab...f3feb00)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Adds a documentation page that forwards the user to Github.
By bumping to logging-parent 9, we remove the explicit Spotless
configuration.
/**
* Components that own properties.
*/
public enum PropertyComponent {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be mostly in log4j-core?

Copy link
Member Author

Choose a reason for hiding this comment

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

It is an enum. So I would need one in core and one in the API. I didn't think it was worth the effort.

@rgoers rgoers merged commit f070192 into main May 16, 2023
@rgoers rgoers deleted the LoggerContextProperties branch May 16, 2023 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants