Re: [I] [MS10] Log4j API generalization #1 (logging-log4j2)
grobmeier commented on issue #2273: URL: https://github.com/apache/logging-log4j2/issues/2273#issuecomment-1994980963 Confirmed -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullable and modernization part 2 (logging-log4net)
erikmav commented on code in PR #123: URL: https://github.com/apache/logging-log4net/pull/123#discussion_r1523826184 ## src/log4net/Repository/Hierarchy/Logger.cs: ## @@ -329,12 +306,12 @@ public virtual void RemoveAllAppenders() /// on the appender removed. /// /// -public virtual IAppender RemoveAppender(IAppender appender) +public virtual IAppender? RemoveAppender(IAppender? appender) Review Comment: I show it covered from existing LoggerTest class -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullable and modernization part 2 (logging-log4net)
FreeAndNil commented on code in PR #123: URL: https://github.com/apache/logging-log4net/pull/123#discussion_r1523959729 ## src/log4net/Repository/Hierarchy/Logger.cs: ## @@ -329,12 +306,12 @@ public virtual void RemoveAllAppenders() /// on the appender removed. /// /// -public virtual IAppender RemoveAppender(IAppender appender) +public virtual IAppender? RemoveAppender(IAppender? appender) Review Comment: RemoveAppender(string) is covered, but RemoveAppender(IAppender) isn't. This could be easily added in TestAppender2(). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullable and modernization part 2 (logging-log4net)
FreeAndNil commented on PR #123: URL: https://github.com/apache/logging-log4net/pull/123#issuecomment-1995964665 @erikmav Thank you very much (especially for adding the tests). After adding the one missing test (RemoveAppender(IAppender) we are ready to merge. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullable and modernization part 2 (logging-log4net)
FreeAndNil commented on PR #123: URL: https://github.com/apache/logging-log4net/pull/123#issuecomment-1995977044 @erikmav @fluffynuts I've created issue #124 for those improvements. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[I] Improve logging context integration [logging-log4j-kotlin]
rocketraman opened a new issue, #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71 Using log4j2 context kind of sucks. The assumption that context will always be set at the Thread or coroutine level is IMO false, and sometimes we just want to set context for a particular block of code, or for a particular logger. We should have a way to do something like this outside of a coroutine / suspending context: ```kotlin withContextMap(...) { // log something } ``` Possible implementations (only map shown here, but similar for stack)? ```kotlin fun withContextMap( map: Map, block: () -> T, ): T { val oldMap = ContextMap.view return try { ContextMap += map block() } finally { ContextMap.clear() ContextMap += oldMap } } ``` Could also be related to https://github.com/apache/logging-log4j-kotlin/issues/36. We may want to do something like: ```kotlin val log = parentLog.withContext(...) ... log.debug { ... } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] [BUG] Exception stack works ok with logback , but a lot of the exception stack is gone with log4j2. (logging-log4j2)
rgoers commented on issue #2363: URL: https://github.com/apache/logging-log4j2/issues/2363#issuecomment-1996359179 @ppkarwasz @vy I agree that the below is not ideal or what I would recommend but the exception does need to log it as a parameter. Changing this behavior now under the covers is very poor. I can attest that I have seen it in a bunch of code at my employer. Simply logging it as an error is NOT ok. In the case where the number of parameters match the number of placeholders they all need to be included as parameters. Only when the Throwable is "extra" should it be logged as a Throwable. ``` private static void log(String param) { try { int b = param.length(); } catch (Exception e) { log.error("fail to process {}, the error is:{}", param, e); } } ``` Logging a warning or error to the status log is perfectly acceptable to me for the following. As I recall we previously simply didn't replace the '{}' sequence. ``` @Test public void testLog() { log.info("first param is {}, second param is {}", "Log4j2"); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
vy commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-1997010610 I think this is related to [apache/logging-log4j2#2213]. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] [BUG] Exception stack works ok with logback , but a lot of the exception stack is gone with log4j2. (logging-log4j2)
vy commented on issue #2363: URL: https://github.com/apache/logging-log4j2/issues/2363#issuecomment-1997032784 @SeasonPanPan, thanks so much for the report. This issue is more convoluted than it meets the eye: 1. `formatTo()` behaviour of `ParameterizedMessage` and `ReusableParameterizedMessage` doesn't match 2. `DEFAULT_MESSAGE_FACTORY_CLASS` and `DEFAULT_FLOW_MESSAGE_FACTORY_CLASS` fields of `AbstractLogger` is not respectively read from `log4j2.messageFactory` and `log4j2.flowMessageFactory` properties anymore (Yet another bug!) 3. Log4j `<2.20.0`, `2.23.1`, Logback... They all exhibit different behaviours. 4. etc. Before implementing anything, I want to do some homework first. I will create a list of all corner cases, compare their behaviour across the two different Log4j versions cited above, and then decide on what shall change and in which way. This week I am swamped with other priorities. I believe I can start working on this sometime next week. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Bump actions/setup-java from 4.1.0 to 4.2.0 [logging-parent]
dependabot[bot] opened a new pull request, #135: URL: https://github.com/apache/logging-parent/pull/135 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4.1.0 to 4.2.0. Release notes Sourced from https://github.com/actions/setup-java/releases";>actions/setup-java's releases. v4.2.0 What's Changed Updated actions/httpclient version to 2.2.1 and other dependencies by https://github.com/HarithaVattikuti";>@HarithaVattikuti in https://redirect.github.com/actions/setup-java/pull/607";>actions/setup-java#607 Added .tool-versions file support along with .java-version file by https://github.com/mahabaleshwars";>@mahabaleshwars in https://redirect.github.com/actions/setup-java/pull/606";>actions/setup-java#606 New Contributors https://github.com/HarithaVattikuti";>@HarithaVattikuti made their first contribution in https://redirect.github.com/actions/setup-java/pull/607";>actions/setup-java#607 Full Changelog: https://github.com/actions/setup-java/compare/v4...v4.2.0";>https://github.com/actions/setup-java/compare/v4...v4.2.0 Commits https://github.com/actions/setup-java/commit/5896cecc08fd8a1fbdfaf517e29b571164b031f7";>5896cec Added .tool-versions file support (https://redirect.github.com/actions/setup-java/issues/606";>#606) https://github.com/actions/setup-java/commit/80ae3c2885b277a440ee4931b74570716d9a0e27";>80ae3c2 Update httpclient version and other dependencies (https://redirect.github.com/actions/setup-java/issues/607";>#607) See full diff in https://github.com/actions/setup-java/compare/9704b39bf258b59bc04b50fa2dd55e9ed76b47a8...5896cecc08fd8a1fbdfaf517e29b571164b031f7";>compare view [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump actions/setup-java from 4.1.0 to 4.2.0 [logging-parent]
github-actions[bot] merged PR #135: URL: https://github.com/apache/logging-parent/pull/135 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Bump com.palantir.javaformat:palantir-java-format from 2.40.0 to 2.41.0 [logging-parent]
dependabot[bot] opened a new pull request, #136: URL: https://github.com/apache/logging-parent/pull/136 Bumps [com.palantir.javaformat:palantir-java-format](https://github.com/palantir/palantir-java-format) from 2.40.0 to 2.41.0. Release notes Sourced from https://github.com/palantir/palantir-java-format/releases";>com.palantir.javaformat:palantir-java-format's releases. 2.41.0 Type Description Link Fix Avoid computing expensive debug info for all checkState() calls https://redirect.github.com/palantir/palantir-java-format/pull/1029";>palantir/palantir-java-format#1029 Improvement Enable Nullaway https://redirect.github.com/palantir/palantir-java-format/pull/988";>palantir/palantir-java-format#988 Commits https://github.com/palantir/palantir-java-format/commit/94bfcd0569451a30dceed6b63d9d7b78c60c050e";>94bfcd0 Autorelease 2.41.0 https://github.com/palantir/palantir-java-format/commit/9c88122074387b8e39781060596073045a888f1f";>9c88122 Avoid computing expensive debug info for all checkState() calls (https://redirect.github.com/palantir/palantir-java-format/issues/1029";>#1029) https://github.com/palantir/palantir-java-format/commit/1f62421b94cb8175abe265d92b88451d63b91d81";>1f62421 Excavator: Upgrade failure-reports plugin (https://redirect.github.com/palantir/palantir-java-format/issues/1027";>#1027) https://github.com/palantir/palantir-java-format/commit/b3ef776d8fd7be6e5a53319f7f4a40b7ee0793a4";>b3ef776 Excavator: Render CircleCI file using template specified in .circleci/templa... https://github.com/palantir/palantir-java-format/commit/8c3c72786be6fe0abe46e0aabd83c1bc7166d0c1";>8c3c727 Excavator: Remove failure-reports plugin (https://redirect.github.com/palantir/palantir-java-format/issues/1022";>#1022) https://github.com/palantir/palantir-java-format/commit/87d018bd9960492ae986d1d625770c7f0902eb7b";>87d018b Excavator: Upgrades Baseline to the latest version (https://redirect.github.com/palantir/palantir-java-format/issues/1021";>#1021) https://github.com/palantir/palantir-java-format/commit/c6dfcb1b0128545b33f44cb4647185c2d9a928aa";>c6dfcb1 Excavator: Upgrade failure-reports plugin (https://redirect.github.com/palantir/palantir-java-format/issues/1020";>#1020) https://github.com/palantir/palantir-java-format/commit/dfab74d2e9b7f1cb42b82b41a59b02539bec7bff";>dfab74d Excavator: Upgrades Baseline to the latest version (https://redirect.github.com/palantir/palantir-java-format/issues/1019";>#1019) https://github.com/palantir/palantir-java-format/commit/e223fabec6b39a4e0bbf71ffd5bdd92ba711a9f3";>e223fab Excavator: Upgrade buildscript dependencies (https://redirect.github.com/palantir/palantir-java-format/issues/1018";>#1018) https://github.com/palantir/palantir-java-format/commit/5c762a4aaf476f1df6756db561e11a5fe8a1277c";>5c762a4 Excavator: Render CircleCI file using template specified in .circleci/templa... Additional commits viewable in https://github.com/palantir/palantir-java-format/compare/2.40.0...2.41.0";>compare view [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) -
Re: [PR] Bump com.palantir.javaformat:palantir-java-format from 2.40.0 to 2.41.0 [logging-parent]
github-actions[bot] merged PR #136: URL: https://github.com/apache/logging-parent/pull/136 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[I] Log messages with partially missing parameters (logging-log4j2)
ppkarwasz opened a new issue, #2380: URL: https://github.com/apache/logging-log4j2/issues/2380 Log4j version `2.20.0` did also log messages with missing parameters. A call like: ```java logger.info("{}, {} and {}", 1, 2); ``` resulted in a partially replaced message: `1, 2, and {}`. The behavior changed in `2.21.0` and should be restored for backward compatibility. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump org.apache.groovy:groovy-bom from 4.0.19 to 4.0.20 (logging-log4j2)
github-actions[bot] merged PR #2376: URL: https://github.com/apache/logging-log4j2/pull/2376 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump guava.version from 33.0.0-jre to 33.1.0-jre (logging-log4j2)
github-actions[bot] closed pull request #2375: Bump guava.version from 33.0.0-jre to 33.1.0-jre URL: https://github.com/apache/logging-log4j2/pull/2375 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump spring-framework.version from 5.3.32 to 5.3.33 (logging-log4j2)
github-actions[bot] merged PR #2378: URL: https://github.com/apache/logging-log4j2/pull/2378 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Add Logback's throwable-consuming semantics as an option (logging-log4j2)
ppkarwasz opened a new pull request, #2381: URL: https://github.com/apache/logging-log4j2/pull/2381 The semantics used to determine the `Throwable` attached to a log event changed in Logback 1.1.0 (in the fix to [LOGBACK-873](https://jira.qos.ch/browse/LOGBACK-873)). When there are not enough arguments to the log call to fill both the throwable field and the placeholders contained in the message pattern, Logback 1.1.0 and later prefer to fill the throwable field and leave some placeholders empty. Log4j Core does the opposite choice: it first fills all the placeholders and only fills the throwable field if there is something left. This change allows `log4j-slf4j-impl` and `log4j-slf4j2-impl` users to switch between the two behaviors by setting the property `log4j2.messageFactory` to: ``` org.apache.logging.slf4j.message.ThrowableConsumingMessageFactory ``` In this PR two choices have been made: - the message factory is only included in `log4j-slf4j-impl` and `log4j-slf4j2-impl`, since it should be mostly required by Logback users during a transition period. Note that Logback's and Log4j's semantics to deal with throwables agree whenever enough arguments are provided. In a second step users can modify their code using openrewrite/rewrite-logging-frameworks#141, so that it behaves in the same way in Logback and Log4j Core out-of-the-box. However I can also create a new `log4j-message` artifact for this. - no **garbage-free** version of this factory is provided. SLF4J creates temporary arrays whenever **more than 2** arguments are provided. I believe that an additional creation of a `ParameterizeMessage` instance does not make a difference. Closes #2363 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Bump org.springframework:spring-framework-bom from 5.3.32 to 5.3.33 [logging-log4j-audit-sample]
dependabot[bot] opened a new pull request, #43: URL: https://github.com/apache/logging-log4j-audit-sample/pull/43 Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 5.3.32 to 5.3.33. Release notes Sourced from https://github.com/spring-projects/spring-framework/releases";>org.springframework:spring-framework-bom's releases. v5.3.33 :star: New Features Extract reusable method for URI validations https://redirect.github.com/spring-projects/spring-framework/issues/32442";>#32442 Allow UriTemplate to be built with an empty template https://redirect.github.com/spring-projects/spring-framework/issues/32438";>#32438 Refine *HttpMessageConverter#getContentLength return value null safety https://redirect.github.com/spring-projects/spring-framework/issues/32332";>#32332 :lady_beetle: Bug Fixes AopUtils.getMostSpecificMethod does not return original method for proxy-derived method anymore https://redirect.github.com/spring-projects/spring-framework/issues/32369";>#32369 Better protect against concurrent error handling for async requests https://redirect.github.com/spring-projects/spring-framework/issues/32342";>#32342 Restore Jetty 10 compatibility in JettyClientHttpResponse https://redirect.github.com/spring-projects/spring-framework/issues/32337";>#32337 ContentCachingResponseWrapper no longer honors Content-Type and Content-Length https://redirect.github.com/spring-projects/spring-framework/issues/32322";>#32322 :notebook_with_decorative_cover: Documentation Build KDoc against 5.3.x Spring Framework Javadoc https://redirect.github.com/spring-projects/spring-framework/issues/32414";>#32414 :hammer: Dependency Upgrades Upgrade to Reactor 2020.0.42 https://redirect.github.com/spring-projects/spring-framework/issues/32422";>#32422 Commits https://github.com/spring-projects/spring-framework/commit/df041ba032cceb9ca5c96214fe238b91c3f94f63";>df041ba Release v5.3.33 https://github.com/spring-projects/spring-framework/commit/297cbae2990e1413537c55845a7e0ea0ffd9f9bb";>297cbae Extract reusable checkSchemeAndPort method https://github.com/spring-projects/spring-framework/commit/274fba47f3b15bc12c8d81571c68987989f812e8";>274fba4 Additional unit tests for operations on empty UriTemplate https://github.com/spring-projects/spring-framework/commit/5dfec09edd62be011bbdbfd4e225f89b1e750311";>5dfec09 Allow UriTemplate to be built with an empty template https://github.com/spring-projects/spring-framework/commit/5056e8cbfb2f22204a4227b335291d17f629dfcb";>5056e8c Upgrade to Reactor 2020.0.42 https://github.com/spring-projects/spring-framework/commit/4566e8685d4baa41a6df4d6815ddc5579c4db073";>4566e86 Polishing https://github.com/spring-projects/spring-framework/commit/1b84f970dee1cce4c4fbf16ae8a90f17c5c6b12c";>1b84f97 Disable external Javadoc URLs not supported on JDK 8 https://github.com/spring-projects/spring-framework/commit/41bc43b03377b33d8182a7aab30d34a29fba9471";>41bc43b Build KDoc against 5.3.x Spring Framework Javadoc https://github.com/spring-projects/spring-framework/commit/915d5bddeaf189b9b638cc3440435291390dfabd";>915d5bd Polishing https://github.com/spring-projects/spring-framework/commit/dc86feaeb6571bfffd594412fc409ba305aff316";>dc86fea Remove IOException that's not thrown from Javadoc Additional commits viewable in https://github.com/spring-projects/spring-framework/compare/v5.3.32...v5.3.33";>compare view [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of
Re: [PR] Bump guava.version from 33.0.0-jre to 33.1.0-jre (logging-log4j2)
github-actions[bot] merged PR #2377: URL: https://github.com/apache/logging-log4j2/pull/2377 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Add Logback's throwable-consuming semantics as an option (logging-log4j2)
ppkarwasz commented on issue #2363: URL: https://github.com/apache/logging-log4j2/issues/2363#issuecomment-1997240044 @SeasonPanPan, As Volkan mentioned, solving your migration issues require 3 ingredients that we will try to incorporate into `2.24.0`: - [ ] #2381 - [ ] #2379 - [ ] #2380 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump org.springframework:spring-framework-bom from 5.3.32 to 5.3.33 [logging-log4j-audit-sample]
github-actions[bot] merged PR #43: URL: https://github.com/apache/logging-log4j-audit-sample/pull/43 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
rocketraman commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-1997613964 > I think this is related to [[apache/logging-log4j2#2213](https://github.com/apache/logging-log4j2/issues/2213)]. @vy It seems so, but I'm unsatisfied by the answers in the [discussion](https://github.com/apache/logging-log4j2/discussions/2214). Let me see if I can illustrate my use case with a generic example. Assume we have this setup: ``` class T { val log = logger() val r: R fun doSomethingInThread() { r.doSomethingOnResource() log.info { "bar" } } } class R { val log = logger() fun doSomethingOnResource() { log.info { "foo" } } } ``` `T` represents some kind of thread. It could be an HTTP request thread for example. So we have some diagnostic context related to that thread, say a request id. `R` represents some kind of resource used by `T`. It could be a state machine or a physical resource or whatever. There is some diagnostic context related to this resource, say a resource name or id. Inside `doSomethingOnResource` when logging "foo", both the thread and resource diagnostic contexts are relevant. However, inside `doSomethingInThread` i.e. the "bar" log, only the thread context is relevant. If `doSomethingOnResource` were to set the context for the resource in the `ThreadContext` before the `foo` log, then the `bar` log would also show the resource context, which would be incorrect. The thread or coroutine attached context works well for `T` but doesn't work well at all for `R`, which is used within the thread of `T`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
vy commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-1997814563 @rocketraman, AFAIC, the problem is the lack of a dynamically scoped variable (you might be familiar with this concept if you have ever used a Lisp dialect), and hence, we use the one closest to that: a thread-local one. Imagine `ThreadContext` is a [`ScopedValue`](https://docs.oracle.com/en/java/javase/21/docs/api/java.base/java/lang/ScopedValue.html). Your `withContextMap(map: Map, block: () -> T)` could simply be represented as `ThreadContext.runWhere("mdcKey", "mdcVal", doStuff())`. Am I missing something? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[I] Remove deprecated code for 3.0 (logging-log4net)
erikmav opened a new issue, #125: URL: https://github.com/apache/logging-log4net/issues/125 There are numerous parts of the code that are marked with [Deprecated] attributes. Additionally there is code that may or may not any longer be in use, such as NDC (src/log4net/NDC.cs). Ideally with the major version change the deprecations should be removed. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Bump com.google.guava:guava from 33.0.0-jre to 33.1.0-jre [logging-log4j-audit]
dependabot[bot] opened a new pull request, #129: URL: https://github.com/apache/logging-log4j-audit/pull/129 Bumps [com.google.guava:guava](https://github.com/google/guava) from 33.0.0-jre to 33.1.0-jre. Release notes Sourced from https://github.com/google/guava/releases";>com.google.guava:guava's releases. 33.1.0 Request for Android users If you know of Guava Android users who have not yet upgraded to at least the previous release https://github.com/google/guava/releases/tag/v33.0.0";>33.0.0, please encourage them to do so. Starting with that version, we are experimenting with including Java 8+ APIs in guava-android. Before we commit to adding such APIs, we want as much testing as we can get: If we later expose a set of Java 8+ APIs and then discover that they break users, we won't want to remove them, as the removal would break users, too. MavenJar files https://repo1.maven.org/maven2/com/google/guava/guava/33.1.0-jre/guava-33.1.0-jre.jar";>33.1.0-jre.jar https://repo1.maven.org/maven2/com/google/guava/guava/33.1.0-android/guava-33.1.0-android.jar";>33.1.0-android.jar Guava requires https://github.com/google/guava/wiki/UseGuavaInYourBuild#what-about-guavas-own-dependencies";>one runtime dependency, which you can download here: https://repo1.maven.org/maven2/com/google/guava/failureaccess/1.0.1/failureaccess-1.0.1.jar";>failureaccess-1.0.1.jar Javadoc http://guava.dev/releases/33.1.0-jre/api/docs/";>33.1.0-jre http://guava.dev/releases/33.1.0-android/api/docs/";>33.1.0-android JDiff http://guava.dev/releases/33.1.0-jre/api/diffs/";>33.1.0-jre vs. 33.0.0-jre http://guava.dev/releases/33.1.0-android/api/diffs/";>33.1.0-android vs. 33.0.0-android http://guava.dev/releases/33.1.0-android/api/androiddiffs/";>33.1.0-android vs. 33.1.0-jre Changelog Updated our Error Prone dependency to 2.26.1, which includes a JPMS-ready jar of annotations. If you use the Error Prone annotations in a modular build of your own code, you may need to https://github.com/google/error-prone/releases/tag/v2.26.1";>add a requires line for them. (d48c6dfbb8, c6e91c498ced26631029d1bdfdb9154d4a217368) base: Added a Duration overload for Suppliers.memoizeWithExpiration. (76e46ec35b) base: Deprecated the remaining two overloads of Throwables.propagateIfPossible. They won't be deleted, but we recommend migrating off them. (cf86414a87) cache: Fixed a bug that could cause https://redirect.github.com/google/guava/pull/6851#issuecomment-1931276822";>false "recursive load" reports during refresh. (0e1aebf73e) graph: Changed the return types of transitiveClosure() and reachableNodes() to Immutable* types. reachableNodes() already returned an immutable object (even though that was not reflected in the declared return type); transitiveClosure() used to return a mutable object. The old signatures remain available, so this change does not break binary compatibility. (09e655f6c1) graph: Changed the behavior of views returned by graph accessor methods that take a graph element as input: They now throw IllegalStateException when that element is removed from the graph. (8dca776341) hash: Optimized Checksum-based hash functions for Java 9+. (afb35a5d1b) testing: Exposed FakeTicker Duration methods to Android users. (f346bbb6a7) util.concurrent: Deprecated the constructors of UncheckedExecutionException and ExecutionError that don't accept a cause. We won't remove these constructors, but we recommend migrating off them, as users of those classes often assume that instances will contain a cause. (1bb3c4386b) util.concurrent: Improved the correctness of racy accesses for J2ObjC users. (d3232b71ce) Commits See full diff in https://github.com/google/guava/commits";>compare view [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been m com.google.guava guava 33.1.0-jre 33.1.0-android
Re: [PR] Bump com.google.guava:guava from 33.0.0-jre to 33.1.0-jre [logging-log4j-audit]
github-actions[bot] merged PR #129: URL: https://github.com/apache/logging-log4j-audit/pull/129 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Make location computation and message formatting more lazy (logging-log4j2)
vy commented on code in PR #2329: URL: https://github.com/apache/logging-log4j2/pull/2329#discussion_r1525178892 ## log4j-1.2-api/src/main/java/org/apache/log4j/bridge/LogEventWrapper.java: ## @@ -109,12 +110,17 @@ public Instant getInstant() { } @Override -public StackTraceElement getSource() { +public @Nullable StackTraceElement peekSource() { final LocationInfo info = event.getLocationInformation(); return new StackTraceElement( info.getClassName(), info.getMethodName(), info.getFileName(), Integer.parseInt(info.getLineNumber())); } +@Override Review Comment: Shouldn't this also be annotated with `@Nullable` too? (Applies to other `getSource()` changes delegating to `peekSource()`.) ## log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MementoLogEvent.java: ## @@ -72,50 +73,37 @@ public MementoLogEvent(final LogEvent event) { if (instant.getEpochMillisecond() == 0 && message instanceof TimestampMessage) { instant.initFromEpochMilli(((TimestampMessage) message).getTimestamp(), 0); } -contextData = memento(event.getContextData()); +contextData = mementoOfContextData(event.getContextData()); contextStack = event.getContextStack(); -source = includeLocation ? event.getSource() : null; +source = includeLocation ? event.getSource() : event.peekSource(); threadName = event.getThreadName(); threadId = event.getThreadId(); threadPriority = event.getThreadPriority(); thrown = event.getThrown(); thrownProxy = event.getThrownProxy(); } -public MementoLogEvent(final LogEvent event, final boolean includeLocation) { -loggerFqcn = event.getLoggerFqcn(); -loggerName = event.getLoggerName(); -instant.initFrom(event.getInstant()); -nanoTime = event.getNanoTime(); -level = event.getLevel(); -marker = event.getMarker(); -locationRequired = includeLocation; -endOfBatch = event.isEndOfBatch(); -message = mementoOfMessage(event); -if (instant.getEpochMillisecond() == 0 && message instanceof TimestampMessage) { -instant.initFromEpochMilli(((TimestampMessage) message).getTimestamp(), 0); +private static ReadOnlyStringMap mementoOfContextData(final ReadOnlyStringMap readOnlyMap) { +if (readOnlyMap instanceof final StringMap stringMap && !stringMap.isFrozen()) { +final StringMap data = ContextDataFactory.createContextData(readOnlyMap); +data.freeze(); +return data; } -contextData = memento(event.getContextData()); -contextStack = event.getContextStack(); -source = includeLocation ? event.getSource() : null; -threadName = event.getThreadName(); -threadId = event.getThreadId(); -threadPriority = event.getThreadPriority(); -thrown = event.getThrown(); -thrownProxy = event.getThrownProxy(); +// otherwise immutable +return readOnlyMap; } -@Override -public LogEvent toImmutable() { -return this; +private static Message mementoOfMessage(final LogEvent event) { +final Message message = event.getMessage(); +if (message instanceof LoggerNameAwareMessage) { +((LoggerNameAwareMessage) message).setLoggerName(event.getLoggerName()); +} +return message instanceof final ReusableMessage reusable ? reusable.memento() : message; Review Comment: _[I know this code block is not actually changed.]_ When the message is not a reusable one, we are assuming it to be immutable. Is this a valid assumption? I would have actually expected a `memento()` (or `freeze()`?) method on the `Message` contract... (Maybe I am not able to see the implications of this.) ## log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MementoLogEvent.java: ## @@ -72,50 +73,37 @@ public MementoLogEvent(final LogEvent event) { if (instant.getEpochMillisecond() == 0 && message instanceof TimestampMessage) { instant.initFromEpochMilli(((TimestampMessage) message).getTimestamp(), 0); } -contextData = memento(event.getContextData()); +contextData = mementoOfContextData(event.getContextData()); contextStack = event.getContextStack(); -source = includeLocation ? event.getSource() : null; +source = includeLocation ? event.getSource() : event.peekSource(); threadName = event.getThreadName(); threadId = event.getThreadId(); threadPriority = event.getThreadPriority(); thrown = event.getThrown(); thrownProxy = event.getThrownProxy(); } -public MementoLogEvent(final LogEvent event, final boolean includeLocation) { -loggerFqcn = event.getLoggerFqcn(); -loggerName = event.g
Re: [I] Improve logging context integration [logging-log4j-kotlin]
rocketraman commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-1998055009 > Am I missing something? @vy Yes, I think so. Or I am :-) If you look back at my example, logging in `R` is not (only) *thread-scoped*, it is both *thread-scoped* AND *class-scoped*. In other words, I want all logging in `R` to show the specific context of `R` as well as the thread-scoped context that is executing the code. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
rocketraman commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-1998067762 I think the ideal solution for this would look something like this, and could leverage the solution we come up with for https://github.com/apache/logging-log4j-kotlin/issues/36: ``` class R { val log = logger().withContext(...) fun doSomethingOnResource() { log.info { "foo" } } } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Make location computation and message formatting more lazy (logging-log4j2)
ppkarwasz commented on code in PR #2329: URL: https://github.com/apache/logging-log4j2/pull/2329#discussion_r1525347864 ## log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MementoLogEvent.java: ## @@ -72,50 +73,37 @@ public MementoLogEvent(final LogEvent event) { if (instant.getEpochMillisecond() == 0 && message instanceof TimestampMessage) { instant.initFromEpochMilli(((TimestampMessage) message).getTimestamp(), 0); } -contextData = memento(event.getContextData()); +contextData = mementoOfContextData(event.getContextData()); contextStack = event.getContextStack(); -source = includeLocation ? event.getSource() : null; +source = includeLocation ? event.getSource() : event.peekSource(); threadName = event.getThreadName(); threadId = event.getThreadId(); threadPriority = event.getThreadPriority(); thrown = event.getThrown(); thrownProxy = event.getThrownProxy(); } -public MementoLogEvent(final LogEvent event, final boolean includeLocation) { -loggerFqcn = event.getLoggerFqcn(); -loggerName = event.getLoggerName(); -instant.initFrom(event.getInstant()); -nanoTime = event.getNanoTime(); -level = event.getLevel(); -marker = event.getMarker(); -locationRequired = includeLocation; -endOfBatch = event.isEndOfBatch(); -message = mementoOfMessage(event); -if (instant.getEpochMillisecond() == 0 && message instanceof TimestampMessage) { -instant.initFromEpochMilli(((TimestampMessage) message).getTimestamp(), 0); +private static ReadOnlyStringMap mementoOfContextData(final ReadOnlyStringMap readOnlyMap) { +if (readOnlyMap instanceof final StringMap stringMap && !stringMap.isFrozen()) { +final StringMap data = ContextDataFactory.createContextData(readOnlyMap); +data.freeze(); +return data; } -contextData = memento(event.getContextData()); -contextStack = event.getContextStack(); -source = includeLocation ? event.getSource() : null; -threadName = event.getThreadName(); -threadId = event.getThreadId(); -threadPriority = event.getThreadPriority(); -thrown = event.getThrown(); -thrownProxy = event.getThrownProxy(); +// otherwise immutable +return readOnlyMap; } -@Override -public LogEvent toImmutable() { -return this; +private static Message mementoOfMessage(final LogEvent event) { +final Message message = event.getMessage(); +if (message instanceof LoggerNameAwareMessage) { +((LoggerNameAwareMessage) message).setLoggerName(event.getLoggerName()); +} Review Comment: Same as above: let's deal with it in another PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Make location computation and message formatting more lazy (logging-log4j2)
ppkarwasz commented on code in PR #2329: URL: https://github.com/apache/logging-log4j2/pull/2329#discussion_r1525347314 ## log4j-core/src/main/java/org/apache/logging/log4j/core/impl/MementoLogEvent.java: ## @@ -72,50 +73,37 @@ public MementoLogEvent(final LogEvent event) { if (instant.getEpochMillisecond() == 0 && message instanceof TimestampMessage) { instant.initFromEpochMilli(((TimestampMessage) message).getTimestamp(), 0); } -contextData = memento(event.getContextData()); +contextData = mementoOfContextData(event.getContextData()); contextStack = event.getContextStack(); -source = includeLocation ? event.getSource() : null; +source = includeLocation ? event.getSource() : event.peekSource(); threadName = event.getThreadName(); threadId = event.getThreadId(); threadPriority = event.getThreadPriority(); thrown = event.getThrown(); thrownProxy = event.getThrownProxy(); } -public MementoLogEvent(final LogEvent event, final boolean includeLocation) { -loggerFqcn = event.getLoggerFqcn(); -loggerName = event.getLoggerName(); -instant.initFrom(event.getInstant()); -nanoTime = event.getNanoTime(); -level = event.getLevel(); -marker = event.getMarker(); -locationRequired = includeLocation; -endOfBatch = event.isEndOfBatch(); -message = mementoOfMessage(event); -if (instant.getEpochMillisecond() == 0 && message instanceof TimestampMessage) { -instant.initFromEpochMilli(((TimestampMessage) message).getTimestamp(), 0); +private static ReadOnlyStringMap mementoOfContextData(final ReadOnlyStringMap readOnlyMap) { +if (readOnlyMap instanceof final StringMap stringMap && !stringMap.isFrozen()) { +final StringMap data = ContextDataFactory.createContextData(readOnlyMap); +data.freeze(); +return data; } -contextData = memento(event.getContextData()); -contextStack = event.getContextStack(); -source = includeLocation ? event.getSource() : null; -threadName = event.getThreadName(); -threadId = event.getThreadId(); -threadPriority = event.getThreadPriority(); -thrown = event.getThrown(); -thrownProxy = event.getThrownProxy(); +// otherwise immutable +return readOnlyMap; } -@Override -public LogEvent toImmutable() { -return this; +private static Message mementoOfMessage(final LogEvent event) { +final Message message = event.getMessage(); +if (message instanceof LoggerNameAwareMessage) { +((LoggerNameAwareMessage) message).setLoggerName(event.getLoggerName()); +} +return message instanceof final ReusableMessage reusable ? reusable.memento() : message; Review Comment: I started to look at these, but I got such a headache, that I decided to split the work in three parts: - location computation issues (calling `LogEvent#getSource` should prepare a log event for a thread jump), - thread data computation issues (I guess these should just be created, when the log event is created), - context data computation issues (probably this should be computed just before the jump), - message immutability issue (no message is immutable until `getFormattedMessage()` is called). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Centralize initialization in `Provider` class (logging-log4j2)
vy commented on code in PR #2374: URL: https://github.com/apache/logging-log4j2/pull/2374#discussion_r1525322283 ## log4j-api-test/src/test/java/org/apache/logging/log4j/spi/ThreadContextMapTest.java: ## @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j.spi; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.time.Duration; +import java.util.Properties; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.stream.Stream; +import org.apache.logging.log4j.util.PropertiesUtil; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; + +class ThreadContextMapTest { + +static Stream defaultMaps() { +return Stream.of( +new DefaultThreadContextMap(), +new CopyOnWriteSortedArrayThreadContextMap(), +new GarbageFreeSortedArrayThreadContextMap()); +} + +static Stream inheritableMaps() { +final Properties props = new Properties(); +props.setProperty("log4j2.isThreadContextMapInheritable", "true"); +final PropertiesUtil util = new PropertiesUtil(props); +return Stream.of( +new DefaultThreadContextMap(true, util), +new CopyOnWriteSortedArrayThreadContextMap(util), +new GarbageFreeSortedArrayThreadContextMap(util)); +} + +@ParameterizedTest +@MethodSource("defaultMaps") +void threadLocalNotInheritableByDefault(final ThreadContextMap contextMap) { +contextMap.put("key", "threadLocalNotInheritableByDefault"); +final ExecutorService executorService = Executors.newSingleThreadExecutor(); +try { +assertThat(executorService.submit(() -> contextMap.get("key"))) +.succeedsWithin(Duration.ofSeconds(1)) +.isEqualTo(null); +} finally { +executorService.shutdown(); +} Review Comment: This block is (almost) identical to the one below. You can implement a single `verifyThreadContextValueAccessedFromAnotherThread(ThreadContextMap contextMap, String expectedValue)` method instead and use it for both tests. ## log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java: ## @@ -163,6 +172,88 @@ static void lazyInit() { } } +/** + * Used to test the public {@link #getProvider()} method. + */ +static Provider selectProvider(final PropertiesUtil properties) { Review Comment: I presume you sufficiently covered this method with tests. :see_no_evil: ## log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java: ## @@ -43,40 +43,30 @@ public class DefaultThreadContextMap implements ThreadContextMap, ReadOnlyString private final boolean useMap; private final ThreadLocal> localMap; -private static boolean inheritableMap; - -static { -init(); -} - -// LOG4J2-479: by default, use a plain ThreadLocal, only use InheritableThreadLocal if configured. -// (This method is package protected for JUnit tests.) -static ThreadLocal> createThreadLocalMap(final boolean isMapEnabled) { -if (inheritableMap) { -return new InheritableThreadLocal>() { -@Override -protected Map childValue(final Map parentValue) { -return parentValue != null && isMapEnabled // -? Collections.unmodifiableMap(new HashMap<>(parentValue)) // -: null; -} -}; -} -// if not inheritable, return plain ThreadLocal with null as initial value -return new ThreadLocal<>(); -} - -static void init() { -inheritableMap = PropertiesUtil.getProperties().getBooleanProperty(INHERITABLE_MAP); -} - public DefaultThreadContextMap() { this(true); } +/** + * @deprecated Since 2.24.0 use the default constructor or {@link NoOpThreadContextMap} instead. Review Comment: Why don't we mark `NoOpThreadContextMap` as
Re: [PR] Make location computation and message formatting more lazy (logging-log4j2)
ppkarwasz commented on PR #2329: URL: https://github.com/apache/logging-log4j2/pull/2329#issuecomment-1998305974 > 1. Since the `Message` is already populated with a `loggerFqcn` and that is enough to resolve the `location` in the `LogEvent`, we don't need to resolve the location in `AbstractLogger`, right? Right. Having the FQCN of the logger class allows us to retrieve the location at any time or never. Previously the location was computed eagerly based on the result of `requiresLocation()`. This method can tell us if location information will be necessary, when the message will be logged. However it can not tell if the message will be logged at all. > 2. Due to to `peekSource()`, when a message gets copied elsewhere, `peekSource()` can be used to initialize the `source`, and reuse the already populated value, if present. Otherwise, `getSource()` can calculate it, if requested. This is the crux of this locate-at-the-end implementation, right? Partially, the original `getSource()` method was introduced when location was a binary choice: you could either compute it and log it or neither compute it nor log it. However the `LogBuilder#withLocation` method changed this: we can know the location without computing it. If we just keep the `getSource()` method and the user sets `includeLocation == false` on a component (which means "do not **compute** location), we need to be extra careful while calling `getSource`: ```java boolean oldIncludeLocation = event.isIncludeLocation(); event.setIncludeLocation(false); event.getSource(); event.setIncludeLocation(oldIncludeLocation); ``` The `peekSource` is a way to make the process easier. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Make location computation and message formatting more lazy (logging-log4j2)
ppkarwasz merged PR #2329: URL: https://github.com/apache/logging-log4j2/pull/2329 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump org.springframework:spring-framework-bom from 6.1.4 to 6.1.5 [logging-log4j-jakarta]
github-actions[bot] merged PR #24: URL: https://github.com/apache/logging-log4j-jakarta/pull/24 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Bump org.springframework:spring-framework-bom from 5.3.31 to 5.3.33 [logging-log4j-samples]
dependabot[bot] opened a new pull request, #119: URL: https://github.com/apache/logging-log4j-samples/pull/119 Bumps [org.springframework:spring-framework-bom](https://github.com/spring-projects/spring-framework) from 5.3.31 to 5.3.33. Release notes Sourced from https://github.com/spring-projects/spring-framework/releases";>org.springframework:spring-framework-bom's releases. v5.3.33 :star: New Features Extract reusable method for URI validations https://redirect.github.com/spring-projects/spring-framework/issues/32442";>#32442 Allow UriTemplate to be built with an empty template https://redirect.github.com/spring-projects/spring-framework/issues/32438";>#32438 Refine *HttpMessageConverter#getContentLength return value null safety https://redirect.github.com/spring-projects/spring-framework/issues/32332";>#32332 :lady_beetle: Bug Fixes AopUtils.getMostSpecificMethod does not return original method for proxy-derived method anymore https://redirect.github.com/spring-projects/spring-framework/issues/32369";>#32369 Better protect against concurrent error handling for async requests https://redirect.github.com/spring-projects/spring-framework/issues/32342";>#32342 Restore Jetty 10 compatibility in JettyClientHttpResponse https://redirect.github.com/spring-projects/spring-framework/issues/32337";>#32337 ContentCachingResponseWrapper no longer honors Content-Type and Content-Length https://redirect.github.com/spring-projects/spring-framework/issues/32322";>#32322 :notebook_with_decorative_cover: Documentation Build KDoc against 5.3.x Spring Framework Javadoc https://redirect.github.com/spring-projects/spring-framework/issues/32414";>#32414 :hammer: Dependency Upgrades Upgrade to Reactor 2020.0.42 https://redirect.github.com/spring-projects/spring-framework/issues/32422";>#32422 v5.3.32 :star: New Features Add CORS support for Private Network Access https://redirect.github.com/spring-projects/spring-framework/issues/31974";>#31974 Avoid early getMostSpecificMethod resolution in CommonAnnotationBeanPostProcessor https://redirect.github.com/spring-projects/spring-framework/issues/31969";>#31969 :lady_beetle: Bug Fixes Consistent parsing of user information in UriComponentsBuilder https://redirect.github.com/spring-projects/spring-framework/issues/32247";>#32247 QualifierAnnotationAutowireCandidateResolver.checkQualifier does identity checks when comparing arrays used as qualifier fields https://redirect.github.com/spring-projects/spring-framework/issues/32108";>#32108 Guard against multiple body subscriptions in Jetty and JDK reactive responses https://redirect.github.com/spring-projects/spring-framework/issues/32101";>#32101 Static resources caching issues with ShallowEtagHeaderFilter and Jetty caching directives https://redirect.github.com/spring-projects/spring-framework/issues/32051";>#32051 ChannelSendOperator.WriteBarrier race condition in request(long) method leads to response being dropped https://redirect.github.com/spring-projects/spring-framework/issues/32021";>#32021 Spring AOP does not propagate arguments for dynamic prototype-scoped advice https://redirect.github.com/spring-projects/spring-framework/issues/31964";>#31964 MergedAnnotation swallows IllegalAccessException for attribute method https://redirect.github.com/spring-projects/spring-framework/issues/31961";>#31961 CronTrigger hard-codes default ZoneId instead of participating in scheduler-wide Clock setup https://redirect.github.com/spring-projects/spring-framework/issues/31950";>#31950 MergedAnnotations finds duplicate annotations on method in multi-level interface hierarchy https://redirect.github.com/spring-projects/spring-framework/issues/31825";>#31825 PathEditor cannot handle absolute Windows paths with forward slashes https://redirect.github.com/spring-projects/spring-framework/issues/31728";>#31728 Include Hibernate's Query.scroll() in SharedEntityManagerCreator's queryTerminatingMethods set https://redirect.github.com/spring-projects/spring-framework/issues/31684";>#31684 TypeDescriptor does not check generics in equals method (for ConversionService caching) https://redirect.github.com/spring-projects/spring-framework/issues/31674";>#31674 Slow SpEL performance due to method sorting in ReflectiveMethodResolver https://redirect.github.com/spring-projects/spring-framework/issues/31665";>#31665 Jackson encoder releases resources in wrong order https://redirect.github.com/spring-projects/spring-framework/issues/31657";>#31657 WebSocketMessageBrokerStats has null stats for stompSubProtocolHandler since 5.3.2 https://redirect.github.com/spring-projects/spring-framework/issues/31642";>#31642 :notebook_with_decorative_cover: Documentation Document cron-vs-quartz parsing convention for dayOfWeek part in CronExpression https://redirect.github.com/sp
Re: [PR] Bump org.springframework:spring-framework-bom from 5.3.31 to 5.3.32 [logging-log4j-samples]
dependabot[bot] commented on PR #116: URL: https://github.com/apache/logging-log4j-samples/pull/116#issuecomment-1998707018 Superseded by #119. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump org.springframework:spring-framework-bom from 5.3.31 to 5.3.32 [logging-log4j-samples]
dependabot[bot] closed pull request #116: Bump org.springframework:spring-framework-bom from 5.3.31 to 5.3.32 URL: https://github.com/apache/logging-log4j-samples/pull/116 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullable and modernization part 2 (logging-log4net)
FreeAndNil commented on PR #123: URL: https://github.com/apache/logging-log4net/pull/123#issuecomment-1999156517 @erikmav did you see my comment regarding the missing test? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Bump actions/setup-java from 4.2.0 to 4.2.1 [logging-parent]
dependabot[bot] opened a new pull request, #137: URL: https://github.com/apache/logging-parent/pull/137 Bumps [actions/setup-java](https://github.com/actions/setup-java) from 4.2.0 to 4.2.1. Release notes Sourced from https://github.com/actions/setup-java/releases";>actions/setup-java's releases. v4.2.1 What's Changed Patch for java version file to accept it from any path by https://github.com/mahabaleshwars";>@mahabaleshwars in https://redirect.github.com/actions/setup-java/pull/610";>actions/setup-java#610 Full Changelog: https://github.com/actions/setup-java/compare/v4...v4.2.1";>https://github.com/actions/setup-java/compare/v4...v4.2.1 Commits https://github.com/actions/setup-java/commit/99b8673ff64fbf99d8d325f52d9a5bdedb8483e9";>99b8673 Patch for java version file (https://redirect.github.com/actions/setup-java/issues/610";>#610) See full diff in https://github.com/actions/setup-java/compare/5896cecc08fd8a1fbdfaf517e29b571164b031f7...99b8673ff64fbf99d8d325f52d9a5bdedb8483e9";>compare view [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot show ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump actions/setup-java from 4.2.0 to 4.2.1 [logging-parent]
github-actions[bot] merged PR #137: URL: https://github.com/apache/logging-parent/pull/137 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Remove deprecated code for 3.0 (logging-log4net)
FreeAndNil commented on issue #125: URL: https://github.com/apache/logging-log4net/issues/125#issuecomment-1999398844 I agree with removing the obsolete classes and methods. I'm not sure about NDC. Looking at the code it seems to be explicitly un-deprecated and there are many uses https://github.com/search?q=NDC.Push+path%3A*.cs+language%3AC%23&type=Code&ref=advsearch&l=C%23&l= The class is just a wrapper around ThreadContext.Stacks["NDC"], so the gain for removing it would be small against the anger we could cause ;-) When we DO want to remove it, we would do it later and first mak it (again) as deprecated. @fluffynuts what do you think? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump spring-framework.version from 6.1.4 to 6.1.5 (logging-log4j2)
github-actions[bot] merged PR #2382: URL: https://github.com/apache/logging-log4j2/pull/2382 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[I] Split off XML configuration into its own module or internal package (logging-log4j2)
ppkarwasz opened a new issue, #2383: URL: https://github.com/apache/logging-log4j2/issues/2383 Since `java.xml` is an **optional** module in Log4j Core 3.x, we need to protect the users from linkage errors like the one reported in [LOG4J2-3681](https://issues.apache.org/jira/browse/LOG4J2-3681). I see two way to do it: - creating a `log4j-config-xml` module like we did with YAML in #2142, - moving the implementation details into their own class/package. The first solution seems a little bit drastic to me: **most** users will have `java.xml` or they will not care about JPMS at all. Regarding the second one, as far as I know the only way to access optional dependencies that is compatible with all JVMs is to access the implementation via reflection. We might as well move the configuration factory to an internal package and leave only a public facade. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullable and modernization part 2 (logging-log4net)
erikmav commented on PR #123: URL: https://github.com/apache/logging-log4net/pull/123#issuecomment-1999873939 Misunderstood the comment. Working on it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[I] log4j-spring-boot gives error (logging-log4j2)
JyotiSathe opened a new issue, #2384: URL: https://github.com/apache/logging-log4j2/issues/2384 ## Description I have spring boot project, recently upgraded to version 3.2.2 from 3.1.0. We are using dependency "org.apache.logging.log4j:log4j-spring-boot" in our project. After upgrading to 3.2.2 we are getting below exception when started the the application. Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.springframework.boot.SpringApplication.(SpringApplication.java:202) On analyzing found that spring-boot-**3.1.0** imports dependency log4j-spring-boot with version **2.20.0** and spring-boot-**3.2.2** imports dependency log4j-spring-boot with version **2.21.1** If I use version 2.20.0 explicitly for log4j-spring-boot with spring-boot 3.2.2, application works as expected with warning in logs "Standard Commons Logging discovery in action with spring-jcl: please remove commons-logging.jar from classpath in order to avoid potential conflicts". As per initial observation it seems 2.21.1 version of log4j-spring-boot have some issue which throws NoClassDefFoundError. ## Configuration **Version:** 2.21.1 **JDK:** JDK-17 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Bump org.postgresql:postgresql from 42.7.2 to 42.7.3 [logging-log4j-audit]
dependabot[bot] opened a new pull request, #130: URL: https://github.com/apache/logging-log4j-audit/pull/130 Bumps [org.postgresql:postgresql](https://github.com/pgjdbc/pgjdbc) from 42.7.2 to 42.7.3. Release notes Sourced from https://github.com/pgjdbc/pgjdbc/releases";>org.postgresql:postgresql's releases. v42.7.3 Changes bump version to 42.7.4 https://github.com/davecramer";>@davecramer (https://redirect.github.com/pgjdbc/pgjdbc/issues/3164";>#3164) fix Issue boolean types not handled in SimpleQuery mode https://github.com/davecramer";>@davecramer (https://redirect.github.com/pgjdbc/pgjdbc/issues/3146";>#3146) The Gradle config enforces 17+ https://github.com/OrangeDog";>@OrangeDog (https://redirect.github.com/pgjdbc/pgjdbc/issues/3147";>#3147) Fix 2 changelog entry titles https://github.com/crunchyjohn";>@crunchyjohn (https://redirect.github.com/pgjdbc/pgjdbc/issues/3142";>#3142) chore: ensure CI jobs include tests for all the values of preferQueryMode, ssl, xa, gss https://github.com/vlsi";>@vlsi (https://redirect.github.com/pgjdbc/pgjdbc/issues/3137";>#3137) update jdbc website security page with latest security advisory https://github.com/davecramer";>@davecramer (https://redirect.github.com/pgjdbc/pgjdbc/issues/3135";>#3135) Changelog Sourced from https://github.com/pgjdbc/pgjdbc/blob/master/CHANGELOG.md";>org.postgresql:postgresql's changelog. [42.7.3] (2024-04-14 14:51:00 -0400) Changed chore: gradle config enforces 17+ [PR https://redirect.github.com/pgjdbc/pgjdbc/issues/3147";>#3147](https://redirect.github.com/pgjdbc/pgjdbc/pull/3147";>pgjdbc/pgjdbc#3147) Fixed fix: boolean types not handled in SimpleQuery mode [PR https://redirect.github.com/pgjdbc/pgjdbc/issues/3146";>#3146](https://redirect.github.com/pgjdbc/pgjdbc/pull/3146";>pgjdbc/pgjdbc#3146) make sure we handle boolean types in simple query mode support uuid as well handle all well known types in text mode and change else if to switch fix: released new versions of 42.2.29, 42.3.10, 42.4.5, 42.5.6, 42.6.2 to deal with NoSuchMethodError on ByteBuffer#position when running on Java 8 Commits https://github.com/pgjdbc/pgjdbc/commit/818953a2b30480ecc874f812e46fcb82d1a395fd";>818953a fix Issue # 3145 boolean types not handled in SimpleQuery mode (https://redirect.github.com/pgjdbc/pgjdbc/issues/3146";>#3146) https://github.com/pgjdbc/pgjdbc/commit/0e8ab636c505947dd1d3d32bdc0a7a2ee45f3545";>0e8ab63 The Gradle config enforces 17+ (https://redirect.github.com/pgjdbc/pgjdbc/issues/3147";>#3147) https://github.com/pgjdbc/pgjdbc/commit/b591b9fe8d9260b8ddae370323970eec26b1034b";>b591b9f Fix 2 changelog entry titles (https://redirect.github.com/pgjdbc/pgjdbc/issues/3142";>#3142) https://github.com/pgjdbc/pgjdbc/commit/81844e6f3f907b1045b1c87da6e9e48bda39d522";>81844e6 chore: ensure CI jobs include tests for all the values of preferQueryMode https://github.com/pgjdbc/pgjdbc/commit/2fada9ef4ec41b2c8a9ae12b431f57ca4b4e88aa";>2fada9e update security page (https://redirect.github.com/pgjdbc/pgjdbc/issues/3135";>#3135) https://github.com/pgjdbc/pgjdbc/commit/388f0276f77a3ab363b180c09e45ca48569c3281";>388f027 fix: typo password_encrypton -> password_encryption in the error message https://github.com/pgjdbc/pgjdbc/commit/9cde4f52b4b3a3f9fd36231240381e9d5e6a02a7";>9cde4f5 Update site for release of 42.7.2 (https://redirect.github.com/pgjdbc/pgjdbc/issues/3133";>#3133) https://github.com/pgjdbc/pgjdbc/commit/df14e53b3f38b7f1aad04f2dd5a0c9b4f45a6249";>df14e53 update version and last year modified See full diff in https://github.com/pgjdbc/pgjdbc/compare/REL42.7.2...REL42.7.3";>compare view [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- Dependabot commands and options You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR
Re: [PR] Bump org.postgresql:postgresql from 42.7.2 to 42.7.3 [logging-log4j-audit]
github-actions[bot] merged PR #130: URL: https://github.com/apache/logging-log4j-audit/pull/130 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] log4j-spring-boot gives error (logging-log4j2)
ppkarwasz closed issue #2384: log4j-spring-boot gives error URL: https://github.com/apache/logging-log4j2/issues/2384 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] log4j-spring-boot gives error (logging-log4j2)
ppkarwasz commented on issue #2384: URL: https://github.com/apache/logging-log4j2/issues/2384#issuecomment-291619 @JyotiSathe, Which Spring Boot 3.x artifact depends on `org.apache.logging.log4j:log4j-spring-boot`? The functionality of `log4j-spring-boot` is embedded into Spring Boot 3.x (cf. spring-projects/spring-boot#32578), so there is **no** need for an additional artifact. The `log4j-spring-boot` artifact only supports Spring Boot 2.x. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] log4j-spring-boot gives error (logging-log4j2)
JyotiSathe commented on issue #2384: URL: https://github.com/apache/logging-log4j2/issues/2384#issuecomment-2000110589 If I remove the dependency log4j-spring-boot then I get below exception. **ERROR StatusConsoleListener Resolver failed to lookup spring:spring.application.name java.lang.IllegalStateException: Unable to obtain Spring Environment from LoggerContext** at org.springframework.util.Assert.state(Assert.java:76) at org.springframework.boot.logging.log4j2.SpringEnvironmentLookup.lookup(SpringEnvironmentLookup.java:46) at org.apache.logging.log4j.core.lookup.StrLookup.evaluate(StrLookup.java:108) at org.apache.logging.log4j.core.lookup.Interpolator.evaluate(Interpolator.java:199) at org.apache.logging.log4j.core.lookup.StrSubstitutor.resolveVariable(StrSubstitutor.java:1183) at org.apache.logging.log4j.core.lookup.StrSubstitutor.substitute(StrSubstitutor.java:1098) at org.apache.logging.log4j.core.lookup.StrSubstitutor.substitute(StrSubstitutor.java:974) at org.apache.logging.log4j.core.lookup.StrSubstitutor.replace(StrSubstitutor.java:488) at org.apache.logging.log4j.core.config.plugins.visitors.PluginBuilderAttributeVisitor.visit(PluginBuilderAttributeVisitor.java:47) at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.injectFields(PluginBuilder.java:186) at org.apache.logging.log4j.core.config.plugins.util.PluginBuilder.build(PluginBuilder.java:122) at org.apache.logging.log4j.core.config.AbstractConfiguration.createPluginObject(AbstractConfiguration.java:1138) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1063) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055) at org.apache.logging.log4j.core.config.AbstractConfiguration.createConfiguration(AbstractConfiguration.java:1055) at org.apache.logging.log4j.core.config.AbstractConfiguration.doConfigure(AbstractConfiguration.java:664) at org.apache.logging.log4j.core.config.AbstractConfiguration.initialize(AbstractConfiguration.java:258) at org.apache.logging.log4j.core.config.AbstractConfiguration.start(AbstractConfiguration.java:304) at org.apache.logging.log4j.core.LoggerContext.setConfiguration(LoggerContext.java:621) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:694) at org.apache.logging.log4j.core.LoggerContext.reconfigure(LoggerContext.java:711) at org.apache.logging.log4j.core.LoggerContext.start(LoggerContext.java:253) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:155) at org.apache.logging.log4j.core.impl.Log4jContextFactory.getContext(Log4jContextFactory.java:47) at org.apache.logging.log4j.LogManager.getContext(LogManager.java:196) at org.apache.commons.logging.LogAdapter$Log4jLog.(LogAdapter.java:146) at org.apache.commons.logging.LogAdapter$Log4jAdapter.createLog(LogAdapter.java:113) at org.apache.commons.logging.LogAdapter.createLog(LogAdapter.java:95) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:67) at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:59) at org.springframework.boot.SpringApplication.(SpringApplication.java:202) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullable and modernization part 2 (logging-log4net)
FreeAndNil commented on PR #123: URL: https://github.com/apache/logging-log4net/pull/123#issuecomment-2000186414 Thanks a lot. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullable and modernization part 2 (logging-log4net)
FreeAndNil merged PR #123: URL: https://github.com/apache/logging-log4net/pull/123 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[I] SpringProfile arbiter fails without a Spring's environment (logging-log4j2)
ppkarwasz opened a new issue, #1783: URL: https://github.com/apache/logging-log4j2/issues/1783 ## Description In a Spring Boot application Log4j Core is initialized **at least** twice: - the first initialization is the static Log4j Core initialization (Spring's [`Environment`](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/core/env/Environment.html) is not available yet), - the second initialization is performed programmatically by Spring Boot as soon as it creates an `Environment`. It can use the same configuration file as the first one. On the other hand the builder of [`SpringProfileArbiter`](https://github.com/apache/logging-log4j2/blob/2.x/log4j-spring-boot/src/main/java/org/apache/logging/log4j/spring/boot/SpringProfileArbiter.java) returns `null` if no Spring `Environment` is present, which causes (handled) `NullPointerException`s in `AbstractConfiguration#processConditionals` or `AbstractConfiguration#processSelect`. Since the arbiter logic itself accepts a `null` environment, we should remove the following null-check: ```java environment = (Environment) loggerContext.getObject(Log4j2SpringBootLoggingSystem.ENVIRONMENT_KEY); if (environment == null) { LOGGER.warn("Cannot create Arbiter, no Spring Environment provided"); return null; } ``` The fix should be propagated to the [Spring Boot project](https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/logging/log4j2/SpringProfileArbiter.java). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] log4j-spring-boot gives error (logging-log4j2)
ppkarwasz commented on issue #2384: URL: https://github.com/apache/logging-log4j2/issues/2384#issuecomment-2000228751 @JyotiSathe, The stack trace you deleted seems like a problem with Spring Boot's version of our lookup. Unlike our version it fails if there is no environment. Such an occurrence is pretty natural. If you use a `log4j2.xml` configuration file it will be used twice: **before** an environment is available and **after** the environment is available. You can work around the problem by renaming the file to `log4j2-spring.xml` or using a Spring arbiter. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Nullability and modernization updates, part 3 (logging-log4net)
erikmav opened a new pull request, #126: URL: https://github.com/apache/logging-log4net/pull/126 (no comment) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullability and modernization updates, part 3 (logging-log4net)
erikmav commented on PR #126: URL: https://github.com/apache/logging-log4net/pull/126#issuecomment-2000331267 For #124 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Remove deprecated code for 3.0 (logging-log4net)
fluffynuts commented on issue #125: URL: https://github.com/apache/logging-log4net/issues/125#issuecomment-2000341731 I agree - something marked `[Obsolete]` can go, something that still works, even if it's only for a few users, can stay. And we should be very judicial about deprecations - I'd much rather keep the library useful for as many people as possible, so even if some part looks unused, if it works, leave it in until there's no other option but to lose it. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullability and modernization updates, part 3 (logging-log4net)
erikmav commented on PR #126: URL: https://github.com/apache/logging-log4net/pull/126#issuecomment-2000343172 @FreeAndNil Important to closely review `ReadOnlyPropertiesDictionary` and `PropertiesDictionary`. I selected the most backward compatible option, which is to coerce the `this[]` getter to avoid throwing KeyNotFoundException like Dictionary<> would (including a new test for the behavior). Also note that to avoid a double-indirection it would be ideal to change both to structs. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Nullability and modernization updates, part 3 (logging-log4net)
FreeAndNil commented on PR #126: URL: https://github.com/apache/logging-log4net/pull/126#issuecomment-2000364779 Thanks. I will review on Monday. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Remove deprecated code for 3.0 (logging-log4net)
FreeAndNil commented on issue #125: URL: https://github.com/apache/logging-log4net/issues/125#issuecomment-2000480599 OK. I would propose releasing the first 3.0.0 preview with the obsolete classes, so that we could deploy this version in our company and to other "willing" users. Then we remove those classes in the next preview for 3.0.0. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Centralize initialization in `Provider` class (logging-log4j2)
ppkarwasz commented on code in PR #2374: URL: https://github.com/apache/logging-log4j2/pull/2374#discussion_r1527118053 ## log4j-api/src/main/java/org/apache/logging/log4j/spi/DefaultThreadContextMap.java: ## @@ -43,40 +43,30 @@ public class DefaultThreadContextMap implements ThreadContextMap, ReadOnlyString private final boolean useMap; private final ThreadLocal> localMap; -private static boolean inheritableMap; - -static { -init(); -} - -// LOG4J2-479: by default, use a plain ThreadLocal, only use InheritableThreadLocal if configured. -// (This method is package protected for JUnit tests.) -static ThreadLocal> createThreadLocalMap(final boolean isMapEnabled) { -if (inheritableMap) { -return new InheritableThreadLocal>() { -@Override -protected Map childValue(final Map parentValue) { -return parentValue != null && isMapEnabled // -? Collections.unmodifiableMap(new HashMap<>(parentValue)) // -: null; -} -}; -} -// if not inheritable, return plain ThreadLocal with null as initial value -return new ThreadLocal<>(); -} - -static void init() { -inheritableMap = PropertiesUtil.getProperties().getBooleanProperty(INHERITABLE_MAP); -} - public DefaultThreadContextMap() { this(true); } +/** + * @deprecated Since 2.24.0 use the default constructor or {@link NoOpThreadContextMap} instead. + */ +@Deprecated public DefaultThreadContextMap(final boolean useMap) { +this(useMap, PropertiesUtil.getProperties()); +} + +DefaultThreadContextMap(final boolean useMap, final PropertiesUtil properties) { this.useMap = useMap; -this.localMap = createThreadLocalMap(useMap); +localMap = properties.getBooleanProperty(INHERITABLE_MAP) +? new InheritableThreadLocal>() { +@Override +protected Map childValue(final Map parentValue) { +return parentValue != null && useMap +? Collections.unmodifiableMap(new HashMap<>(parentValue)) +: null; +} +} +: new ThreadLocal>(); Review Comment: `localMap` must be a `ThreadLocal`, ;-) If `!useMap` I could probably set `localMap` to `null`, but our code (see `Provider`) does not use `DefaultThreadContextMap` in such a case. I leave the `useMap` parameter only for backward compatibility. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Add Logback's throwable-consuming semantics as an option (logging-log4j2)
SeasonPanPan commented on issue #2363: URL: https://github.com/apache/logging-log4j2/issues/2363#issuecomment-2001921715 @ppkarwasz @vy -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Centralize initialization in `Provider` class (logging-log4j2)
ppkarwasz commented on code in PR #2374: URL: https://github.com/apache/logging-log4j2/pull/2374#discussion_r1527192000 ## log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java: ## @@ -20,39 +20,135 @@ import java.net.URL; import java.util.Properties; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.simple.SimpleLoggerContextFactory; import org.apache.logging.log4j.status.StatusLogger; +import org.apache.logging.log4j.util.Constants; +import org.apache.logging.log4j.util.Lazy; +import org.apache.logging.log4j.util.LoaderUtil; +import org.apache.logging.log4j.util.PropertiesUtil; /** - * Model class for a Log4j 2 provider. The properties in this class correspond to the properties used in a - * {@code META-INF/log4j-provider.properties} file. Note that this class is automatically created by Log4j and should - * not be used by providers. + * Service class used to bind the Log4j API with an implementation. + * + * Implementors should register an implementation of this class with {@link java.util.ServiceLoader}. + * + * + * Deprecated: the automatic registration of providers from + * {@code META-INF/log4j-provider.properties} is supported for compatibility reasons. Support for this file will + * be dropped in a future version. + * */ public class Provider { +protected static final String CURRENT_VERSION = "2.6.0"; + /** * Property name to set for a Log4j 2 provider to specify the priority of this implementation. + * @deprecated since 2.24.0 */ +@Deprecated public static final String FACTORY_PRIORITY = "FactoryPriority"; + /** - * Property name to set to the implementation of {@link org.apache.logging.log4j.spi.ThreadContextMap}. + * Property name to set to the implementation of {@link ThreadContextMap}. + * @deprecated since 2.24.0 */ +@Deprecated public static final String THREAD_CONTEXT_MAP = "ThreadContextMap"; + /** - * Property name to set to the implementation of {@link org.apache.logging.log4j.spi.LoggerContextFactory}. + * Property name to set to the implementation of {@link LoggerContextFactory}. + * @deprecated since 2.24.0 */ +@Deprecated public static final String LOGGER_CONTEXT_FACTORY = "LoggerContextFactory"; -private static final Integer DEFAULT_PRIORITY = Integer.valueOf(-1); +/** + * System property used to specify the class name of the provider to use. + * @since 2.24.0 + */ +public static final String PROVIDER_PROPERTY_NAME = "log4j.provider"; + +// Bundled context map implementations +private static final String BASE = "org.apache.logging.log4j.internal.map."; + +/** + * Constant used to disable the {@link ThreadContextMap}. + * + * Warning: the value of this constant does not point to a concrete class name. + * + * @see #getThreadContextMap + */ +public static final String NO_OP_CONTEXT_MAP = BASE + "NoOp"; + +/** + * Constant used to select a web application-safe implementation of {@link ThreadContextMap}. + * + * This implementation only binds JRE classes to {@link ThreadLocal} variables. + * + * + * Warning: the value of this constant does not point to a concrete class name. + * + * @see #getThreadContextMap + */ +public static final String WEB_APP_CONTEXT_MAP = BASE + "WebApp"; + +/** + * Constant used to select a copy-on-write implementation of {@link ThreadContextMap}. + * + * Warning: the value of this constant does not point to a concrete class name. + * + * @see #getThreadContextMap + */ +public static final String COPY_ON_WRITE_CONTEXT_MAP = BASE + "CopyOnWrite"; + +/** + * Constant used to select a garbage-free implementation of {@link ThreadContextMap}. + * + * This implementation must ensure that common operations don't create new object instances. The drawback is + * the necessity to bind custom classes to {@link ThreadLocal} variables. + * + * + * Warning: the value of this constant does not point to a concrete class name. + * + * @see #getThreadContextMap + */ +public static final String GARBAGE_FREE_CONTEXT_MAP = BASE + "GarbageFree"; Review Comment: You are right, they could be `protected`. The reason I introduced these constants is: - half of these implementations are package-private. An implementation of `Provider` can not instantiate them, but `Provider` itself can. To use these context maps an implementation should: 1. implement `#getThreadContextMap` and return one of these special constants, 2. make a call to `super.createThreadContextMap()` in its `#createThreadContextMap` implementation. - I wanted to separate the characteristics of the context map, from the implementation. So the constant `WebApp`
Re: [PR] Centralize initialization in `Provider` class (logging-log4j2)
ppkarwasz commented on code in PR #2374: URL: https://github.com/apache/logging-log4j2/pull/2374#discussion_r1527192823 ## log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java: ## @@ -97,127 +217,266 @@ public String getVersions() { /** * Gets the priority (natural ordering) of this Provider. - * + * + * Log4j selects the highest priority provider. + * * @return the priority of this Provider */ public Integer getPriority() { return priority; } /** - * Gets the class name of the {@link org.apache.logging.log4j.spi.LoggerContextFactory} implementation of this - * Provider. + * Gets the class name of the {@link LoggerContextFactory} implementation of this Provider. * - * @return the class name of a LoggerContextFactory implementation + * @return the class name of a LoggerContextFactory implementation or {@code null} if unspecified. + * @see #loadLoggerContextFactory() */ public String getClassName() { -if (loggerContextFactoryClass != null) { -return loggerContextFactoryClass.getName(); -} -return className; +return loggerContextFactoryClass != null ? loggerContextFactoryClass.getName() : className; } /** - * Loads the {@link org.apache.logging.log4j.spi.LoggerContextFactory} class specified by this Provider. + * Loads the {@link LoggerContextFactory} class specified by this Provider. * - * @return the LoggerContextFactory implementation class or {@code null} if there was an error loading it + * @return the LoggerContextFactory implementation class or {@code null} if unspecified or a loader error occurred. + * @see #createLoggerContextFactory() */ public Class loadLoggerContextFactory() { if (loggerContextFactoryClass != null) { return loggerContextFactoryClass; } -if (className == null) { -return null; -} +final String className = getClassName(); final ClassLoader loader = classLoader.get(); -if (loader == null) { +// Support for deprecated {@code META-INF/log4j-provider.properties} format. +// In the remaining cases {@code loader == null}. +if (loader == null || className == null) { return null; } try { final Class clazz = loader.loadClass(className); if (LoggerContextFactory.class.isAssignableFrom(clazz)) { return clazz.asSubclass(LoggerContextFactory.class); +} else { +LOGGER.error( +"Class {} specified in {} does not extend {}", +className, +getUrl(), +LoggerContextFactory.class.getName()); } } catch (final Exception e) { -LOGGER.error("Unable to create class {} specified in {}", className, url.toString(), e); +LOGGER.error("Unable to create class {} specified in {}", className, getUrl(), e); } return null; } /** - * Gets the class name of the {@link org.apache.logging.log4j.spi.ThreadContextMap} implementation of this Provider. - * + * Extension point for providers to create a {@link LoggerContextFactory}. + * @since 2.24.0 + */ +protected LoggerContextFactory createLoggerContextFactory() { Review Comment: This is actually one of the two methods that implementations should implement. Due to the long history of the class, there are other methods: - `#getClassName()` gives the name of the class, but then Log4j API must guess the classloader to use to load it, - `#loadLoggerContextFactory()` returns a class, but unless I am mistaken JPMS will not allow Log4j API to instantiate the class unless it is `public` and in an exported package, I introduced this method so that implementations can instantiate it in any way they need. E.g. Log4j Core 3.x uses: ```java new Log4jContextFactory(instanceFactory); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Centralize initialization in `Provider` class (logging-log4j2)
ppkarwasz commented on code in PR #2374: URL: https://github.com/apache/logging-log4j2/pull/2374#discussion_r1527193084 ## log4j-api/src/main/java/org/apache/logging/log4j/spi/Provider.java: ## @@ -97,127 +217,266 @@ public String getVersions() { /** * Gets the priority (natural ordering) of this Provider. - * + * + * Log4j selects the highest priority provider. + * * @return the priority of this Provider */ public Integer getPriority() { return priority; } /** - * Gets the class name of the {@link org.apache.logging.log4j.spi.LoggerContextFactory} implementation of this - * Provider. + * Gets the class name of the {@link LoggerContextFactory} implementation of this Provider. * - * @return the class name of a LoggerContextFactory implementation + * @return the class name of a LoggerContextFactory implementation or {@code null} if unspecified. + * @see #loadLoggerContextFactory() */ public String getClassName() { -if (loggerContextFactoryClass != null) { -return loggerContextFactoryClass.getName(); -} -return className; +return loggerContextFactoryClass != null ? loggerContextFactoryClass.getName() : className; } /** - * Loads the {@link org.apache.logging.log4j.spi.LoggerContextFactory} class specified by this Provider. + * Loads the {@link LoggerContextFactory} class specified by this Provider. * - * @return the LoggerContextFactory implementation class or {@code null} if there was an error loading it + * @return the LoggerContextFactory implementation class or {@code null} if unspecified or a loader error occurred. + * @see #createLoggerContextFactory() */ public Class loadLoggerContextFactory() { if (loggerContextFactoryClass != null) { return loggerContextFactoryClass; } -if (className == null) { -return null; -} +final String className = getClassName(); final ClassLoader loader = classLoader.get(); -if (loader == null) { +// Support for deprecated {@code META-INF/log4j-provider.properties} format. +// In the remaining cases {@code loader == null}. +if (loader == null || className == null) { return null; } try { final Class clazz = loader.loadClass(className); if (LoggerContextFactory.class.isAssignableFrom(clazz)) { return clazz.asSubclass(LoggerContextFactory.class); +} else { +LOGGER.error( +"Class {} specified in {} does not extend {}", +className, +getUrl(), +LoggerContextFactory.class.getName()); } } catch (final Exception e) { -LOGGER.error("Unable to create class {} specified in {}", className, url.toString(), e); +LOGGER.error("Unable to create class {} specified in {}", className, getUrl(), e); } return null; } /** - * Gets the class name of the {@link org.apache.logging.log4j.spi.ThreadContextMap} implementation of this Provider. - * + * Extension point for providers to create a {@link LoggerContextFactory}. + * @since 2.24.0 + */ +protected LoggerContextFactory createLoggerContextFactory() { +final Class factoryClass = loadLoggerContextFactory(); +if (factoryClass != null) { +try { +return LoaderUtil.newInstanceOf(factoryClass); +} catch (final Exception e) { +LOGGER.error( +"Unable to create instance of class {} specified in {}", factoryClass.getName(), getUrl(), e); +} +} +LOGGER.warn("Falling back to {}", SimpleLoggerContextFactory.INSTANCE); +return SimpleLoggerContextFactory.INSTANCE; +} + +/** + * @return A lazily initialized logger context factory + * @since 2.24.0 + */ +public final LoggerContextFactory getLoggerContextFactory() { Review Comment: I wanted to stress out the `LoggerContextFactory` is a singleton. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Centralize initialization in `Provider` class (logging-log4j2)
ppkarwasz commented on code in PR #2374: URL: https://github.com/apache/logging-log4j2/pull/2374#discussion_r1527196204 ## log4j-api/src/main/java/org/apache/logging/log4j/util/ProviderUtil.java: ## @@ -163,6 +172,88 @@ static void lazyInit() { } } +/** + * Used to test the public {@link #getProvider()} method. + */ +static Provider selectProvider(final PropertiesUtil properties) { Review Comment: I tested the externally observable behavior: 1. the `log4j.provider` system property creates a provider with the specified class name, 2. the `log4j2.loggerContextFactory` system property create a provider with the specified logger context factory class, 3. if more than one implementation is available, the implementation with highest `getPriority` wins. What happens in the remaining cases (multiple system properties set, typos in the names of properties) are in my opinion implementation details and we can change them at will without breaking the `#getProvider()` contract. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Add Logback's throwable-consuming semantics as an option (logging-log4j2)
ppkarwasz commented on issue #2363: URL: https://github.com/apache/logging-log4j2/issues/2363#issuecomment-2002079852 @SeasonPanPan, Thank you for your proposal. #2379 might be a little bit Log4j specific, but I can assign you #2380 if it interests you. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] 2214 - Add support for ScopedContext (logging-log4j2)
rgoers opened a new pull request, #2385: URL: https://github.com/apache/logging-log4j2/pull/2385 This adds support for a ScopedContext as requested in kotlin/#74 and similar to #2214 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
ppkarwasz commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-2002375125 > If you look back at my example, logging in `R` is not (only) _thread-scoped_, it is both _thread-scoped_ AND _class-scoped_. In other words, I want all logging in `R` to show the specific context of `R` in addition to the thread-scoped context that is executing the code. There are already two sources for context data: - the contents of the thread-bound context map, - the contents of the `` elements bound the logger in the configuration: ```lang-xml ``` Is this what you are missing? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Add Logback's throwable-consuming semantics as an option (logging-log4j2)
SeasonPanPan commented on issue #2363: URL: https://github.com/apache/logging-log4j2/issues/2363#issuecomment-2002400761 > @SeasonPanPan, > > Thank you for your proposal. #2379 might be a little bit Log4j specific, but I can assign you #2380 if it interests you. @ppkarwasz OK,assign to me -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Add Logback's throwable-consuming semantics as an option (logging-log4j2)
ppkarwasz commented on issue #2363: URL: https://github.com/apache/logging-log4j2/issues/2363#issuecomment-2002444711 Not sure how this works on Github. Maybe you need to comment on the issue, for me to be able to assign it to you. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Log messages with partially missing parameters (logging-log4j2)
SeasonPanPan commented on issue #2380: URL: https://github.com/apache/logging-log4j2/issues/2380#issuecomment-2002451427 I will work on this issue #2380 . -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
rocketraman commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-2002452904 @rgoers I think you missed the class-scoped (*not* thread-scoped) context in my example. @ppkarwasz Ah interesting -- if I could bind `Property` dynamically then yes, that would work. For example, lets say I have 3 instances of class R, all with different values of `resourceId`. They all use the same logger name, but each have a different `resourceId`. I haven't looked deeply but it doesn't seem there is any API for this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Log messages with partially missing parameters (logging-log4j2)
ppkarwasz commented on issue #2380: URL: https://github.com/apache/logging-log4j2/issues/2380#issuecomment-2002453940 Thanks -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[I] Enable building log4net with docker container (logging-log4net)
FreeAndNil opened a new issue, #127: URL: https://github.com/apache/logging-log4net/issues/127 Provide the following convenience for PMC members to review the project: ``` git checkout docker build -t log4net-builder . docker run log4net-builder ``` That is, a convenience to build a Docker image containing all necessary dependencies to be able to build the project an entry point to build the project using the created Docker image. Proposed by @vy -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
[PR] Enable building log4net with docker container #127 (logging-log4net)
FreeAndNil opened a new pull request, #128: URL: https://github.com/apache/logging-log4net/pull/128 Enable building log4net with docker container #127 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
rgoers commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-2002548717 @rocketraman I guess I am not grasping at all what you want. With my PR you can now do: ``` class T { private static final Logger log = LogManger.getLogger(T.class); R r = new R(); doSomethingInThread() { ScopedContext.newInstance().where("context", "thread").run(() -> { r.doSomethingOnResource(); log.info{ "bar"); }); } } class R { private static final Logger log = LogManger.getLogger(R.class); fun doSomethingOnResource() { log.info("context will be 'thread' here); ScooedContext.newInstance().where("context", "resource").run(() -> { log.info { "foo" }; )}; } } ``` so everything inside the run method, and only inside the run method contains the data. In the example above the value of context will vary depending on which ScopedContext you are executing in. Isn't this what you wanted? Note, that while the PR uses a ThreadLocal it has to do that to make it thread-safe. Each Thread has its own stack of contexts. Now it would be great if instead you could annotate the class or method with the scope but due to their limitations I am not sure how you could actually populate the context since properties associated with annotations have to be known at compile time. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
rocketraman commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-2002565293 @rgoers Yes, in my original post I proposed a method `withContextMap` that would be used in Kotlin the same way as `ScopedContext` (though its a bit nicer in Kotlin). > Now it would be great if instead you could annotate the class or method with the scope but due to their limitations I am not sure how you could actually populate the context since properties I think with some kind of LogBuilder-type API [this could be possible](https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-1998067762). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] Improve logging context integration [logging-log4j-kotlin]
rgoers commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-2002582832 @rocketraman Again, I don't understand. ScopedContext IS a builder. Each where method adds a new key/value pair to the context. The run and call methods are, in essence, the builders. Of course, that isn't strictly true since newInstance creates the object, but the ScopedContext cannot reallly be used for anything until run or call are called. Note: I very loosely used Java 21 ScopedValues for the API for this, although ScopedContext is quite a bit simpler IMO. The where method in scoped variables creates a new immutable ScopedValue.Carrier - I believe the JDK has gone a bit overboard in making things immutable. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Enable building log4net with docker container #127 (logging-log4net)
vy commented on code in PR #128: URL: https://github.com/apache/logging-log4net/pull/128#discussion_r1527612300 ## Dockerfile: ## @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# MAINTAINER Jan Friedrich + +FROM mono:latest + +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y wget \ + && apt-get install -y tree \ + && wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh \ + && chmod +x ./dotnet-install.sh \ + && ./dotnet-install.sh --channel 8.0 +ENV DOTNET_NOLOGO=true +ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true +ENV DOTNET_ROOT=/root/.dotnet +ENV PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools" + +ADD . /logging-log4net + +CMD ["/logging-log4net/docker-build.sh"] Review Comment: This doesn't work for me: ``` docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/logging-log4net/docker-build.sh": permission denied: unknown. ``` I guess the executable bit is not reflected. I am not gonna Google to try to figure out why, since I know you can do that too. I will appreciate it if you can fix this. In the worst case: ```suggestion CMD ["sh", "/logging-log4net/docker-build.sh"] ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
ppkarwasz commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1527614991 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { Review Comment: I believe that `ThreadContext` and `ScopedContext` should be **write-only**. As far as I see it, these are logging-only services. The presence of `get()` methods allows user to use these services to store and retrieve their thread-dependent data, which is in my opinion and **abuse** of the API. There are more proper ways to store data, e.g. in a servlet application the username should be stored in the `ServletRequest` attributes, not in `ThreadContext`. ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + *
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
rgoers commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1527626489 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { Review Comment: I have to disagree with this but here we are just expressing our own opinions. Your example would require passing the ServletRequest through many methods that have no business knowing what a ServletRequest is or that they are even running in a servlet, but do need to know who the user is. For example, I have plenty of code that is shared between REST requests and Kafka consumers. It is obviously very late to suggest that the ThreadContext be write only. FWIW, the enhancement going into SLF4J does something sort of similar to this but instead of having the scoped context completely separate there you still do MDC.get to fetch attributes from the scoped context. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsu
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
rgoers commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1527630234 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { +Renderable renderable = getContext().get(key); +if (renderable != null) { +return (T) renderable.getObject(); +} else { +return null; +} +} + +private final Map contextMap = new HashMap<>(); + +private ScopedContext(boolean inherit) { +Map parent = ScopedContext.getContext(); +if (inherit && !parent.isEmpty()) { +contextMap.putAll(parent); +} +} + +/** + * Add all the values in the specified Map to the ScopedContext being constructed. + * + * @param map The Map to add to the ScopedContext being constructed. + * @return the ScopedContext being constructed. + */ +public ScopedContext where(Map map) { +map.forEach(this::addObject); +return this; +} + +/** + * Adds a key/value pair to the ScopedContext being constructed. + * @param key
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
rgoers commented on PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#issuecomment-2002643187 @ppkarwasz For some reason I cannot reply to your original comment directly. > At a first glance, I would probably prefer to see a wrapper like this: > > public class ContextLogger implements Logger, CloseableThreadContext.Instance { > private final Logger delegate; > private final Map contextData; > ... > } This I could not agree to. It is a completely different paradigm. The ScopedContext creates attributes to be logged for a block of code across all the Loggers that may be encountered. What you propose here is a context for a single Logger. While that may be useful it is not the same thing at all and serves a completely different purpose. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
rgoers commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1527630234 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { +Renderable renderable = getContext().get(key); +if (renderable != null) { +return (T) renderable.getObject(); +} else { +return null; +} +} + +private final Map contextMap = new HashMap<>(); + +private ScopedContext(boolean inherit) { +Map parent = ScopedContext.getContext(); +if (inherit && !parent.isEmpty()) { +contextMap.putAll(parent); +} +} + +/** + * Add all the values in the specified Map to the ScopedContext being constructed. + * + * @param map The Map to add to the ScopedContext being constructed. + * @return the ScopedContext being constructed. + */ +public ScopedContext where(Map map) { +map.forEach(this::addObject); +return this; +} + +/** + * Adds a key/value pair to the ScopedContext being constructed. + * @param key
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
ppkarwasz commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1527614991 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { Review Comment: I believe that `ThreadContext` and `ScopedContext` should be **write-only**. The way I see it, these are logging-only services. The presence of `get()` methods allows user to use these services to store and retrieve their thread-dependent data, which is in my opinion and **abuse** of the API. There are more proper ways to store data, e.g. in a servlet application the username should be stored in the `ServletRequest` attributes, not in `ThreadContext`. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
rgoers commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1527643984 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { +Renderable renderable = getContext().get(key); +if (renderable != null) { +return (T) renderable.getObject(); +} else { +return null; +} +} + +private final Map contextMap = new HashMap<>(); + +private ScopedContext(boolean inherit) { +Map parent = ScopedContext.getContext(); +if (inherit && !parent.isEmpty()) { +contextMap.putAll(parent); +} +} + +/** + * Add all the values in the specified Map to the ScopedContext being constructed. + * + * @param map The Map to add to the ScopedContext being constructed. + * @return the ScopedContext being constructed. + */ +public ScopedContext where(Map map) { +map.forEach(this::addObject); +return this; +} + +/** + * Adds a key/value pair to the ScopedContext being constructed. + * @param key
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
rgoers commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1527643984 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { +Renderable renderable = getContext().get(key); +if (renderable != null) { +return (T) renderable.getObject(); +} else { +return null; +} +} + +private final Map contextMap = new HashMap<>(); + +private ScopedContext(boolean inherit) { +Map parent = ScopedContext.getContext(); +if (inherit && !parent.isEmpty()) { +contextMap.putAll(parent); +} +} + +/** + * Add all the values in the specified Map to the ScopedContext being constructed. + * + * @param map The Map to add to the ScopedContext being constructed. + * @return the ScopedContext being constructed. + */ +public ScopedContext where(Map map) { +map.forEach(this::addObject); +return this; +} + +/** + * Adds a key/value pair to the ScopedContext being constructed. + * @param key
Re: [I] log4j-spring-boot gives error (logging-log4j2)
JyotiSathe closed issue #2384: log4j-spring-boot gives error URL: https://github.com/apache/logging-log4j2/issues/2384 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [I] log4j-spring-boot gives error (logging-log4j2)
JyotiSathe commented on issue #2384: URL: https://github.com/apache/logging-log4j2/issues/2384#issuecomment-2003015836 Yes after removing log4j-spring-boot and renaming log4j-spring.xml issue is resolved. Thanks for the help. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
rgoers commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1527909612 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { +Renderable renderable = getContext().get(key); +if (renderable != null) { +return (T) renderable.getObject(); +} else { +return null; +} +} + +private final Map contextMap = new HashMap<>(); + +private ScopedContext(boolean inherit) { +Map parent = ScopedContext.getContext(); +if (inherit && !parent.isEmpty()) { +contextMap.putAll(parent); +} +} + +/** + * Add all the values in the specified Map to the ScopedContext being constructed. + * + * @param map The Map to add to the ScopedContext being constructed. + * @return the ScopedContext being constructed. + */ +public ScopedContext where(Map map) { +map.forEach(this::addObject); +return this; +} + +/** + * Adds a key/value pair to the ScopedContext being constructed. + * @param key
Re: [I] Improve logging context integration [logging-log4j-kotlin]
ppkarwasz commented on issue #71: URL: https://github.com/apache/logging-log4j-kotlin/issues/71#issuecomment-2003349991 I think we should discuss it in `dev@logging`. I started a [thread dedicated to this subject](https://lists.apache.org/thread/ossk8ckz4yy59z88l8hhbb3k87hbbk0r). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
ppkarwasz commented on PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#issuecomment-2003350474 I think we should discuss it in `dev@logging`. I started a [thread dedicated to this subject](https://lists.apache.org/thread/ossk8ckz4yy59z88l8hhbb3k87hbbk0r). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] 2214 - Add support for ScopedContext (logging-log4j2)
ppkarwasz commented on code in PR #2385: URL: https://github.com/apache/logging-log4j2/pull/2385#discussion_r1528224543 ## log4j-api/src/main/java/org/apache/logging/log4j/ScopedContext.java: ## @@ -0,0 +1,224 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to you under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.logging.log4j; + +import java.util.ArrayDeque; +import java.util.Collections; +import java.util.Deque; +import java.util.HashMap; +import java.util.Map; +import java.util.concurrent.Callable; +import java.util.function.Supplier; + +/** + * Context that can be used for data to be logged in a block of code. + * + * While this is influenced by ScopedValues from Java 21 it does not share the same API. While it can perform a + * similar function as a set of ScopedValues it is really meant to allow a block of code to include a set of keys and + * values in all the log events within that block. The underlying implementation must provide support for + * logging the ScopedContext for that to happen. + * + * The ScopedContext will not be bound to the current thread until either a run or call method is invoked. The + * contexts are nested so creating and running or calling via a second ScopedContext will result in the first + * ScopedContext being hidden until the call is returned. Thus the values from the first ScopedContext need to + * be added to the second to be included. + * + * @since 2.24.0 + */ +public class ScopedContext { + +private static final ThreadLocal>> scopedContext = new ThreadLocal<>(); + +/** + * Returns an immutable Map containing all the key/value pairs as Renderable objects. + * @return An immutable copy of the Map at the current scope. + */ +public static Map getContext() { +Deque> stack = scopedContext.get(); +if (stack != null && !stack.isEmpty()) { +return Collections.unmodifiableMap(stack.getFirst()); +} +return Collections.emptyMap(); +} + +private static void addScopedContext(Map contextMap) { +Deque> stack = scopedContext.get(); +if (stack == null) { +stack = new ArrayDeque<>(); +scopedContext.set(stack); +} +stack.addFirst(contextMap); +} + +private static void removeScopedContext() { +Deque> stack = scopedContext.get(); +if (stack != null) { +if (!stack.isEmpty()) { +stack.removeFirst(); +} +if (stack.isEmpty()) { +scopedContext.remove(); +} +} +} + +/** + * Return a new ScopedContext. + * @return the ScopedContext. + */ +public static ScopedContext newInstance() { +return newInstance(false); +} + +/** + * Return a new ScopedContext. + * @param inherit true if this context should inherit the values of its parent. + * @return the ScopedContext. + */ +public static ScopedContext newInstance(boolean inherit) { +return new ScopedContext(inherit); +} + +/** + * Return the key from the current ScopedContext, if there is one and the key exists. + * @param key The key. + * @return The value of the key in the current ScopedContext. + */ +@SuppressWarnings("unchecked") +public static T get(String key) { Review Comment: Yes, I believe it is a matter of taste and commodity. I am a little bit worried about users using `ThreadContext` for business-critical functionality, since a change of logging backend (e.g. from `log4j-core` to `log4j-to-jul`), might break that functionality. For example in #2374 I assumed that the `ThreadContextMap` implementation used by an implementation is strictly linked to the logger context implementation; since `java.util.logging` formatters don't support context data, `log4j-to-jul` might as well use no-op `ThreadContextMap`. Am I wrong? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apac
Re: [PR] Enable building log4net with docker container #127 (logging-log4net)
FreeAndNil commented on code in PR #128: URL: https://github.com/apache/logging-log4net/pull/128#discussion_r152831 ## Dockerfile: ## @@ -0,0 +1,35 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# MAINTAINER Jan Friedrich + +FROM mono:latest + +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y wget \ + && apt-get install -y tree \ + && wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh \ + && chmod +x ./dotnet-install.sh \ + && ./dotnet-install.sh --channel 8.0 +ENV DOTNET_NOLOGO=true +ENV DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true +ENV DOTNET_ROOT=/root/.dotnet +ENV PATH="$PATH:$DOTNET_ROOT:$DOTNET_ROOT/tools" + +ADD . /logging-log4net + +CMD ["/logging-log4net/docker-build.sh"] Review Comment: Thanks for the hint. The chmod +x was missing. For whatever reason this worked on my Docker Desktop install. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump org.apache.activemq:activemq-broker from 6.0.1 to 6.1.0 (logging-log4j2)
github-actions[bot] merged PR #2387: URL: https://github.com/apache/logging-log4j2/pull/2387 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Bump org.awaitility:awaitility from 4.2.0 to 4.2.1 (logging-log4j2)
github-actions[bot] merged PR #2386: URL: https://github.com/apache/logging-log4j2/pull/2386 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org
Re: [PR] Enable building log4net with docker container #127 (logging-log4net)
FreeAndNil commented on PR #128: URL: https://github.com/apache/logging-log4net/pull/128#issuecomment-2003614301 @vy I've updated the dockerfile, the scripts and https://github.com/apache/logging-log4net/blob/Feature/127-docker-build/doc/BUILDING.md Please take a look. @fluffynuts what is your opinion? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@logging.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org