Class AbstractLogger<API extends FloggerApi<API>>

  • Type Parameters:
    API - the logging API provided by this logger.
    Direct Known Subclasses:
    FluentLogger2

    public abstract class AbstractLogger<API extends FloggerApi<API>>
    extends Object
    Base class for the fluent logger API. This class is a factory for instances of a fluent logging API, used to build log statements via method chaining.
    See Also:
    Original Java code of Google Flogger
    • Constructor Detail

      • AbstractLogger

        protected AbstractLogger​(LoggerBackend backend)
        Constructs a new logger for the specified backend.
        Parameters:
        backend - the logger backend which ultimately writes the log statements out.
    • Method Detail

      • at

        public abstract API at​(Level level)
        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().
      • atSevere

        public final API atSevere()
        A convenience method for at(Level.SEVERE).
      • atWarning

        public final API atWarning()
        A convenience method for at(Level.WARNING).
      • atInfo

        public final API atInfo()
        A convenience method for at(Level.INFO).
      • atConfig

        public final API atConfig()
        A convenience method for at(Level.CONFIG).
      • atFine

        public final API atFine()
        A convenience method for at(Level.FINE).
      • atFiner

        public final API atFiner()
        A convenience method for at(Level.FINER).
      • atFinest

        public final API atFinest()
        A convenience method for at(Level.FINEST).
      • getName

        protected String getName()
        Returns the non-null name of this logger (Flogger does not currently support anonymous loggers).
      • isLoggable

        protected final boolean isLoggable​(Level level)
        Returns whether the given level is enabled for this logger. Users wishing to guard code with a check for "loggability" should use logger.atLevel().isEnabled() instead.