We are currently using Flogger with JUL as backend. There is a new requirement to control log level based on some criteria in the current web request (we have a way to determine log level for different web requests). One brute force method is to wrap each log statement with a check for whether that log statement’s at<Level> is loggable for the web request.
Is there any way to achieve the requirement without modifying the log statements (or with minimal modification), short of implementing a custom logger?
We are currently using Flogger with JUL as backend. There is a new requirement to control log level based on some criteria in the current web request (we have a way to determine log level for different web requests). One brute force method is to wrap each log statement with a check for whether that log statement’s at<Level> is loggable for the web request.
Is there any way to achieve the requirement without modifying the log statements (or with minimal modification), short of implementing a custom logger?
--
You received this message because you are subscribed to the Google Groups "Flogger Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flogger-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/391f7835-e0e1-4c49-8644-98e4459f46c9n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/CAOqvkfYiG2kOhEsWpV_geyD9ncJh7RrBcO5CFAiRZL3mvVGxeQ%40mail.gmail.com.
Thanks, Chris and David for your responses.
To clarify, the requirement is to only customize the log level configuration for each web request. The log statements themselves would have fixed level that they are intended for.
In our code, class com.my.xyz.abc has this example code.
log.atInfo().log(“Info message”);A single application instance forwards incoming requests to multiple environments (say, Production and Test). It has a way of knowing target environment for each request. The application supports configuration that is conceptually as below.
Production:
Log-levels:
com.my.xyz.pqr: Fine
com.my.xyz.abc: Info
Test:
Log-levels:
com.my.xyz: Fine
When request is for Production environment, only the first log statement should be printed. When it is for Test environment, the first 2 log statements should be printed.
Brute force method is to modify each log statement like below.
If (webRequestLoggable(INFO)) {
log.atInfo().log(“Info message”);
}
Of course, the above will only work if the application is configured with logger com.my set to Finest! Cumbersome and not preferred at all, but the log messages will have the correct log level indicator.
David, you say the next release of Flogger will have the feature “Increase log level inside this request for just some set of classes/packages”. Does this map to my requirement? That is, some known thread local map of logger-name -> log-level will be supported and Flogger will use those levels as the overriding loggable levels for the duration of the request?
- MadhuTo view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/30472a05-1835-4155-8b08-c8ba05f0224an%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/CAOqvkfbP7AsnLbrndnJD%3DvEG%3DA9Mt700ouMxAx_R5BDT0Q2mQA%40mail.gmail.com.
=====Excerpt from my posting =====
David, you say the next release of Flogger will have the feature “Increase log level inside this request for just some set of classes/packages”. Does this map to my requirement? That is, some known thread local map of logger-name -> log-level will be supported and Flogger will use those levels as the overriding loggable levels for the duration of the request?
=====David's response =====
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/0f09147f-6c39-42a9-b4c7-115bb1728839n%40googlegroups.com.
David,As you suggested, I cloned the project and studied the source code. I have some questions.1) I have only used Maven to build my projects. It looks like a different build tool is used by Flogger. Can you give some instructions on how to build the project?2) I had made a simplistic assumption that log level map will work like simple thread-local data to be used by Flogger log statements. Looking at your example (in the previous post), I am not so sure. Please confirm if the following type of logic will work for me.MyResourceHandingMethod() {LoggingScope context = ScopedLoggingContext.getInstance().withNewScope().applyLogLevelMap(myLogLevelMap);Process request and prepare responsecontext.close();return response;}If the above will work, I can conveniently create context in request filter and close it in response filter (leaving the rest of my code base blissfully unaffected!).
--
You received this message because you are subscribed to the Google Groups "Flogger Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flogger-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/fcf80404-3f51-411f-a6c8-91d075c103aan%40googlegroups.com.
David,
I downloaded Bazel 4.0.0 and tried to build LOCAL-SNAPSHOT version of flogger. Here is the procedure I followed and the issues I faced. Please let me know if I am doing something fundamentally wrong.
Based on instruction in an older Flogger Discuss thread titled “How to build Flogger from source”, I executed the command “bazel build --javacopt='-Xlint:-options' …”
It failed towards the end (see below).
=====
Starting local Bazel server and connecting to it...
INFO: Analyzed 77 targets (133 packages loaded, 1263 targets configured).
INFO: Found 77 targets...
INFO: From Action google/flogger_javadoc.jar:
Creating destination directory: "tmp/"
INFO: From Action grpc/javadoc.jar:
Creating destination directory: "tmp/"
INFO: From Action api/api_javadoc.jar:
Creating destination directory: "tmp/"
INFO: From Action log4j/javadoc.jar:
Creating destination directory: "tmp/"
INFO: From Action api/system_backend_javadoc.jar:
Creating destination directory: "tmp/"
INFO: From Action slf4j/javadoc.jar:
Creating destination directory: "tmp/"
INFO: From Action log4j2/javadoc.jar:
Creating destination directory: "tmp/"
INFO: From Action api/testing_javadoc.jar:
Creating destination directory: "tmp/"
ERROR: /Users/mnarasim/IdeaProjects/flogger/tools/BUILD:21:16: Action tools/all_javadoc.jar failed: (Exit 1): bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox bash failed: error executing command /bin/bash -c ... (remaining 1 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
javadoc: error - Error fetching URL: https://google.github.io/guava/releases/24.1-jre/api/docs/
javadoc: error - Error fetching URL: https://google.github.io/truth/api/0.40/
javadoc: error - Error fetching URL: http://errorprone.info/api/latest/
javadoc: error - Error fetching URL: https://junit.org/junit4/javadoc/4.11/
Creating destination directory: "tmp/"
4 errors
INFO: Elapsed time: 668.182s, Critical Path: 630.64s
INFO: 256 processes: 156 internal, 44 darwin-sandbox, 56 worker.
FAILED: Build did NOT complete successfully
=====
In spite of the above errors, I could see that directories bazel-* had been created.
Not knowing anything better, I executed the following commands.
cd bazel-bin/api
mvn install -f api_pom.xml
mvn install -f system_backend_pom.xml
Both the above commands were successful, but said “No sources to compile”
I could see that LOCAL-SNAPSHOT jar files were created in the Maven cache directory.
~/.m2/repository/com/google/flogger/flogger contained another directory LOCAL-SNAPSHOT parallel to the one for 0.5.1.
Likewise, ~/.m2/repository/com/google/flogger/flogger-system-backend/LOCAL-SNAPSHOT was also created.
Both flogger-LOCAL-SNAPSHOT.jar and flogger-system-backend-LOCAL-SNAPSHOT.jar had no classes inside! Hence, my application build failed (with flogger version specified as LOCAL-SNAPSHOT in my pom.xml).
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/c313881a-9dce-4a1e-af2f-c3176ac9c6ban%40googlegroups.com.
com.google.common.flogger.backend.NoOpContextDataProvider.NoOpScopedLoggingContext.LazyLogger | Scoped logging contexts are disabled; no context data provider was installed.
To enable scoped logging contexts in your application, see the site-specific Platform class used to configure logging behaviour.
Default Platform: com.google.common.flogger.backend.system.DefaultPlatform
Thanks for all the help so far.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/6507dbf6-6631-4f50-8a75-3610f5024280n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/cf806fff-7e6a-48d2-aad9-06d99e89a1c3n%40googlegroups.com.
Hi David n all,My name is Pei. Madhu n I work on the same project where we are making dynamic log level productized...Madhu tried that successfully. I am pretty much using all the tips Madhu has given to me, but somehow still don't work. So I will try to document what I have done, hopefully your guys are experts, and know what I am missing.We are using:com.google.flogger:flogger:0.6com.google.flogger:flogger-grpc-context:0.6com.google.flogger:flogger-system-backend:0.5.1Question: does the flogger-system-backend needs to be 0.6 as well?
In our Java code:LogLevelMap logLevelMap = loggingUtil.getLogLevelMap(); // loggingUtil.getLogLevelMap() is our own utility to populate log levels of all appsfinal var loggingScope = ScopedLoggingContext.getInstance()//.newContext()//.withNewScope().newScope().withLogLevelMap(logLevelMap).install();And we close the context when the REST session is finishedQuestion: I saw newScope() is deprecated, replaced by newContext(), tried both, no difference. No surprise since newScope() is calling the later.
When starting our REST server, I use the following flag:java -jar target/service.jar -Dflogger.logging_context=com.google.common.flogger.grpc.GrpcContextDataProvider#getInstance
Question: we don't have gRPC use cases, all our business cases are from REST calls, do we still need to depend on grpc.GrpcContextDataProvider?
Instead of GrpcScopedLoggingContext, I also have tried a few other things, like:-Dflogger.logging_context=com.google.common.flogger.grpc.GrpcScopedLoggingContext#getInstance-Dflogger.logging_context=com.google.common.flogger.context.ScopedLoggingContext#getInstance-Dflogger.logging_context=com.google.common.flogger.backend.NoOpContextDataProvider#getInstanceBut all have the same warning when a REST call is processed:2021-06-16 23:04:07.791-0700 | GET | :PostmanRuntime/7.28.0:dev-pei:f65dfb1e-31a3-43a7-808f-413cf72e0278 | helidon-1 | | WARN | com.google.common.flogger.backend.NoOpContextDataProvider.NoOpScopedLoggingContext.LazyLogger | Scoped logging contexts are disabled; no context data provider was installed.To enable scoped logging contexts in your application, see the site-specific Platform class used to configure logging behaviour.Default Platform: com.google.common.flogger.backend.system.DefaultPlatformcom.google.common.flogger.LogSiteStackTrace: SMALLat com.google.common.flogger.backend.NoOpContextDataProvider$NoOpScopedLoggingContext.logWarningOnceOnly(NoOpContextDataProvider.java:60)at com.google.common.flogger.backend.NoOpContextDataProvider$NoOpScopedLoggingContext.access$100(NoOpContextDataProvider.java:45)at com.google.common.flogger.backend.NoOpContextDataProvider$NoOpScopedLoggingContext$1.install(NoOpContextDataProvider.java:73)at com.oracle.cx.communications.dx4c.fabric.utils.http.ContainerFilter.filter(ContainerFilter.java:72)at org.glassfish.jersey.server.ContainerFilteringStage.apply(ContainerFilteringStage.java:108)at org.glassfish.jersey.server.ContainerFilteringStage.apply(ContainerFilteringStage.java:44)at org.glassfish.jersey.process.internal.Stages.process(Stages.java:173)at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:247)at org.glassfish.jersey.internal.Errors$1.call(Errors.java:248)at org.glassfish.jersey.internal.Errors$1.call(Errors.java:244)
And dynamic log levels are not set properly.
From source code, quite a few classes have getInstance() to return ScopedLoggingContext.Builder, I am not confident that I have the right class and right methods get called...
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/65130551-843d-4347-9e94-f3ff8ec02c43n%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/6f999aee-47bc-4854-a128-193089718c8bn%40googlegroups.com.
Note that very soon Flogger will no longer require the system property to load services such as the GrpcContextDataProvider. An upcoming change will allow Flogger to use ServiceLoader to load services from jars that include the proper metadata, and the jar containing GrpcContextDataProvider will be updated to include that metadata. So all you'll need to do is put the jar containing GrpcContextDataProvider on the classpath and Flogger will load and use it automatically. If the system property is set, Flogger will attempt to use that rather than ServiceLoader.That change should be merged later this week I'm hoping, and I'd like to get a new release of Flogger including that change out in the next few weeks.On Tue, Jun 29, 2021 at 1:47 PM Peiyuan Zhou <pzhouc...@gmail.com> wrote:Hi David,We found out what is the problem, it is the command line argument position:java -jar target/service.jar -Dflogger.logging_context=com.google.common.flogger.grpc.GrpcContextDataProvider#getInstanceOnce we move -D option to java, then it works:java -Dflogger.logging_context=com.google.common.flogger.grpc.GrpcContextDataProvider#getInstance -jar target/service.jarSo seems -D option is for JVM and needs to be front.We like to explore how to pass -D flag in other options, as our deployment team have questions on how to set -D flag in their deployment descriptor script.We love to get your expert advice on some these options:1. How to set this property programmatically as part of logging initialization. If it is harmless, it can go to our server main initialization method.
2. Another option is to check for a way to provide JVM arguments through an environment variable
3. Or how to set -D flag property in the deployment descriptor script.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/CAHJY%3Dp7McC_ms%2B2ru8h%2BQxOq5DSi8%2BSMaHDWvUv9ePhP7vW%3Dvw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/82d25ac5-ca56-4ee7-94d7-fd1f359ce462n%40googlegroups.com.
I have 1 more problem about closing the logging context...Due to our business nature, and hence the way we code, our applications are all controlled at front, we don't have a common place to close the dynamic logging context at the end of a given transaction.So what we do is at the beginning of each transaction, before we open another logging context, we close the existing logging context if it is still not null.
I have 2 env to run/text our applications. And they behave differently, regarding the previous logging context.In one env, the previous/existing logging context is still there at the next REST call, so it is closed by calling close().While in my another test env, the previous context is null, assuming closed automatically by the time of next REST call comes in.I haven't figured out why behaves are different. Make it worse, in the first env, it was reported that log level of subsequent REST calls is stuck to the level of the first call. So dynamic logging stops working. I will login into the env to debug it today.
You received this message because you are subscribed to a topic in the Google Groups "Flogger Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/flogger-discuss/FFkyBuOtku4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to flogger-discu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flogger-discuss/c8ff0b40-c63a-435f-95be-5ff4a3b11cc8n%40googlegroups.com.