Package com.google.common.flogger
Class AbstractLogger<API extends LoggingApi<API>>
- java.lang.Object
-
- com.google.common.flogger.AbstractLogger<API>
-
- Type Parameters:
API- the logging API provided by this logger.
- Direct Known Subclasses:
FluentLogger2
public abstract class AbstractLogger<API extends LoggingApi<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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractLogger(LoggerBackend backend)Constructs a new logger for the specified backend.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract APIat(Level level)Returns a fluent logging API appropriate for the specified log level.APIatConfig()A convenience method for at(Level.CONFIG).APIatFine()A convenience method for at(Level.FINE).APIatFiner()A convenience method for at(Level.FINER).APIatFinest()A convenience method for at(Level.FINEST).APIatInfo()A convenience method for at(Level.INFO).APIatSevere()A convenience method for at(Level.SEVERE).APIatWarning()A convenience method for at(Level.WARNING).protected StringgetName()Returns the non-null name of this logger (Flogger does not currently support anonymous loggers).protected booleanisLoggable(Level level)Returns whether the given level is enabled for this logger.
-
-
-
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:
whereboolean isLoggable = isLoggable(level); boolean isForced = Platform.shouldForceLogging(getName(), level, isLoggable); return (isLoggable | isForced) ? new SubContext(level, isForced) : NO_OP;NO_OPis a singleton, no-op instance of the logging API whose methods do nothing and justreturn 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 uselogger.atLevel().isEnabled()instead.
-
-