Package com.apple.foundationdb.util
Class LoggableKeysAndValuesImpl
- java.lang.Object
-
- com.apple.foundationdb.util.LoggableKeysAndValuesImpl
-
- All Implemented Interfaces:
LoggableKeysAndValues<LoggableKeysAndValuesImpl>
@API(MAINTAINED) public class LoggableKeysAndValuesImpl extends Object implements LoggableKeysAndValues<LoggableKeysAndValuesImpl>
Provides a default implementation ofLoggableKeysAndValues
.
-
-
Constructor Summary
Constructors Constructor Description LoggableKeysAndValuesImpl(Object... keyValues)
Create an instance with the given message and a sequence of key-value pairs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description LoggableKeysAndValuesImpl
addLogInfo(Object... keyValue)
Add a list of key/value pairs to the log information.LoggableKeysAndValuesImpl
addLogInfo(String description, Object object)
Add a key/value pair to the log information.Object[]
exportLogInfo()
Export the log information to a flattened array.Map<String,Object>
getLogInfo()
Get the log information associated with this exception as a map.
-
-
-
Constructor Detail
-
LoggableKeysAndValuesImpl
public LoggableKeysAndValuesImpl(@Nullable Object... keyValues)
Create an instance with the given message and a sequence of key-value pairs. This will throw anIllegalArgumentException
ifkeyValues
contains an odd number of elements.- Parameters:
keyValues
- list- See Also:
addLogInfo(Object...)
-
-
Method Detail
-
getLogInfo
@Nonnull public Map<String,Object> getLogInfo()
Get the log information associated with this exception as a map.- Specified by:
getLogInfo
in interfaceLoggableKeysAndValues<LoggableKeysAndValuesImpl>
- Returns:
- a single map with all log information
-
addLogInfo
@Nonnull public LoggableKeysAndValuesImpl addLogInfo(@Nonnull String description, Object object)
Add a key/value pair to the log information. This will use the description given as the key and the object provided as the value.- Specified by:
addLogInfo
in interfaceLoggableKeysAndValues<LoggableKeysAndValuesImpl>
- Parameters:
description
- description of the log info pairobject
- value of the log info pair- Returns:
- this
LoggableException
-
addLogInfo
@Nonnull public LoggableKeysAndValuesImpl addLogInfo(@Nonnull Object... keyValue)
Add a list of key/value pairs to the log information. This will treat the list of items as pairs to be added with every even element being a key and every odd element being a value (associated with the even key preceding it). So, for example,["k0", "v0", "k1", "v1"]
will add two pairs to the log info, one with key"k0"
and value"v0"
and one with key"k1"
and value"v1"
. Note that this is the same format that is exported byexportLogInfo()
.- Specified by:
addLogInfo
in interfaceLoggableKeysAndValues<LoggableKeysAndValuesImpl>
- Parameters:
keyValue
- flattened map of key-value pairs- Returns:
- this
LoggableException
- Throws:
IllegalArgumentException
- ifkeyValue
has odd length
-
exportLogInfo
@Nonnull public Object[] exportLogInfo()
Export the log information to a flattened array. This will flatten the map that would be returned bygetLogInfo()
into an array where every even element is a key within the map and every odd element is the value associated with the key before it. So, for example,{"k0:"v0", "k1":"v1"}
would be flattened into["k0", "v0", "k1", "v1"]
.- Specified by:
exportLogInfo
in interfaceLoggableKeysAndValues<LoggableKeysAndValuesImpl>
- Returns:
- a flattened map of key-value pairs
-
-