Class ThrottleLogger
- java.lang.Object
-
- jetbrains.buildServer.log.ThrottleLogger
-
public class ThrottleLogger extends Object
Logger that will repeat the same message not more than once per defined interval. Messages are stored in WeakHashMap as keys. This means that throttling might not actually work if full GC is run. This is a trade-off from storing hard references to messages and always remembering them for the full hour so that memory can be freed if java needs it.ThrottleLogger use logging template to compare message identities. Messages identical if templates are the same object.
The easiest way to achieve it is to use java string pool/literals instead of objects. As uninterned objects would not work.For example:
log.debug("Hello world!") lod.debug("Hello " + "world!")will be treated as two different messages. But
log.debug("Hello world!") lod.debug(("Hello " + "world!").intern())be the same.
Usage of arguments are optional. If last parameter
instanceof Throwableit considered as Exception and will be treated as one. Template syntax use "{}" as placeholders to format message.
Formats messages according to Slf4j MessageFormatter syntax.
It is recommended to use parametrized templates if not especially required otherwise.log.debug("Hello {}!", "World")Be careful: throttling would not be supported if
template != template. It is considered a code smell to use string concatenation/jdk message format/string builder/other approaches. Using that approached not only consumes considerably more CPU/Memory resources but also prevents effectively use ThrottleLogger.log.debug(String.format("Hello %s!","World")) <- bad log.debug("Hello " + "World!")) <- bad log.debug(new StringBuilder().append("Hello ").append("World!").toString()) <- badint a = 0; log.debug("Hello {} a={}!", "World", a) try { ... } catch (Exception e) { log.error("Hello {} a={}!", "World", a, e); }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classThrottleLogger.JBDiagnosticLoggerAdapterDirect link to #com.intellij.openapi.diagnostic.Loggerstatic interfaceThrottleLogger.LoggerAdapterstatic classThrottleLogger.LogLevelstatic classThrottleLogger.WeakKey<T>
-
Field Summary
Fields Modifier and Type Field Description static longLIMIT_UNLIMITEDstatic longTIME_1_HOURstatic longTIME_1_MINstatic longTIME_30_SECstatic longTIME_5_MINS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidall(String template, Object... args)voiddebug(String template, Object... args)voiderror(String template, Object... args)voidfatal(String template, Object... args)static ThrottleLoggerget1HrLogger(Class<?> aClass)static ThrottleLoggerget1MinLLogger(Class<?> aClass)static ThrottleLoggerget1MinLogger(Class<?> aClass)static ThrottleLoggerget5MinLLogger(Class<?> aClass)static ThrottleLoggerget5MinLogger(Class<?> aClass)static ThrottleLoggerget5MinLogger(String category)static ThrottleLoggergetLLogger(Class<?> aClass)Logs duplicate messages with lower priority instead of just ignoring, with 5 minutes throttling.static ThrottleLoggergetLLogger(Class<?> aClass, long timeLimitNanos)Logs duplicate messages with lower priority instead of just ignoring them.static ThrottleLoggergetLogger(Class<?> aClass)static ThrottleLoggergetLogger(Class<?> aClass, long timeLimitNanos)static ThrottleLoggergetLogger(Class<?> aClass, long timeLimitNanos, boolean lowerLevel)static ThrottleLoggergetLogger(Class<?> aClass, long timeLimitNanos, long messageLimit, boolean lowerLevel)static ThrottleLoggergetLogger(String category)static ThrottleLoggergetLogger(String category, long timeLimitNanos)static ThrottleLoggergetLogger(String category, long timeLimitNanos, long messageLimit, boolean lowerLevel)static ThrottleLoggergetLogger(ThrottleLogger.LoggerAdapter loggerAdapter, long timeLimitNanos, long messageLimit, boolean lowerLevel)static ThrottleLoggergetNoThrottleLogger(Class<?> aClass)static ThrottleLoggergetNoThrottleLogger(String category)voidinfo(String template, Object... args)booleanisDebugEnabled()booleanisInfoEnabled()booleanisTraceEnabled()booleanisWarnEnabled()voidlog(ThrottleLogger.LogLevel level, String template, Object... args)voidtrace(String template, Object... args)voidwarn(String template, Object... args)voidwarnAndDebugDetails(String template, Object... args)
-
-
-
Field Detail
-
TIME_1_HOUR
public static final long TIME_1_HOUR
-
TIME_5_MINS
public static final long TIME_5_MINS
-
TIME_1_MIN
public static final long TIME_1_MIN
-
TIME_30_SEC
public static final long TIME_30_SEC
-
LIMIT_UNLIMITED
public static final long LIMIT_UNLIMITED
- See Also:
- Constant Field Values
-
-
Method Detail
-
getLogger
public static ThrottleLogger getLogger(ThrottleLogger.LoggerAdapter loggerAdapter, long timeLimitNanos, long messageLimit, boolean lowerLevel)
-
getLogger
public static ThrottleLogger getLogger(Class<?> aClass, long timeLimitNanos, long messageLimit, boolean lowerLevel)
-
getLogger
public static ThrottleLogger getLogger(String category, long timeLimitNanos, long messageLimit, boolean lowerLevel)
-
getLogger
public static ThrottleLogger getLogger(Class<?> aClass, long timeLimitNanos)
-
getLogger
public static ThrottleLogger getLogger(String category, long timeLimitNanos)
-
getLogger
public static ThrottleLogger getLogger(Class<?> aClass, long timeLimitNanos, boolean lowerLevel)
-
getLLogger
public static ThrottleLogger getLLogger(Class<?> aClass, long timeLimitNanos)
Logs duplicate messages with lower priority instead of just ignoring them.- Parameters:
aClass- class used to create the name of the logger.timeLimitNanos- time period during which same messages will be treated as duplicates.- Returns:
- created logger
-
getNoThrottleLogger
public static ThrottleLogger getNoThrottleLogger(Class<?> aClass)
-
getNoThrottleLogger
public static ThrottleLogger getNoThrottleLogger(String category)
-
getLogger
public static ThrottleLogger getLogger(Class<?> aClass)
-
getLogger
public static ThrottleLogger getLogger(String category)
-
get1MinLogger
public static ThrottleLogger get1MinLogger(Class<?> aClass)
-
get5MinLogger
public static ThrottleLogger get5MinLogger(Class<?> aClass)
-
get5MinLogger
public static ThrottleLogger get5MinLogger(String category)
-
get1HrLogger
public static ThrottleLogger get1HrLogger(Class<?> aClass)
-
getLLogger
public static ThrottleLogger getLLogger(Class<?> aClass)
Logs duplicate messages with lower priority instead of just ignoring, with 5 minutes throttling.- Parameters:
aClass- class used to create the name of the logger.- Returns:
- created logger
-
get5MinLLogger
public static ThrottleLogger get5MinLLogger(Class<?> aClass)
-
get1MinLLogger
public static ThrottleLogger get1MinLLogger(Class<?> aClass)
-
log
public void log(ThrottleLogger.LogLevel level, String template, Object... args)
-
isDebugEnabled
public boolean isDebugEnabled()
-
isWarnEnabled
public boolean isWarnEnabled()
-
isInfoEnabled
public boolean isInfoEnabled()
-
isTraceEnabled
public boolean isTraceEnabled()
-
-