Interface Event
public interface Event
Structured Logged Event interface.
This interface is used to add context information to the log event and eventually log.
-
Method Summary
Modifier and TypeMethodDescriptionatError()Log this event at the error level.atInfo()Log this event at the info level (the default).Add an attribute for the event.Add an attribute for the event using a supplier.atWarn()Log this event at the warn level.Attach an exception to the event.voidLog the event, using an enum as the message.voidLog the event, using a string.Create a new child event.Set the parent ID of the event.Add a resource for the event.Add a resource for the event using a supplier.resources(EventResources attrs) Add resources for the event from an EventResources object.Mark this event as sampled.voidstash()Stash this log event to bridge across an unmodifiable API call.timed()Mark this event as timed.Set the trace ID of the event.
-
Method Details
-
newChildEvent
Event newChildEvent()Create a new child event. The child event will inherit the trace ID of the event from which it was created. The child event parentId will be the ID of the event from which it was created. The child will inherit resources from its parent event, but not attributes.- Returns:
- a new child event
-
traceId
Set the trace ID of the event. Normally this will be inherited from the parent event. In the case of a root event, the trace ID will be automatically generated. This method only needs to be used if a traceID has been received from elsewhere, such as from a user request.- Parameters:
traceId- the traceId- Returns:
- this
-
parentId
Set the parent ID of the event. Normally this is set automatically for child events. For root events, it is normally empty unless provided by some other means, such as via a user request.- Parameters:
parentId- the parentId- Returns:
- this
-
timed
Event timed()Mark this event as timed. Timed events will measure the duration between #timed() being called and logged being called. The duration will be in milliseconds.Event e = logger.newRootEvent().timed(); // do something that takes time. e.log(Events.SOME_EVENT);
- Returns:
- this
-
sampled
Mark this event as sampled. Sampled events will only log once per specified duration. The sampling key is used to scope the rate limit. All events using the same sampling key will observe the same rate limit. Sampled events are most useful in the data plane, where, if there is an error for one event, there's likely to be a lot of other events which are almost identical.- Parameters:
samplingKey- a key by which to scope the rate limitingduration- the duration for which one event will be loggedunit- the duration unit- Returns:
- this
-
resources
Add resources for the event from an EventResources object.- Returns:
- this
- See Also:
-
resource
Add a resource for the event. Resources are inherited by child events.- Parameters:
key- the key to identify the resourcevalue- the value which will be logged for the resource. This is converted to a string before logging.- Returns:
- this
-
resource
Add a resource for the event using a supplier. The supplier is used in the case that generating the string from the object is expensive or we want to generate a custom string.- Parameters:
key- the key to identify the resourcevalue- a supplier which returns the value to be logged for this resource- See Also:
-
attr
Add an attribute for the event. Attributes are not inherited by child events.- Parameters:
key- the key to identify the attributevalue- the value which will be logged for the attribute. This is converted to a string, using Object#toString() before logging.- Returns:
- this
-
attr
Add an attribute for the event using a supplier.- Parameters:
key- the key to identify the attributevalue- a supplier which returns the value to be logged for this attribute- Returns:
- this
-
exception
Attach an exception to the event.- Parameters:
t- the exception- Returns:
- this
-
atError
Event atError()Log this event at the error level.- Returns:
- this
-
atInfo
Event atInfo()Log this event at the info level (the default).- Returns:
- this
-
atWarn
Event atWarn()Log this event at the warn level.- Returns:
- this
-
log
Log the event, using an enum as the message. Logging with a enum allows documentation and annotations, such as subcomponent to be attached to the message.- Parameters:
event- the event message, in enum form
-
log
Log the event, using a string.- Parameters:
event- the event message.
-
stash
void stash()Stash this log event to bridge across an unmodifiable API call.- See Also:
-