Fluent-Log API landed in e(fx)clipse


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" )
Advertisements
This entry was posted in e(fx)clipse. Bookmark the permalink.

6 Responses to Fluent-Log API landed in e(fx)clipse

  1. Marcelo says:

    It looks great!

  2. Matthias Sohn says:

    just filed CQs to prepare using flogger from jgit, gerrit also wants to migrate. Will add libraries to orbit

  3. Marcelo says:

    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.

  4. 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?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.