Last week I came a cross Googles FLogger-API and I really liked it.
Back in e(fx)clipse land I started to miss it but because introducing a dependency to other log-frameworks is not possible – I implemented our own fluent log API inspired by Flogger.
So how do you use it:
// if you have a logger Logger logger = LoggerCreator.createLogger( Sample.class ); FluentLogger flogger = FluentLogger.of( logger ); // if you use @Log @Inject @Log FluentLogger flogger; // Log something FluentLogContext debug = flogger.atDebug(); debug.log( "Hello World" ); debug.log( "Hello World with format %s", 10 ); debug.log( () -> "Lazy Hello World" ); debug.log( t -> "Lazy Hello World with Context" + t, o ); // Log with exception try { // ... } catch( Throwable l ) { flogger.atInfo().withException( t ).log( "Hello World" ); } // Throttle: Only log every 100 log statement flogger.atInfo().throttleByCount(100) .log( "Log every 100 time" ); // Throttle: Only log every minute flogger.atInfo().throttleByTime(1, TimeUnit.MINUTES) .log( "Log every minute" ); // Build your own condition fluent addition logger.atInfo().with( Throttle::new ).every( 100 ) .log( "Log every 100 time" )
It looks great!
just filed CQs to prepare using flogger from jgit, gerrit also wants to migrate. Will add libraries to orbit
A bit unrelated to this topic -but indeed related in the sense that this could be a nice addition to e(fx)clipse- to this topic: while researching for more examples and comparisons between the MVVM and other patterns I came across with the project: mvvmFX. One of the things that instantly caught my eye was their ModelWrapper class: https://github.com/sialcasa/mvvmFX/wiki/ModelWrapper.
I don‘t efxclipse needs to provide such a thing – just use the one from mvvmFX
Do I get it right, that flogger is (at least by now) a replacement of the complete logging toolchain? I.e. a project currently using slf4j and one of the available logging backends underneath will have to replace both of those by flogger, right?
Flogger yes, our API will delegate to slf4j, jul, log4j