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 Throwable
it 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()) <- bad
int 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 class
ThrottleLogger.JBDiagnosticLoggerAdapter
Direct link to #com.intellij.openapi.diagnostic.Loggerstatic interface
ThrottleLogger.LoggerAdapter
static class
ThrottleLogger.LogLevel
static class
ThrottleLogger.WeakKey<T>
-
Field Summary
Fields Modifier and Type Field Description static long
LIMIT_UNLIMITED
static long
TIME_1_HOUR
static long
TIME_1_MIN
static long
TIME_30_SEC
static long
TIME_5_MINS
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
all(String template, Object... args)
void
debug(String template, Object... args)
void
error(String template, Object... args)
void
fatal(String template, Object... args)
static ThrottleLogger
get1HrLogger(Class<?> aClass)
static ThrottleLogger
get1MinLLogger(Class<?> aClass)
static ThrottleLogger
get1MinLogger(Class<?> aClass)
static ThrottleLogger
get5MinLLogger(Class<?> aClass)
static ThrottleLogger
get5MinLogger(Class<?> aClass)
static ThrottleLogger
get5MinLogger(String category)
static ThrottleLogger
getLLogger(Class<?> aClass)
Logs duplicate messages with lower priority instead of just ignoring, with 5 minutes throttling.static ThrottleLogger
getLLogger(Class<?> aClass, long timeLimitNanos)
Logs duplicate messages with lower priority instead of just ignoring them.static ThrottleLogger
getLogger(Class<?> aClass)
static ThrottleLogger
getLogger(Class<?> aClass, long timeLimitNanos)
static ThrottleLogger
getLogger(Class<?> aClass, long timeLimitNanos, boolean lowerLevel)
static ThrottleLogger
getLogger(Class<?> aClass, long timeLimitNanos, long messageLimit, boolean lowerLevel)
static ThrottleLogger
getLogger(String category)
static ThrottleLogger
getLogger(String category, long timeLimitNanos)
static ThrottleLogger
getLogger(String category, long timeLimitNanos, long messageLimit, boolean lowerLevel)
static ThrottleLogger
getLogger(ThrottleLogger.LoggerAdapter loggerAdapter, long timeLimitNanos, long messageLimit, boolean lowerLevel)
static ThrottleLogger
getNoThrottleLogger(Class<?> aClass)
static ThrottleLogger
getNoThrottleLogger(String category)
void
info(String template, Object... args)
boolean
isDebugEnabled()
boolean
isInfoEnabled()
boolean
isTraceEnabled()
boolean
isWarnEnabled()
void
log(ThrottleLogger.LogLevel level, String template, Object... args)
void
trace(String template, Object... args)
void
warn(String template, Object... args)
void
warnAndDebugDetails(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()
-
-