Uploaded image for project: 'SLF4J'
  1. SLF4J
  2. SLF4J-526

Idea for fluent API improvement

    XMLWordPrintable

Details

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Major Major
    • 2.0.17
    • None
    • None
    • None

    Description

      I found current Fluent API design a bit hard to read for two reasons:

      • method names are too verbose
      • Slightly counter-intuitive to have arguments before the log message

       

      Especially the second issue, people (at least for me) found it hard to read as I need to twist my mind to find corresponding arguments before and after the message.

      imho it looks a bit better to provide alternatives like this (totally fine to keep the original form)

      logger.atDebug()
              .message("Temperature of {} rise from {} to {}" )
              .arg(country).arg(oldTemp).arg(newTemp).log();
      
      // equivalent to 
      
      logger.atDebug()
              .addArgument(country).addArgument(oldTemp).addArgument(newTemp)
              .log("Temperature of {} rise from {} to {}");
      
      // Compare to the old-style
      logger.debug("Temperature of {} rise from {} to {}", country, oldTemp, newTemp);
      

       

      Attachments

        Activity

          People

            ceki Ceki Gülcü
            adrianshum Adrian Shum
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated: