code
stringlengths
23
201k
docstring
stringlengths
17
96.2k
func_name
stringlengths
0
235
language
stringclasses
1 value
repo
stringlengths
8
72
path
stringlengths
11
317
url
stringlengths
57
377
license
stringclasses
7 values
public boolean hasValues() { return ! values.isEmpty(); }
Value object to abstract multiple values mapped by a {@link String} key. @author Mark Paluch @since 28.02.14 09:50
hasValues
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/Values.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/Values.java
MIT
public int size() { return values.size(); }
Value object to abstract multiple values mapped by a {@link String} key. @author Mark Paluch @since 28.02.14 09:50
size
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/Values.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/Values.java
MIT
public Set<String> getEntryNames() { return Collections.unmodifiableSet(values.keySet()); }
Value object to abstract multiple values mapped by a {@link String} key. @author Mark Paluch @since 28.02.14 09:50
getEntryNames
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/Values.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/Values.java
MIT
public void setValue(String key, Object value) { values.put(key, value); }
Value object to abstract multiple values mapped by a {@link String} key. @author Mark Paluch @since 28.02.14 09:50
setValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/Values.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/Values.java
MIT
@SuppressWarnings("unchecked") public <T> T getValue(String key) { return (T) values.get(key); }
Value object to abstract multiple values mapped by a {@link String} key. @author Mark Paluch @since 28.02.14 09:50
getValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/Values.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/Values.java
MIT
public static final void close(Closeable closeable) { try { if (closeable != null) { closeable.close(); } } catch (IOException e) { // ignore } }
Close silently the closeable. @param closeable the closeable
close
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/Closer.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/Closer.java
MIT
public static final void close(Socket socket) { try { if (socket != null) { socket.close(); } } catch (IOException e) { // ignore } }
Close silently the socket. @param socket the socket
close
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/Closer.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/Closer.java
MIT
public static void setAdditionalFields(String spec, GelfMessageAssembler gelfMessageAssembler) { if (null != spec) { String[] properties = spec.split(MULTI_VALUE_DELIMITTER); for (String field : properties) { final int index = field.indexOf(EQ); if (-1 == index) { continue; } gelfMessageAssembler.addField(new StaticMessageField(field.substring(0, index), field.substring(index + 1))); } } }
Set the additional (static) fields. @param spec field=value,field1=value1, ... @param gelfMessageAssembler the Gelf message assembler to apply the configuration
setAdditionalFields
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
MIT
public static void setMdcFields(String spec, GelfMessageAssembler gelfMessageAssembler) { if (null != spec) { String[] fields = spec.split(MULTI_VALUE_DELIMITTER); for (String field : fields) { gelfMessageAssembler.addField(new MdcMessageField(field.trim(), field.trim())); } } }
Set the MDC fields. @param spec field, field2, field3 @param gelfMessageAssembler the Gelf message assembler to apply the configuration
setMdcFields
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
MIT
public static void setDynamicMdcFields(String spec, GelfMessageAssembler gelfMessageAssembler) { if (null != spec) { String[] fields = spec.split(MULTI_VALUE_DELIMITTER); for (String field : fields) { gelfMessageAssembler.addField(new DynamicMdcMessageField(field.trim())); } } }
Set the dynamic MDC fields. @param spec field, .*FieldSuffix, fieldPrefix.* @param gelfMessageAssembler the {@link GelfMessageAssembler}.
setDynamicMdcFields
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
MIT
public static void setAdditionalFieldTypes(String spec, GelfMessageAssembler gelfMessageAssembler) { if (null != spec) { String[] properties = spec.split(MULTI_VALUE_DELIMITTER); for (String field : properties) { final int index = field.indexOf(EQ); if (-1 != index) { gelfMessageAssembler.setAdditionalFieldType(field.substring(0, index), field.substring(index + 1)); } } } }
Set the additional field types. @param spec field=String,field1=Double, ... See {@link GelfMessage} for supported types. @param gelfMessageAssembler the Gelf message assembler to apply the configuration
setAdditionalFieldTypes
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
MIT
public static void setDynamicMdcFieldTypes(String spec, GelfMessageAssembler gelfMessageAssembler) { if (null != spec) { String[] properties = spec.split(MULTI_VALUE_DELIMITTER); for (String field : properties) { final int index = field.indexOf(EQ); if (-1 != index) { gelfMessageAssembler.setDynamicMdcFieldType(field.substring(0, index), field.substring(index + 1)); } } } }
Set the dynamic mdc field types. @param spec field=String,field1=Double, ... See {@link GelfMessage} for supported types. @param gelfMessageAssembler the Gelf message assembler to apply the configuration
setDynamicMdcFieldTypes
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ConfigurationSupport.java
MIT
public String toJson() { return toJson("_"); }
Create a JSON representation for this {@link GelfMessage}. Additional fields are prefixed with underscore {@code _}. @return the JSON string.
toJson
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String toJson(String additionalFieldPrefix) { return new String(toJsonByteArray(additionalFieldPrefix), StandardCharsets.UTF_8); }
Create a JSON representation for this {@link GelfMessage}. Additional fields are prefixed with {@code additionalFieldPrefix}. @param additionalFieldPrefix must not be {@literal null} @return the JSON string.
toJson
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
private byte[] toJsonByteArray(String additionalFieldPrefix) { ByteArrayOutputStream buffer = new ByteArrayOutputStream(); toJson(OutputAccessor.from(buffer), additionalFieldPrefix); return buffer.toByteArray(); }
Create a JSON representation for this {@link GelfMessage}. Additional fields are prefixed with {@code additionalFieldPrefix}. @param additionalFieldPrefix must not be {@literal null} @return the JSON string.
toJsonByteArray
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void toJson(ByteBuffer byteBuffer, String additionalFieldPrefix) { toJson(OutputAccessor.from(byteBuffer), additionalFieldPrefix); }
Create a JSON representation for this {@link GelfMessage} and write it to the {@link ByteBuffer}. Additional fields are prefixed with {@code additionalFieldPrefix}. @param byteBuffer must not be {@literal null} @param additionalFieldPrefix must not be {@literal null}
toJson
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
protected void toJson(OutputAccessor out, String additionalFieldPrefix) { JsonWriter.writeObjectStart(out); boolean hasFields = writeIfNotEmpty(out, false, FIELD_HOST, getHost()); if (!isEmpty(version) && !GELF_VERSION_1_0.equals(version)) { hasFields = writeIfNotEmpty(out, hasFields, FIELD_VERSION, version); } if (!isEmpty(shortMessage)) { hasFields = writeIfNotEmpty(out, hasFields, FIELD_SHORT_MESSAGE, getShortMessage()); } hasFields = writeIfNotEmpty(out, hasFields, FIELD_FULL_MESSAGE, getFullMessage()); if (getJavaTimestamp() != 0) { if (GELF_VERSION_1_1.equals(version)) { hasFields = writeIfNotEmpty(out, hasFields, FIELD_TIMESTAMP, getTimestampAsBigDecimal().doubleValue()); } else { hasFields = writeIfNotEmpty(out, hasFields, FIELD_TIMESTAMP, getTimestampAsBigDecimal().toString()); } } if (!isEmpty(getLevel())) { if (GELF_VERSION_1_1.equals(version)) { int level; try { level = Integer.parseInt(getLevel()); } catch (NumberFormatException ex) { // fallback on the default value level = DEFAUL_LEVEL; } hasFields = writeIfNotEmpty(out, hasFields, FIELD_LEVEL, level); } else { hasFields = writeIfNotEmpty(out, hasFields, FIELD_LEVEL, getLevel()); } } if (!isEmpty(getFacility())) { hasFields = writeIfNotEmpty(out, hasFields, FIELD_FACILITY, getFacility()); } for (Map.Entry<String, String> additionalField : additonalFields.entrySet()) { if (!ID_NAME.equals(additionalField.getKey()) && additionalField.getValue() != null) { String value = additionalField.getValue(); String fieldType = additionalFieldTypes.get(additionalField.getKey()); if (fieldType == null) { fieldType = getMatchingDynamicMdcFieldType(additionalField.getKey()); if (fieldType == null) { fieldType = FIELD_TYPE_DEFAULT; } } Object result = getAdditionalFieldValue(value, fieldType); if (result != null) { hasFields = writeIfNotEmpty(out, hasFields, additionalFieldPrefix + additionalField.getKey(), result); } } } JsonWriter.writeObjectEnd(out); }
Create a JSON representation for this {@link GelfMessage} and write it to the {@link ByteBuffer}. Additional fields are prefixed with {@code additionalFieldPrefix}. @param byteBuffer must not be {@literal null} @param additionalFieldPrefix must not be {@literal null}
toJson
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
private static boolean writeIfNotEmpty(OutputAccessor out, boolean hasFields, String field, Object value) { if (value == null) { return hasFields; } if (value instanceof String) { if (GelfMessage.isEmpty((String) value)) { return hasFields; } if (hasFields) { writeKeyValueSeparator(out); } writeMapEntry(out, field, value); return true; } if (hasFields) { writeKeyValueSeparator(out); } writeMapEntry(out, field, value); return true; }
Write a Value to JSON if the value is not empty.
writeIfNotEmpty
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
static Object getAdditionalFieldValue(String value, String fieldType) { Object result = null; if (fieldType.equalsIgnoreCase(FIELD_TYPE_DISCOVER)) { Result discoveredType = ValueDiscovery.discover(value); if (discoveredType == Result.STRING) { return value; } if (discoveredType == Result.LONG) { try { // try adding the value as a long return Long.parseLong(value); } catch (NumberFormatException ex) { // fallback on the double value return value; } } try { return Double.parseDouble(value); } catch (NumberFormatException ex) { // fallback on the string value return value; } } if (fieldType.equalsIgnoreCase(FIELD_TYPE_STRING)) { result = value; } if (fieldType.equals(FIELD_TYPE_DOUBLE) || fieldType.equalsIgnoreCase(FIELD_TYPE_DOUBLE2)) { try { result = Double.parseDouble(value); } catch (NumberFormatException ex) { if (fieldType.equals(FIELD_TYPE_DOUBLE)) { result = Double.valueOf(0); } } } if (fieldType.equals(FIELD_TYPE_LONG) || fieldType.equalsIgnoreCase(FIELD_TYPE_LONG2)) { try { result = (long) Double.parseDouble(value); } catch (NumberFormatException ex) { if (fieldType.equals(FIELD_TYPE_LONG)) { result = Long.valueOf(0); } } } return result; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getAdditionalFieldValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public ByteBuffer[] toUDPBuffers() { byte[] messageBytes = gzipMessage(toJsonByteArray("_")); if (messageBytes.length > maximumMessageSize) { // calculate the length of the datagrams array int datagramsLength = messageBytes.length / maximumMessageSize; // In case of a remainder, due to the integer division, add a extra datagram if (messageBytes.length % maximumMessageSize != 0) { datagramsLength++; } ByteBuffer targetBuffer = ByteBuffer.allocate(messageBytes.length + (datagramsLength * 12)); return sliceDatagrams(ByteBuffer.wrap(messageBytes), datagramsLength, targetBuffer); } ByteBuffer[] datagrams = new ByteBuffer[1]; datagrams[0] = ByteBuffer.allocate(messageBytes.length); datagrams[0].put(messageBytes); datagrams[0].flip(); return datagrams; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
toUDPBuffers
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public ByteBuffer[] toUDPBuffers(ByteBuffer buffer, ByteBuffer tempBuffer) { tempBuffer.put(gzipMessage(toJsonByteArray("_"))); // calculate the length of the datagrams array if (tempBuffer.position() > maximumMessageSize) { int diagramsLength = tempBuffer.position() / maximumMessageSize; // In case of a remainder, due to the integer division, add a extra datagram if (tempBuffer.position() % maximumMessageSize != 0) { diagramsLength++; } buffer.clear(); return sliceDatagrams((ByteBuffer) tempBuffer.flip(), diagramsLength, buffer); } return new ByteBuffer[] { (ByteBuffer) tempBuffer.flip() }; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
toUDPBuffers
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public ByteBuffer toTCPBuffer() { // Do not use GZIP, as the headers will contain \0 bytes // graylog2-server uses \0 as a delimiter for TCP frames // see: https://github.com/Graylog2/graylog2-server/issues/127 byte[] messageBytes = toJsonByteArray("_"); ByteBuffer buffer = ByteBuffer.allocate(messageBytes.length + 1); buffer.put(messageBytes); buffer.put((byte) '\0'); buffer.flip(); return buffer; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
toTCPBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public ByteBuffer toTCPBuffer(ByteBuffer buffer) { // Do not use GZIP, as the headers will contain \0 bytes // graylog2-server uses \0 as a delimiter for TCP frames // see: https://github.com/Graylog2/graylog2-server/issues/127 toJson(buffer, "_"); buffer.put((byte) '\0'); buffer.flip(); return buffer; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
toTCPBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
protected ByteBuffer[] sliceDatagrams(ByteBuffer source, int datagrams, ByteBuffer target) { int messageLength = source.limit(); long msgId = generateMsgId(); // Reuse length of datagrams array since this is supposed to be the correct number of datagrams ByteBuffer[] slices = new ByteBuffer[datagrams]; for (int idx = 0; idx < datagrams; idx++) { int start = target.position(); target.put(GELF_CHUNKED_ID).putLong(msgId).put((byte) idx).put((byte) datagrams); int from = idx * maximumMessageSize; int to = from + maximumMessageSize; if (to >= messageLength) { to = messageLength; } ByteBuffer duplicate = (ByteBuffer) source.duplicate().limit(to).position(from); target.put(duplicate); int end = target.position(); slices[idx] = (ByteBuffer) target.duplicate().limit(end).position(start); } return slices; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
sliceDatagrams
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
long generateMsgId() { /* * Considerations about generating the message ID: The GELF documentation suggests to * "[g]enerate [the id] from millisecond timestamp + hostname for example": * https://docs.graylog.org/en/3.1/pages/gelf.html#chunking * * However, relying on current time in milliseconds on the same system will result in a high collision probability if * lots of messages are generated quickly. Things will be even worse if multiple servers send to the same log server. * Adding the hostname is not guaranteed to help, and if the hostname is the FQDN it is even unlikely to be unique at * all. * * The GELF module used by Logstash uses the first eight bytes of an MD5 hash of the current time as floating point, a * hyphen, and an eight byte random number: https://github.com/logstash-plugins/logstash-output-gelf * https://github.com/graylog-labs/gelf-rb/blob/master/lib/gelf/notifier.rb#L239 It probably doesn't have to be that * clever: * * Using the timestamp plus a random number will mean we only have to worry about collision of random numbers within the * same milliseconds. How short can the timestamp be before it will collide with old timestamps? Every second Graylog * will evict expired messaged (5 seconds old) from the pool: * https://github.com/Graylog2/graylog2-server/blob/master/graylog2-server/src/main/java/org/graylog2/inputs/codecs/ * GelfChunkAggregator.java Thus, we just need six seconds which will require 13 bits. Then we can spend the rest on a * random number. */ return (getRandomLong() & 0xFFFFFFFFFFFFE000L) | (getCurrentTimeMillis() & 0x1FFFL); }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
generateMsgId
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
long getRandomLong() { return ThreadLocalRandom.current().nextLong(); }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getRandomLong
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
long getCurrentTimeMillis() { return System.currentTimeMillis(); }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getCurrentTimeMillis
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
private byte[] gzipMessage(byte[] message) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { GZIPOutputStream stream = new GZIPOutputStream(bos); stream.write(message); stream.finish(); Closer.close(stream); byte[] zipped = bos.toByteArray(); Closer.close(bos); return zipped; } catch (IOException e) { throw new IllegalStateException(); } }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
gzipMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
private String getMatchingDynamicMdcFieldType(String fieldName) { String fieldType = null; for (Map.Entry<Pattern, String> entry : dynamicMdcFieldTypes.entrySet()) { if (entry.getKey().matcher(fieldName).matches()) { fieldType = entry.getValue(); break; } } return fieldType; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getMatchingDynamicMdcFieldType
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String getVersion() { return version; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getVersion
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setVersion(String version) { this.version = version; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
setVersion
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String getHost() { return host; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getHost
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setHost(String host) { this.host = host; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
setHost
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String getShortMessage() { return !isEmpty(shortMessage) ? shortMessage : "<empty>"; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getShortMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setShortMessage(String shortMessage) { this.shortMessage = shortMessage; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
setShortMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String getFullMessage() { return fullMessage; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getFullMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setFullMessage(String fullMessage) { this.fullMessage = fullMessage; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
setFullMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public BigDecimal getTimestampAsBigDecimal() { return new BigDecimal(javaTimestamp).divide(TIME_DIVISOR); }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getTimestampAsBigDecimal
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String getTimestamp() { return getTimestampAsBigDecimal().toPlainString(); }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getTimestamp
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public Long getJavaTimestamp() { return javaTimestamp; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getJavaTimestamp
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setJavaTimestamp(long javaTimestamp) { this.javaTimestamp = javaTimestamp; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
setJavaTimestamp
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String getLevel() { return level; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getLevel
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setLevel(String level) { this.level = level; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
setLevel
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String getFacility() { return facility; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getFacility
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setFacility(String facility) { this.facility = facility; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
setFacility
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public Map<String, String> getAdditionalFieldTypes() { return additionalFieldTypes; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
getAdditionalFieldTypes
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setDynamicMdcFieldTypes(Map<Pattern, String> dynamicMdcFieldTypes) { this.dynamicMdcFieldTypes = dynamicMdcFieldTypes; }
Get the field value as requested data type. @param value the value as string @param fieldType see field types @return the field value in the appropriate data type or {@literal null}.
setDynamicMdcFieldTypes
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public GelfMessage addFields(Map<String, String> fields) { if (fields == null) { throw new IllegalArgumentException("fields is null"); } getAdditonalFields().putAll(fields); return this; }
Add multiple fields (key/value pairs) @param fields map of fields @return the current GelfMessage.
addFields
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public GelfMessage addField(String key, String value) { getAdditonalFields().put(key, value); return this; }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
addField
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public Map<String, String> getAdditonalFields() { return additonalFields; }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
getAdditonalFields
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public boolean isValid() { return isShortOrFullMessagesExists() && !isEmpty(version) && !isEmpty(host); }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
isValid
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
private boolean isShortOrFullMessagesExists() { return !isEmpty(shortMessage) || !isEmpty(fullMessage); }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
isShortOrFullMessagesExists
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public static boolean isEmpty(String str) { return str == null || "".equals(str.trim()); }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
isEmpty
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public int getMaximumMessageSize() { return maximumMessageSize; }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
getMaximumMessageSize
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public void setMaximumMessageSize(int maximumMessageSize) { this.maximumMessageSize = maximumMessageSize; }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
setMaximumMessageSize
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public String getField(String fieldName) { return getAdditonalFields().get(fieldName); }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
getField
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
@Override public boolean equals(Object o) { if (this == o) { return true; } if (!(o instanceof GelfMessage)) { return false; } GelfMessage that = (GelfMessage) o; if (javaTimestamp != that.javaTimestamp) { return false; } if (maximumMessageSize != that.maximumMessageSize) { return false; } if (additonalFields != null ? !additonalFields.equals(that.additonalFields) : that.additonalFields != null) { return false; } if (facility != null ? !facility.equals(that.facility) : that.facility != null) { return false; } if (fullMessage != null ? !fullMessage.equals(that.fullMessage) : that.fullMessage != null) { return false; } if (host != null ? !host.equals(that.host) : that.host != null) { return false; } if (level != null ? !level.equals(that.level) : that.level != null) { return false; } if (shortMessage != null ? !shortMessage.equals(that.shortMessage) : that.shortMessage != null) { return false; } if (version != null ? !version.equals(that.version) : that.version != null) { return false; } return true; }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
equals
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
@Override public int hashCode() { int result = version != null ? version.hashCode() : 0; result = 31 * result + (host != null ? host.hashCode() : 0); result = 31 * result + (shortMessage != null ? shortMessage.hashCode() : 0); result = 31 * result + (fullMessage != null ? fullMessage.hashCode() : 0); result = 31 * result + (int) (javaTimestamp ^ (javaTimestamp >>> 32)); result = 31 * result + (level != null ? level.hashCode() : 0); result = 31 * result + (facility != null ? facility.hashCode() : 0); result = 31 * result + (additonalFields != null ? additonalFields.hashCode() : 0); result = 31 * result + maximumMessageSize; return result; }
Add a particular field. @param key the key @param value the value @return the current GelfMessage.
hashCode
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfMessage.java
MIT
public static GelfSender createSender(final HostAndPortProvider hostAndPortProvider, final ErrorReporter errorReporter, final Map<String, Object> senderSpecificConfigurations) { GelfSenderConfiguration senderConfiguration = new GelfSenderConfiguration() { @Override public int getPort() { return hostAndPortProvider.getPort(); } @Override public String getHost() { return hostAndPortProvider.getHost(); } @Override public ErrorReporter getErrorReporter() { return errorReporter; } @Override public Map<String, Object> getSpecificConfigurations() { return senderSpecificConfigurations; } }; return createSender(senderConfiguration); }
Create a GelfSender based on the configuration. @param hostAndPortProvider the host and port @param errorReporter the error reporter @param senderSpecificConfigurations configuration map @return a new {@link GelfSender} instance
createSender
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
@Override public int getPort() { return hostAndPortProvider.getPort(); }
Create a GelfSender based on the configuration. @param hostAndPortProvider the host and port @param errorReporter the error reporter @param senderSpecificConfigurations configuration map @return a new {@link GelfSender} instance
getPort
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
@Override public String getHost() { return hostAndPortProvider.getHost(); }
Create a GelfSender based on the configuration. @param hostAndPortProvider the host and port @param errorReporter the error reporter @param senderSpecificConfigurations configuration map @return a new {@link GelfSender} instance
getHost
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
@Override public ErrorReporter getErrorReporter() { return errorReporter; }
Create a GelfSender based on the configuration. @param hostAndPortProvider the host and port @param errorReporter the error reporter @param senderSpecificConfigurations configuration map @return a new {@link GelfSender} instance
getErrorReporter
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
@Override public Map<String, Object> getSpecificConfigurations() { return senderSpecificConfigurations; }
Create a GelfSender based on the configuration. @param hostAndPortProvider the host and port @param errorReporter the error reporter @param senderSpecificConfigurations configuration map @return a new {@link GelfSender} instance
getSpecificConfigurations
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
public static GelfSender createSender(GelfSenderConfiguration senderConfiguration) { ErrorReporter errorReporter = senderConfiguration.getErrorReporter(); if (senderConfiguration.getHost() == null) { senderConfiguration.getErrorReporter().reportError("GELF server hostname is empty!", null); } else { try { for (GelfSenderProvider provider : SenderProviderHolder.getSenderProvider()) { if (provider.supports(senderConfiguration.getHost())) { return provider.create(senderConfiguration); } } senderConfiguration.getErrorReporter().reportError("No sender found for host " + senderConfiguration.getHost(), null); return null; } catch (UnknownHostException e) { errorReporter.reportError("Unknown GELF server hostname:" + senderConfiguration.getHost(), e); } catch (SocketException e) { errorReporter.reportError("Socket exception: " + e.getMessage(), e); } catch (IOException e) { errorReporter.reportError("IO exception: " + e.getMessage(), e); } } return null; }
Create a GelfSender based on the configuration. @param senderConfiguration the configuration @return a new {@link GelfSender} instance
createSender
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
static List<GelfSenderProvider> getSenderProvider() { return providerList; }
Create a GelfSender based on the configuration. @param senderConfiguration the configuration @return a new {@link GelfSender} instance
getSenderProvider
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
static void addSenderProvider(GelfSenderProvider provider) { synchronized (providerList) { addedProviders.add(provider); if (!providerList.contains(provider)) { providerList.add(0, provider); // To take precedence over built-in providers } } }
Create a GelfSender based on the configuration. @param senderConfiguration the configuration @return a new {@link GelfSender} instance
addSenderProvider
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
static void removeAllAddedSenderProviders() { synchronized (providerList) { providerList.removeAll(addedProviders); addedProviders.clear(); } }
Create a GelfSender based on the configuration. @param senderConfiguration the configuration @return a new {@link GelfSender} instance
removeAllAddedSenderProviders
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
static void removeSenderProvider(GelfSenderProvider provider) { synchronized (providerList) { addedProviders.remove(provider); providerList.remove(provider); } }
Create a GelfSender based on the configuration. @param senderConfiguration the configuration @return a new {@link GelfSender} instance
removeSenderProvider
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/GelfSenderFactory.java
MIT
public static void toJSONString(OutputAccessor out, Map<String, ? extends Object> map) { writeObjectStart(out); boolean first = true; for (Map.Entry<String, ? extends Object> entry : map.entrySet()) { if (first) { first = false; } else { writeKeyValueSeparator(out); } writeMapEntry(out, entry.getKey(), entry.getValue()); } writeObjectEnd(out); }
Utility method to write a {@link Map} into a JSON representation. @param out @param map
toJSONString
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
MIT
public static void writeMapEntry(OutputAccessor out, String key, Object value) { out.write((byte) '\"'); if (key == null) out.write(NULL); else { writeUtf8(out, key); } out.write(Q_AND_C); toJSONString(out, value); }
Write a map entry. @param out @param key @param value
writeMapEntry
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
MIT
private static void toJSONString(OutputAccessor out, Object value) { if (value == null) { out.write(NULL); return; } if (value instanceof String) { out.write((byte) '\"'); writeUtf8(out, (String) value); out.write((byte) '\"'); return; } if (value instanceof Double) { Double d = (Double) value; if (d.isNaN()) { out.write((byte) '\"'); out.write(NaN); out.write((byte) '\"'); } else if (d.isInfinite()) { out.write((byte) '\"'); if (d == Double.NEGATIVE_INFINITY) { out.write('-'); } out.write(Infinite); out.write((byte) '\"'); } else { writeAscii(out, value.toString()); } return; } if (value instanceof Float) { Float f = (Float) value; if (f.isNaN()) { out.write((byte) '\"'); out.write(NaN); out.write((byte) '\"'); } else if (f.isInfinite()) { out.write((byte) '\"'); if (f == Float.NEGATIVE_INFINITY) { out.write('-'); } out.write(Infinite); out.write((byte) '\"'); } else { writeAscii(out, value.toString()); } return; } if (value instanceof Number) { writeAscii(out, value.toString()); } if (value instanceof Boolean) { if ((boolean) value) { out.write(TRUE); } else { out.write(FALSE); } } }
Convert an object to JSON text. Encode the value as UTF-8 text, or "null" if value is null or it's an NaN or an INF number.
toJSONString
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
MIT
private static void writeUtf8(OutputAccessor out, String string) { writeUtf8(out, string, string.length()); }
Convert an object to JSON text. Encode the value as UTF-8 text, or "null" if value is null or it's an NaN or an INF number.
writeUtf8
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
MIT
private static void escape(OutputAccessor out, int charToEscape) { out.write('\\'); out.write('u'); if (charToEscape > 0xFF) { int hi = (charToEscape >> 8) & 0xFF; out.write(HEX_BYTES[hi >> 4]); out.write(HEX_BYTES[hi & 0xF]); charToEscape &= 0xFF; } else { out.write((byte) '0'); out.write((byte) '0'); } // We know it's a control char, so only the last 2 chars are non-0 out.write(HEX_BYTES[charToEscape >> 4]); out.write(HEX_BYTES[charToEscape & 0xF]); }
Write a UTF escape sequence using either an one or two-byte seqience. @param out the output @param charToEscape the character to escape.
escape
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
MIT
private static boolean isSurrogate(char c) { return c >= '\uD800' && c <= '\uDFFF'; }
Determine if {@code c} lies within the range of values defined for <a href="http://unicode.org/glossary/#surrogate_code_point">Surrogate Code Point</a>. @param c the character to check. @return {@code true} if {@code c} lies within the range of values defined for <a href="http://unicode.org/glossary/#surrogate_code_point">Surrogate Code Point</a>. {@code false} otherwise.
isSurrogate
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/JsonWriter.java
MIT
@Override public void reportError(String message, Exception e) { String messageToUse = postProcessMessage(message, e); delegate.reportError(messageToUse, e); }
{@link ErrorReporter} that post-processes the error message if it is {@code null} by using the exception class name as fallback. @author Mark Paluch @since 1.11.2
reportError
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/MessagePostprocessingErrorReporter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/MessagePostprocessingErrorReporter.java
MIT
private static String postProcessMessage(String message, Exception e) { if ((message == null || "null".equalsIgnoreCase(message)) && e != null) { if (e.getMessage() != null) { return e.getMessage(); } return e.getClass().getSimpleName(); } return message; }
{@link ErrorReporter} that post-processes the error message if it is {@code null} by using the exception class name as fallback. @author Mark Paluch @since 1.11.2
postProcessMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/MessagePostprocessingErrorReporter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/MessagePostprocessingErrorReporter.java
MIT
public static OutputAccessor from(OutputStream outputStream) { return new OutputStreamAccessor(outputStream); }
Create an {@link OutputAccessor} for the given {@link OutputStream}. @param outputStream @return
from
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
public static OutputAccessor from(ByteBuffer byteBuffer) { ByteBufferOutputAccessor accessor = new ByteBufferOutputAccessor(); accessor.byteBuffer = byteBuffer; return accessor; }
Create an {@link OutputAccessor} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param byteBuffer @return
from
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
public static OutputAccessor from(OutputAccessorPoolHolder poolHolder, ByteBuffer byteBuffer) { ByteBufferOutputAccessor accessor = poolHolder.getByteBufferOutputAccessor(); accessor.byteBuffer = byteBuffer; return accessor; }
Create an {@link OutputAccessor} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
from
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
public static OutputStream pooledStream(OutputAccessorPoolHolder poolHolder) { return poolHolder.getByteBufferOutputStream(); }
Retrieve a pooled {@link OutputStream}. @param poolHolder @return
pooledStream
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
public static OutputStream asStream(OutputAccessorPoolHolder poolHolder, ByteBuffer byteBuffer) { ByteBufferOutputStream accessor = poolHolder.getByteBufferOutputStream(); accessor.byteBuffer = byteBuffer; return accessor; }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
asStream
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(byte[] b, int off, int len) { byteBuffer.put(b, off, len); }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(byte[] b) { byteBuffer.put(b); }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(int b) { byteBuffer.put((byte) b); }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(byte[] b, int off, int len) { byteBuffer.put(b, off, len); }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(byte[] b) { byteBuffer.put(b); }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(int b) { byteBuffer.put((byte) b); }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(byte[] b, int off, int len) { try { delegate.write(b, off, len); } catch (IOException e) { throw new IllegalStateException(e); } }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(byte[] b) { try { delegate.write(b); } catch (IOException e) { throw new IllegalStateException(e); } }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
@Override public void write(int b) { try { delegate.write(b); } catch (IOException e) { throw new IllegalStateException(e); } }
Retrieved a pooled an {@link OutputStream} for the given {@link ByteBuffer}. Instances are pooled within the thread scope. @param poolHolder @param byteBuffer @return
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/OutputAccessor.java
MIT
public static PoolHolder noop() { return NoOpPoolHolder.noop(); }
Holder for {@link ThreadLocal} pools. @author Mark Paluch
noop
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
MIT
public static PoolHolder threadLocal() { return new ThreadLocalPoolHolder(); }
Holder for {@link ThreadLocal} pools. @author Mark Paluch
threadLocal
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
MIT
@Override protected ReusableGzipOutputStream initialValue() { try { return new ReusableGzipOutputStream(OutputAccessor.pooledStream(outputAccessorPoolHolder)); } catch (IOException e) { throw new IllegalStateException(e); } }
{@link PoolHolder} backed by {@link ThreadLocal}.
initialValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
MIT
@Override protected ByteBuffer[] initialValue() { return new ByteBuffer[1]; }
{@link PoolHolder} backed by {@link ThreadLocal}.
initialValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
MIT
@Override protected byte[] initialValue() { return new byte[8192 * 2]; }
{@link PoolHolder} backed by {@link ThreadLocal}.
initialValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
MIT
public ByteBuffer[] getSingleBuffer() { return singleBufferPool.get(); }
@return a pooled {@link ByteBuffer}-array instance.
getSingleBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolHolder.java
MIT
@Override public void toJson(ByteBuffer byteBuffer, String additionalFieldPrefix) { toJson(OutputAccessor.from(poolHolder.getOutputAccessorPoolHolder(), byteBuffer), additionalFieldPrefix); }
Represents a Gelf message using resource pooling. Special caution is required with methods accepting {@link ByteBuffer}: Buffer construction is generally thread-safe but the resulting buffers must not cross thread boundaries because buffers are pooled on a per-thread level. @author Mark Paluch
toJson
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolingGelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolingGelfMessage.java
MIT
@Override public ByteBuffer[] toUDPBuffers(ByteBuffer buffer, ByteBuffer tempBuffer) { try { toJson(buffer, "_"); OutputAccessor.asStream(poolHolder.getOutputAccessorPoolHolder(), tempBuffer); ReusableGzipOutputStream gz = poolHolder.getReusableGzipOutputStream(); gz.reset(); gz.writeHeader(); buffer.mark(); gzip(buffer, gz); gz.finish(); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new IllegalStateException(e); } // calculate the length of the datagrams array if (tempBuffer.position() > getMaximumMessageSize()) { int diagramsLength = tempBuffer.position() / getMaximumMessageSize(); // In case of a remainder, due to the integer division, add a extra datagram if (tempBuffer.position() % getMaximumMessageSize() != 0) { diagramsLength++; } buffer.clear(); return sliceDatagrams((ByteBuffer) tempBuffer.flip(), diagramsLength, buffer); } else { ByteBuffer[] byteBuffers = poolHolder.getSingleBuffer(); byteBuffers[0] = (ByteBuffer) tempBuffer.flip(); return byteBuffers; } }
Represents a Gelf message using resource pooling. Special caution is required with methods accepting {@link ByteBuffer}: Buffer construction is generally thread-safe but the resulting buffers must not cross thread boundaries because buffers are pooled on a per-thread level. @author Mark Paluch
toUDPBuffers
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolingGelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolingGelfMessage.java
MIT
private void gzip(ByteBuffer source, ReusableGzipOutputStream gz) throws IOException { int size = source.position(); if (source.isDirect()) { int read = 0; source.position(0); byte[] bytes = poolHolder.getByteArray(); while (size > read) { if ((size - read) > bytes.length) { read += bytes.length; source.get(bytes); gz.write(bytes); } else { int remain = size - read; read += remain; source.get(bytes, 0, remain); gz.write(bytes, 0, remain); } } } else { gz.write(source.array(), source.arrayOffset(), source.position()); } }
Represents a Gelf message using resource pooling. Special caution is required with methods accepting {@link ByteBuffer}: Buffer construction is generally thread-safe but the resulting buffers must not cross thread boundaries because buffers are pooled on a per-thread level. @author Mark Paluch
gzip
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolingGelfMessage.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolingGelfMessage.java
MIT
public static PoolingGelfMessageBuilder newInstance() { return new PoolingGelfMessageBuilder(STATIC_POOLING ? STATIC_POOL_HOLDER : PoolHolder.threadLocal()); }
Creates a new instance of the GelfMessageBuilder. @return GelfMessageBuilder
newInstance
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/PoolingGelfMessageBuilder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/PoolingGelfMessageBuilder.java
MIT