Class LogContext.Key

  • Enclosing class:
    LogContext<LOGGER extends AbstractLogger<API>,​API extends LoggingApi<API>>

    public static final class LogContext.Key
    extends Object
    The predefined metadata keys used by the default logging API. Backend implementations can use these to identify metadata added by the core logging API.
    • Field Detail

      • LOG_AT_MOST_EVERY

        public static final MetadataKey<com.google.common.flogger.DurationRateLimiter.RateLimitPeriod> LOG_AT_MOST_EVERY
        The key associated with a rate limiting period for "at most once every N" rate limiting. The value is set by LoggingApi.atMostEvery(int, TimeUnit).
      • SKIPPED_LOG_COUNT

        public static final MetadataKey<Integer> SKIPPED_LOG_COUNT
        The key associated with a count of rate limited logs. This is only public so backends can reference the key to control formatting.
      • LOG_SITE_GROUPING_KEY

        public static final MetadataKey<Object> LOG_SITE_GROUPING_KEY
        The key associated with a sequence of log site "grouping keys". These serve to specialize the log site key to group the behaviour of stateful operations like rate limiting. This is used by the per() methods and is only public so backends can reference the key to control formatting.
      • WAS_FORCED

        public static final MetadataKey<Boolean> WAS_FORCED
        The key associated with a Boolean value used to specify that the log statement must be emitted.

        Forcing a log statement ensures that the LoggerBackend is passed the LogData for this log statement regardless of the backend's log level or any other filtering or rate limiting which might normally occur. If a log statement is forced, this key will be set immediately on creation of the logging context and will be visible to both fluent methods and post-processing.

        Filtering and rate-limiting methods must check for this value and should treat forced log statements as not having had any filtering or rate limiting applied. For example, if the following log statement was forced:

        
         logger.atInfo().withCause(e).atMostEvery(1, MINUTES).log("Message...");
         
        it should behave as if the rate-limiting methods were never called, such as:
        
         logger.atInfo().withCause(e).log("Message...");
         
        As well as no longer including any rate-limiting metadata for the forced log statement, this also has the effect of never interfering with the rate-limiting of this log statement for other callers.

        The decision of whether to force a log statement is expected to be made based upon debug values provded by the logger which come from a scope greater than the log statement itself. Thus it makes no sense to provide a public method to set this value programmatically for a log statement.

      • TAGS

        public static final MetadataKey<Tags> TAGS
        The key associated with any injected Tags.

        If tags are injected, they are added after post-processing if the log site is enabled. Thus they are not available to the postProcess() method itself. The rationale is that a log statement's behavior should only be affected by code at the log site (other than "forcing" log statements, which is slightly a special case).

        Tags can be added at the log site, although this should rarely be necessary and using normal log message arguments is always the preferred way to indicate unstrctured log data. Users should never build new Tags instances just to pass them into a log statement.

      • CONTEXT_STACK_SIZE

        public static final MetadataKey<StackSize> CONTEXT_STACK_SIZE
        Key associated with the metadata for specifying additional stack information with a log statement.