Comments (4)
Thanks for this information, it's hopefully going to be useful to anyone else.
The fact is that Google doesn't really use log4j or logback, so there's been no effort internally to make any of this work. If you felt up to writing a new backend to make this less "janky", I'd happily review it. Backends are pretty minimal, so getting something hacky to work as proof of concept shouldn't be too hard.
LoggerConfig is a JDK thing. It's not really part of the Flogger API, it's a convenience class to prevent a common misuse of JDK loggers (logger.getLogger() returns a weakly referenced instance causing weird race conditions in which logging configuration can be lost). I see it's caused confusion (for which I apologize). I should have given it a name that makes it clearer it's not intended to support general logging configuration for any Flogger backend.
I have to confess to knowing next to nothing about logback though, so if you think that supporting it "properly" will require changing internal APIs, please let me know.
from flogger.
Maybe subjective, but feels cleaner to have direct backend to logback. Then also, not a high priority, as flogger->slf4j->logkback seems to work well. I am subscribing to this issue, so one day if it is resolved, I can clean the dependecies a bit :)
from flogger.
Some feedback on getting logback to work.
I adapted and fixed some bugs in this version. I doubt it is an ideal implementation especially since it's not implemented against the latest backend loading changes.
When it worked
It worked ok with simple classpaths -- it even worked alongside dropwizard. Reconfiguring loggers programatically via the LoggerConfig was not working with this approach however.
When it didn't
For testing scenarios certain logback class paths made it impossible to get the platform loaded. Controlling classpath traversal in a test with multiple rules is quite hard. The classpath contained multiple logback.xml's but I think the main issue was the classloading order. Debugging the issue did reveal the custom backend registration hooks were being called if I tried to control the classloading order -- but in practise the default backend classes were being used.
Just using the slf4j bridge seems to be the most reliable approach
I spent quite some time trying to get around it -- eventually I decided to try the slf4j bridge via logback. This works very well. As far as I can tell config from logback.xml
is propagating to JUL
and using the LoggerConfig
also works.
In test code I use this LevelChangePropagator
as a way to execute the init block reliably.
class AxsyConfigurator: LevelChangePropagator() {
init {
if(!SLF4JBridgeHandler.isInstalled()) {
LogManager.getLogManager().reset()
SLF4JBridgeHandler.install()
}
setResetJUL(true)
}
}
with this in logback.xml
<contextListener class="...logback.AxsyConfigurator"/>
The slf4j bridge works well, I don't know if there are any hidden costs in the bridging layer.
from flogger.
I've just looked at logback and it's licensed under the LGPL and EPL (simultaneously), but not ASL.
While it's still possible to have a Google project depend on software developed with the EPL (1.0) license, it's more work, so for now I've chosen to concentrate on a log4j2 backend right now (unless someone can give me a really compelling story as to why it's worth the additional effort to support logback first).
Obviously anyone else is welcome to support logback themselves if they so wish, but the reciprocity of the EPL license makes developing with inside Google more awkward.
from flogger.
Related Issues (20)
- Architecture diagram for flogger
- Extensibility How to HOT 9
- Better document Flogger's status (active, maintained, in use at Google) HOT 5
- Support for java.util.ResourceBundle HOT 9
- Add tags from thread context to log HOT 17
- Use java.time.Duration for atMostEvery in LoggingApi. HOT 2
- Flag --incompatible_disable_starlark_host_transitions will break Flogger in Bazel 7.0 HOT 6
- Release schedule?
- Default JavaDocs generated for Flogger confusingly suggest it's deprecated (it isn't). HOT 2
- How to handle ScopedLoggingContext for new Threads / ThreadPools? HOT 1
- Provide a log writer to produce JSON log items according to Elastic Common Schema HOT 8
- I don't believe ScopedLoggingContexts should obviously accept null "no-op" arguments. HOT 5
- Incorrect caller details logged with Flogger in spring boot HOT 2
- Error: 'JavaInfo' value has no field or method 'transitive_deps' HOT 5
- Error: 'JavaInfo' value has no field or method 'transitive_deps' HOT 5
- Next release HOT 2
- ThreadlocalRandom instead of ThreadLocal HOT 8
- java failed error executing Javac command from target //api:checks HOT 5
- test
- `LogData.getTemplateContext()` should be `@NullableDecl`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flogger.