google / google/flogger

Configurable LogCallerFinder via system properties and other improvements

Open
#81 6 comments 1 reaction 0 assignees View on GitHub
P3
Dominant language
Java
Stars
1.5k
Forks
133
Avg merge
6m
Merged PRs (30d)
7

Description

Using `DefaultPlatform` one can configure `BackendFactory`, `LoggingContext`, and `Clock` via system properties, however `LogCallerFinder` remains set as `StackBasedCallerFinder` with no option to change that. I would like the ability added to configure the LogCallerFinder as well. This is certainly useful when one is writing custom backends, especially when it comes to those where naming your loggers using the stack doesn't make much sense. The property name could be `flogger.caller_finder` or something of the sort.

Also it would be nice to set the `resolveAttribute` method in `DefaultPlatform` to `public` as the functionality of dynamic configuration and extensibility via system properties seems quite useful and I find that I would like to utilize it for consistency and simplicity when writing dynamically extensible Flogger backends. An example of a useful case for this is where the library you are writing the backend for does not support disabling Levels and you want to make that functionality available through dynamically configured extensions instead of providing a single prescribed way.

I am currently resorting to some less than preferable reflection tricks when doing all of the above in my Fluentd backend as seen here:
https://github.com/agsimeonov/flogger-fluentd-backend/blob/master/src/main/java/com/agsimeonov/flogger/backend/fluentd/FluentdBackendFactory.java

The only other option I see is writing my own `Platform` but then I would have to resort to classpath tricks to provide it through a custom `PlatformProvider` which also doesn't seem like a particularly pleasant option. I would also have to rewrite a lot of perfectly good code already present in `DefaultPlatform` simply to add a tiny bit of extensibility.

Last but not least, and maybe I need to create a separate issue for this as it is not related to the above, I would like to talk about `Metadata` and `SimpleMessageFormatter`. The code here https://github.com/google/flogger/blob/master/api/src/main/java/com/google/common/flogger/backend/SimpleMessageFormatter.java#L85 appends what is deemed unknown metadata to the log message and there is no way of doing anything fancier with this unknown metadata instead. I propose creating a handler for it that could be used to extend what can be done with it. This is now becoming especially useful when we consider that the `with()` functionality `GoogleLogger` provided is now merged into `FluentLogger`. More people are certainly starting to use Metadata so there needs to be a better way to handle the formatting of this Metadata. Now I know one can simply create their own `MessageBuilder` however SimpleMessageFormatter does a lot of things great and one might want to expand upon it rather than completely rewrite it.

If all of or at least a part of all of this seems reasonable I can certainly contribute with a pull request. Let me know what you guys think. I love what you have done with Flogger and I am certainly open to other ideas/suggestions as well. Keep it up!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.