Class FluentLogger2


  • public final class FluentLogger2
    extends AbstractLogger<FluentLogger2.Api>
    The default implementation of AbstractLogger which returns the basic LoggingApi and uses the default parser and system configured backend.

    Note that when extending the logging API or specifying a new parser, you will need to create a new logger class (rather than extending this one). Unlike the LogContext class, which must be extended in order to modify the logging API, this class is not generified and thus cannot be modified to produce a different logging API.

    The choice to prevent direct extension of loggers was made deliberately to ensure that users of a specific logger implementation always get the same behavior.

    • Constructor Detail

      • FluentLogger2

        public FluentLogger2​(LoggerBackend backend)
        Creates a new fluent logger instance with the specified backend.
        API Note:
        This constructor used to be package-private in the original Flogger implementation. This, in turn, required reflection-based creation of new instances of this class in io.spine.logging.JvmLoggerFactoryKt. Now, as we aggregate the Flogger code, we open the constructor for simplicity.
    • Method Detail

      • forEnclosingClass

        public static FluentLogger2 forEnclosingClass()
        Returns a new logger instance which parses log messages using printf format for the enclosing class using the system default logging backend.
      • at

        public FluentLogger2.Api at​(Level level)
        Description copied from class: AbstractLogger
        Returns a fluent logging API appropriate for the specified log level.

        If a logger implementation determines that logging is definitely disabled at this point then this method is expected to return a "no-op" implementation of that logging API, which will result in all further calls made for the log statement to being silently ignored.

        A simple implementation of this method in a concrete subclass might look like:

        
         boolean isLoggable = isLoggable(level);
         boolean isForced = Platform.shouldForceLogging(getName(), level, isLoggable);
         return (isLoggable | isForced) ? new SubContext(level, isForced) : NO_OP;
         
        where NO_OP is a singleton, no-op instance of the logging API whose methods do nothing and just return noOp().
        Specified by:
        at in class AbstractLogger<FluentLogger2.Api>