Class CounterResolver
- java.lang.Object
-
- org.apache.logging.log4j.layout.template.json.resolver.CounterResolver
-
- All Implemented Interfaces:
EventResolver
,TemplateResolver<LogEvent>
public class CounterResolver extends Object implements EventResolver
Resolves a number from an internal counter.Configuration
config = [ start ] , [ overflowing ] , [ stringified ] start = "start" -> number overflowing = "overflowing" -> boolean stringified = "stringified" -> boolean
Unless provided, start and overflowing are respectively set to zero and true by default.When overflowing is set to true, the internal counter is created using a long, which is subject to overflow while incrementing, though garbage-free. Otherwise, a
BigInteger
is used, which does not overflow, but incurs allocation costs.When stringified is enabled, which is set to false by default, the resolved number will be converted to a string.
Examples
Resolves a sequence of numbers starting from 0. OnceLong.MAX_VALUE
is reached, counter overflows toLong.MIN_VALUE
.{ "$resolver": "counter" }
Resolves a sequence of numbers starting from 1000. OnceLong.MAX_VALUE
is reached, counter overflows toLong.MIN_VALUE
.{ "$resolver": "counter", "start": 1000 }
Resolves a sequence of numbers starting from 0 and keeps on doing as long as JVM heap allows.{ "$resolver": "counter", "overflowing": false }
-
-
Constructor Summary
Constructors Constructor Description CounterResolver(EventResolverContext context, TemplateResolverConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
resolve(LogEvent ignored, JsonWriter jsonWriter)
Resolves the givenvalue
using the providedJsonWriter
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.logging.log4j.layout.template.json.resolver.TemplateResolver
isFlattening, isResolvable, isResolvable, resolve
-
-
-
-
Constructor Detail
-
CounterResolver
public CounterResolver(EventResolverContext context, TemplateResolverConfig config)
-
-
Method Detail
-
resolve
public void resolve(LogEvent ignored, JsonWriter jsonWriter)
Description copied from interface:TemplateResolver
Resolves the givenvalue
using the providedJsonWriter
.- Specified by:
resolve
in interfaceTemplateResolver<LogEvent>
-
-