java.lang.Object
io.jstach.rainbowgum.json.JsonBuffer
- All Implemented Interfaces:
LogEncoder.Buffer
,AutoCloseable
A buffer designed for encoding JSON efficiently.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Extended fields are just fields that have some special prefix for things like GELF and ECS.static enum
JSON tokens.Nested classes/interfaces inherited from interface io.jstach.rainbowgum.LogEncoder.Buffer
LogEncoder.Buffer.StringBuilderBuffer
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
A flag to indicate this field is extended which means it will be prefixed withJsonBuffer.ExtendedFieldPrefix
. -
Constructor Summary
ConstructorDescriptionJsonBuffer
(boolean prettyPrint, JsonBuffer.ExtendedFieldPrefix extendedFieldPrefix) Create a JSON buffer. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Prepare the buffer for reuse.void
The appender will call this usually within a lock to transfer content from the buffer to the output.Reusable String buffer for formatted messages.final void
write
(JsonBuffer.JSONToken token) Writes a JSON token.final int
Writes a string field.final int
Writes a string field.final int
writeDouble
(String k, double v, int index, int flag) Writes a double field.final int
Writes a string field.final void
Efficiently writes a line feed.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.jstach.rainbowgum.LogEncoder.Buffer
close
-
Field Details
-
EXTENDED_F
A flag to indicate this field is extended which means it will be prefixed withJsonBuffer.ExtendedFieldPrefix
.- See Also:
-
-
Constructor Details
-
JsonBuffer
Create a JSON buffer.- Parameters:
prettyPrint
- whether or not to pretty print the JSON.extendedFieldPrefix
- prefix for extended fields.
-
-
Method Details
-
drain
Description copied from interface:LogEncoder.Buffer
The appender will call this usually within a lock to transfer content from the buffer to the output.- Specified by:
drain
in interfaceLogEncoder.Buffer
- Parameters:
output
- output to receive content.event
- log event.
-
clear
Description copied from interface:LogEncoder.Buffer
Prepare the buffer for reuse.An appender may not call clear before being passed to the encoder so the encoder should do its own clearing.
- Specified by:
clear
in interfaceLogEncoder.Buffer
-
getFormattedMessageBuilder
Reusable String buffer for formatted messages.- Returns:
- buffer.
-
write
Writes a JSON token.- Parameters:
token
- token not null.
-
writeLineFeed
Efficiently writes a line feed. -
write
Writes a string field.- Parameters:
k
- field namev
- valueindex
- the current index for comma determination- Returns:
- index + 1
-
write
Writes a string field.- Parameters:
k
- field namev
- valueindex
- the current index for comma determinationflag
- seeEXTENDED_F
- Returns:
- index + 1
-
writeDouble
Writes a double field.- Parameters:
k
- field namev
- valueindex
- the current index for comma determinationflag
- seeEXTENDED_F
- Returns:
- index + 1
-
writeInt
Writes a string field.- Parameters:
k
- field namev
- valueindex
- the current index for comma determinationflag
- seeEXTENDED_F
- Returns:
- index + 1
-