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 static boolean usePooling() { return STATIC_POOLING || USE_POOLING_VAL.equalsIgnoreCase("true"); }
@return {@literal true} if pooling (static/instance-held pools) is enabled.
usePooling
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
public GelfMessageBuilder recycle() { version = GelfMessage.GELF_VERSION; host = null; shortMessage = null; fullMessage = null; javaTimestamp = 0; level = null; facility = GelfMessage.DEFAULT_FACILITY; maximumMessageSize = GelfMessage.DEFAULT_MESSAGE_SIZE; additionalFields.clear(); additionalFieldTypes.clear(); return this; }
Recycle this {@link GelfMessageBuilder} to a default state. @return {@code this} {@link GelfMessageBuilder}
recycle
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
@Override public GelfMessage build() { GelfMessage gelfMessage = new PoolingGelfMessage(shortMessage, fullMessage, javaTimestamp, level, poolHolder); gelfMessage.addFields(additionalFields); gelfMessage.setMaximumMessageSize(maximumMessageSize); gelfMessage.setVersion(version); gelfMessage.setHost(host); gelfMessage.setJavaTimestamp(javaTimestamp); gelfMessage.setFacility(facility); gelfMessage.setAdditionalFieldTypes(additionalFieldTypes); gelfMessage.setDynamicMdcFieldTypes(dynamicMdcFieldTypes); return gelfMessage; }
Build a new Gelf message based on the builder settings. @return GelfMessage
build
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
@Override public synchronized void write(byte[] buf, int off, int len) throws IOException { super.write(buf, off, len); crc.update(buf, off, len); }
Writes array of bytes to the compressed output stream. This method will block until all the bytes are written. @param buf the data to be written @param off the start offset of the data @param len the length of the data @exception IOException If an I/O error has occurred.
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
MIT
@Override public void finish() throws IOException { if (!def.finished()) { def.finish(); while (!def.finished()) { int len = def.deflate(buf, 0, buf.length); if (def.finished() && len <= buf.length - TRAILER_SIZE) { // last deflater buffer. Fit trailer at the end writeTrailer(buf, len); len = len + TRAILER_SIZE; out.write(buf, 0, len); return; } if (len > 0) out.write(buf, 0, len); } // if we can't fit the trailer at the end of the last // deflater buffer, we write it separately byte[] trailer = new byte[TRAILER_SIZE]; writeTrailer(trailer, 0); out.write(trailer); } }
Finishes writing compressed data to the output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream. @exception IOException if an I/O error has occurred
finish
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
MIT
public void writeHeader() throws IOException { out.write(new byte[] { (byte) GZIP_MAGIC, // Magic number (short) (byte) (GZIP_MAGIC >> 8), // Magic number (short) Deflater.DEFLATED, // Compression method (CM) 0, // Flags (FLG) 0, // Modification time MTIME (int) 0, // Modification time MTIME (int) 0, // Modification time MTIME (int) 0, // Modification time MTIME (int) 0, // Extra flags (XFLG) 0 // Operating system (OS) }); }
Finishes writing compressed data to the output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream. @exception IOException if an I/O error has occurred
writeHeader
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
MIT
private void writeTrailer(byte[] buf, int offset) { writeInt((int) crc.getValue(), buf, offset); // CRC-32 of uncompr. data writeInt(def.getTotalIn(), buf, offset + 4); // Number of uncompr. bytes }
Finishes writing compressed data to the output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream. @exception IOException if an I/O error has occurred
writeTrailer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
MIT
private void writeInt(int i, byte[] buf, int offset) { writeShort(i & 0xffff, buf, offset); writeShort((i >> 16) & 0xffff, buf, offset + 2); }
Finishes writing compressed data to the output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream. @exception IOException if an I/O error has occurred
writeInt
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
MIT
private void writeShort(int s, byte[] buf, int offset) { buf[offset] = (byte) (s & 0xff); buf[offset + 1] = (byte) ((s >> 8) & 0xff); }
Finishes writing compressed data to the output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream. @exception IOException if an I/O error has occurred
writeShort
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
MIT
public void reset() { crc.reset(); def.reset(); }
Finishes writing compressed data to the output stream without closing the underlying stream. Use this method when applying multiple filters in succession to the same output stream. @exception IOException if an I/O error has occurred
reset
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ReusableGzipOutputStream.java
MIT
static Result discover(String value) { long len = value.length(); if (len == 0 || len > 32) { return Result.STRING; } char firstChar = value.charAt(0); if (firstChar < '0' || firstChar > '9') { // Possible leading "+" or "-" if (firstChar == 'N' && len == 3 && value.equals("NaN")) { return Result.DOUBLE; } else if (firstChar == 'I' && len == 8 && value.equals("Infinity")) { return Result.DOUBLE; } else if (firstChar == '+' && len == 9 && value.equals("+Infinity")) { return Result.DOUBLE; } else if (firstChar == '-' && len == 9 && value.equals("-Infinity")) { return Result.DOUBLE; } if (firstChar != '-' && firstChar != '+') { return Result.STRING; } } boolean numbersOnly = true; for (int pos = 0; pos < Math.min(len, 20); pos++) { char c = value.charAt(pos); numbersOnly &= (c >= '0' && c <= '9'); if (numbersOnly) { continue; } if ((c != '+') && (c != '-') && (c < '0' || c > '9') && (c < 'a' || c > 'f') && (c < 'A' || c > 'F') && (c != '.') && (c != 'x' && c != 'X') && (c != 'p' && c != 'P')) { return Result.STRING; } } if (numbersOnly) { if (len == 1) { return Result.LONG; } else if (len <= 19 && firstChar != '0') { return Result.LONG; } else { return Result.STRING; } } else if (longPattern.matcher(value).matches()) { return Result.LONG; } else if (doublePattern.matcher(value).matches()) { return Result.DOUBLE; } return Result.STRING; }
Data type discovery for {@link String} value types. Discovers an indicator whether a type is a {@link Result#LONG}, a {@link Result#DOUBLE} or {@link Result#STRING} type. @author <a href="mailto:mpaluch@paluch.biz">Mark Paluch</a> @author Wolfgang Jung
discover
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/ValueDiscovery.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/ValueDiscovery.java
MIT
protected boolean isConnected() throws IOException { ByteBuffer byteBuffer = readBuffers.get(); byteBuffer.clear(); T myChannel = channel(); if (myChannel != null && myChannel.isOpen() && isConnected(myChannel)) { try { return myChannel.read(byteBuffer) >= 0; } catch (PortUnreachableException e) { errorReporter.reportError("Port " + getHost() + ":" + getPort() + " not reachable", e); Closer.close(channel()); } catch (IOException e) { errorReporter.reportError("Cannot verify whether channel to " + getHost() + ":" + getPort() + " is connected: " + e.getMessage(), e); } } return false; }
Create a new {@link AbstractNioSender} given {@link ErrorReporter}, {@code host} and {@code port}. Object creation triggers hostname lookup for early failure. @param errorReporter the error reporter. @param host hostname. @param port port number. @exception UnknownHostException if no IP address for the {@code host} could be found, or if a scope_id was specified for a global IPv6 address.
isConnected
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
MIT
protected T channel() { return channel; }
Create a new {@link AbstractNioSender} given {@link ErrorReporter}, {@code host} and {@code port}. Object creation triggers hostname lookup for early failure. @param errorReporter the error reporter. @param host hostname. @param port port number. @exception UnknownHostException if no IP address for the {@code host} could be found, or if a scope_id was specified for a global IPv6 address.
channel
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
MIT
public String getHost() { return host; }
Create a new {@link AbstractNioSender} given {@link ErrorReporter}, {@code host} and {@code port}. Object creation triggers hostname lookup for early failure. @param errorReporter the error reporter. @param host hostname. @param port port number. @exception UnknownHostException if no IP address for the {@code host} could be found, or if a scope_id was specified for a global IPv6 address.
getHost
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
MIT
public int getPort() { return port; }
Create a new {@link AbstractNioSender} given {@link ErrorReporter}, {@code host} and {@code port}. Object creation triggers hostname lookup for early failure. @param errorReporter the error reporter. @param host hostname. @param port port number. @exception UnknownHostException if no IP address for the {@code host} could be found, or if a scope_id was specified for a global IPv6 address.
getPort
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
MIT
public void close() { shutdown = true; Closer.close(channel()); }
Create a new {@link AbstractNioSender} given {@link ErrorReporter}, {@code host} and {@code port}. Object creation triggers hostname lookup for early failure. @param errorReporter the error reporter. @param host hostname. @param port port number. @exception UnknownHostException if no IP address for the {@code host} could be found, or if a scope_id was specified for a global IPv6 address.
close
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
MIT
public boolean isShutdown() { return shutdown; }
Create a new {@link AbstractNioSender} given {@link ErrorReporter}, {@code host} and {@code port}. Object creation triggers hostname lookup for early failure. @param errorReporter the error reporter. @param host hostname. @param port port number. @exception UnknownHostException if no IP address for the {@code host} could be found, or if a scope_id was specified for a global IPv6 address.
isShutdown
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
MIT
@Override public void reportError(String message, Exception e) { errorReporter.reportError(message, e); }
Create a new {@link AbstractNioSender} given {@link ErrorReporter}, {@code host} and {@code port}. Object creation triggers hostname lookup for early failure. @param errorReporter the error reporter. @param host hostname. @param port port number. @exception UnknownHostException if no IP address for the {@code host} could be found, or if a scope_id was specified for a global IPv6 address.
reportError
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
MIT
public void setChannel(T channel) { this.channel = channel; }
Create a new {@link AbstractNioSender} given {@link ErrorReporter}, {@code host} and {@code port}. Object creation triggers hostname lookup for early failure. @param errorReporter the error reporter. @param host hostname. @param port port number. @exception UnknownHostException if no IP address for the {@code host} could be found, or if a scope_id was specified for a global IPv6 address.
setChannel
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/AbstractNioSender.java
MIT
public static String encodeString(String s) { return new String(encode(s.getBytes())); }
Encodes a string into Base64 format. No blanks or line breaks are inserted. @param s A String to be encoded. @return A String containing the Base64 encoded data.
encodeString
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/Base64Coder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/Base64Coder.java
MIT
public static char[] encode(byte[] in) { return encode(in, 0, in.length); }
Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. @param in An array containing the data bytes to be encoded. @return A character array containing the Base64 encoded data.
encode
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/Base64Coder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/Base64Coder.java
MIT
public static char[] encode(byte[] in, int iOff, int iLen) { int oDataLen = (iLen * 4 + 2) / 3; // output length without padding int oLen = ((iLen + 2) / 3) * 4; // output length including padding char[] out = new char[oLen]; int ip = iOff; int iEnd = iOff + iLen; int op = 0; while (ip < iEnd) { int i0 = in[ip++] & 0xff; int i1 = ip < iEnd ? in[ip++] & 0xff : 0; int i2 = ip < iEnd ? in[ip++] & 0xff : 0; int o0 = i0 >>> 2; int o1 = ((i0 & 3) << 4) | (i1 >>> 4); int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6); int o3 = i2 & 0x3F; out[op++] = map1[o0]; out[op++] = map1[o1]; out[op] = op < oDataLen ? map1[o2] : '='; op++; out[op] = op < oDataLen ? map1[o3] : '='; op++; } return out; }
Encodes a byte array into Base64 format. No blanks or line breaks are inserted in the output. @param in An array containing the data bytes to be encoded. @param iOff Offset of the first byte in <code>in</code> to be processed. @param iLen Number of bytes to process in <code>in</code>, starting at <code>iOff</code>. @return A character array containing the Base64 encoded data.
encode
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/Base64Coder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/Base64Coder.java
MIT
@Override public long nextBackOff() { return backoffTimeMs; }
Constant {@link BackOff} implementation. @author Mark Paluch
nextBackOff
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/ConstantBackOff.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/ConstantBackOff.java
MIT
@Override public BackOffExecution start() { return this; }
Constant {@link BackOff} implementation. @author Mark Paluch
start
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/ConstantBackOff.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/ConstantBackOff.java
MIT
protected static ByteBuffer[] toUDPBuffers(GelfMessage message, ThreadLocal<ByteBuffer> writeBuffers, ThreadLocal<ByteBuffer> tempBuffers) { while (true) { try { return message.toUDPBuffers(getBuffer(writeBuffers), getBuffer(tempBuffers)); } catch (BufferOverflowException e) { enlargeBuffer(writeBuffers); enlargeBuffer(tempBuffers); } } }
Create UDP buffers and apply auto-buffer-enlarging, if necessary. @param message @param writeBuffers @param tempBuffers @return
toUDPBuffers
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
MIT
protected static ByteBuffer toTCPBuffer(GelfMessage message, ThreadLocal<ByteBuffer> writeBuffers) { while (true) { try { return message.toTCPBuffer(getBuffer(writeBuffers)); } catch (BufferOverflowException e) { enlargeBuffer(writeBuffers); } } }
Create TCP buffer and apply auto-buffer-enlarging, if necessary. @param message @param writeBuffers @return
toTCPBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
MIT
private static void enlargeBuffer(ThreadLocal<ByteBuffer> buffers) { ByteBuffer newBuffer = ByteBuffer.allocateDirect(calculateNewBufferSize(buffers.get().capacity())); buffers.set(newBuffer); }
Create TCP buffer and apply auto-buffer-enlarging, if necessary. @param message @param writeBuffers @return
enlargeBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
MIT
private static ByteBuffer getBuffer(ThreadLocal<ByteBuffer> buffers) { return (ByteBuffer) buffers.get().clear(); }
Create TCP buffer and apply auto-buffer-enlarging, if necessary. @param message @param writeBuffers @return
getBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
MIT
private static int calculateNewBufferSize(int capacity) { return (int) (capacity * 1.5); }
Create TCP buffer and apply auto-buffer-enlarging, if necessary. @param message @param writeBuffers @return
calculateNewBufferSize
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfBuffers.java
MIT
@Override public boolean sendMessage(GelfMessage message) { HttpURLConnection connection = null; try { connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(connectTimeoutMs); connection.setReadTimeout(readTimeoutMs); connection.setDoOutput(true); connection.setRequestMethod("POST"); connection.addRequestProperty("Content-type", "application/json"); String userInfo = url.getUserInfo(); // contains user:password if (userInfo != null) { String encodedString = Base64Coder.encodeString(userInfo); connection.setRequestProperty("Authorization", "Basic " + encodedString); } OutputStream outputStream = connection.getOutputStream(); outputStream.write(message.toJson().getBytes(StandardCharsets.UTF_8)); outputStream.close(); int responseCode = connection.getResponseCode(); if (responseCode >= HTTP_SUCCESSFUL_LOWER_BOUND && responseCode <= HTTP_SUCCESSFUL_UPPER_BOUND) { return true; } errorReporter.reportError("Server responded with unexpected status code: " + responseCode, null); } catch (IOException e) { String cleanUrl = url.toString(); String userInfo = url.getUserInfo(); if (userInfo != null) { cleanUrl = cleanUrl.replace(userInfo + "@", ""); } errorReporter.reportError("Cannot send data to " + cleanUrl, e); } finally { // disconnecting HttpURLConnection here to avoid underlying premature underlying Socket being closed. if (connection != null) { connection.disconnect(); } } return false; }
Create a new {@link GelfHTTPSender} given {@code url}, {@code connectTimeoutMs}, {@code readTimeoutMs} and {@link ErrorReporter}. @param url target URL @param connectTimeoutMs connection timeout in milliseconds. @param readTimeoutMs read timeout in milliseconds. @param errorReporter the error reporter.
sendMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java
MIT
@Override public void close() { // nothing to do }
Create a new {@link GelfHTTPSender} given {@code url}, {@code connectTimeoutMs}, {@code readTimeoutMs} and {@link ErrorReporter}. @param url target URL @param connectTimeoutMs connection timeout in milliseconds. @param readTimeoutMs read timeout in milliseconds. @param errorReporter the error reporter.
close
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfHTTPSender.java
MIT
public boolean sendMessage(GelfMessage message) { // prevent recursive self calls caused by the Redis driver since it if (!callers.add(Thread.currentThread())) { return false; } try { return sendMessage0(message); } finally { callers.remove(Thread.currentThread()); } }
@author https://github.com/strima/logstash-gelf.git @author Mark Paluch @since 1.5
sendMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSender.java
MIT
protected boolean sendMessage0(GelfMessage message) { try (Jedis jedisClient = jedisPool.getResource()) { jedisClient.lpush(redisKey, message.toJson("")); return true; } catch (Exception e) { errorReporter.reportError(e.getMessage(), new IOException("Cannot send REDIS data with key URI " + redisKey, e)); return false; } }
@author https://github.com/strima/logstash-gelf.git @author Mark Paluch @since 1.5
sendMessage0
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSender.java
MIT
public void close() { callers.clear(); jedisPool.destroy(); }
@author https://github.com/strima/logstash-gelf.git @author Mark Paluch @since 1.5
close
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfREDISSender.java
MIT
@Override protected ByteBuffer initialValue() { return ByteBuffer.allocateDirect(INITIAL_BUFFER_SIZE); }
@author https://github.com/t0xa/gelfj @author Mark Paluch
initialValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
MIT
protected SocketChannel createSocketChannel(int readTimeoutMs, boolean keepAlive) throws IOException { SocketChannel socketChannel = SocketChannel.open(); socketChannel.configureBlocking(false); socketChannel.socket().setKeepAlive(keepAlive); socketChannel.socket().setSoTimeout(readTimeoutMs); return socketChannel; }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @throws IOException in case of I/O errors
createSocketChannel
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
MIT
public boolean sendMessage(GelfMessage message) { if (isShutdown()) { return false; } IOException exception = null; for (int i = 0; i < deliveryAttempts; i++) { try { // (re)-connect if necessary if (!isConnected()) { synchronized (ioLock) { connect(); } } ByteBuffer buffer; if (INITIAL_BUFFER_SIZE == 0) { buffer = message.toTCPBuffer(); } else { buffer = GelfBuffers.toTCPBuffer(message, writeBuffers); } try { synchronized (ioLock) { write(buffer); } } catch (InterruptedException e) { reportError(e.getMessage(), new IOException("Cannot send data to " + getHost() + ":" + getPort(), e)); Thread.currentThread().interrupt(); return false; } return true; } catch (IOException e) { Closer.close(channel()); exception = e; } } if (exception != null) { reportError(exception.getMessage(), new IOException("Cannot send data to " + getHost() + ":" + getPort(), exception)); } return false; }
@param message the message @return {@literal true} if message was sent.
sendMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
MIT
protected void write(ByteBuffer buffer) throws IOException, InterruptedException { int nothingWrittenTimesInRow = 0; BackOffExecution backoffExecution = null; while (buffer.hasRemaining()) { int written = channel().write(buffer); if (written < 0 || !isConnected()) { // indicator the socket was closed Closer.close(channel()); throw new SocketException("Cannot write buffer to channel"); } if (written == 0) { if (backoffExecution == null) { backoffExecution = backoff.start(); } nothingWrittenTimesInRow++; if (nothingWrittenTimesInRow > writeBackoffThreshold) { long toSleep = backoffExecution.nextBackOff(); if (toSleep == BackOffExecution.STOP) { Closer.close(channel()); throw new SocketException("Cannot write buffer to channel, no progress in writing"); } Thread.sleep(toSleep); } } else { // written > 0 nothingWrittenTimesInRow = 0; } } }
@param message the message @return {@literal true} if message was sent.
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
MIT
protected boolean connect() throws IOException { if (isConnected()) { return false; } Closer.close(channel()); setChannel(createSocketChannel(readTimeoutMs, keepAlive)); InetSocketAddress inetSocketAddress = new InetSocketAddress(getHost(), getPort()); if (channel().connect(inetSocketAddress)) { return true; } long connectTimeoutLeft = TimeUnit.MILLISECONDS.toNanos(connectTimeoutMs); long waitTimeoutMs = 10; long waitTimeoutNs = TimeUnit.MILLISECONDS.toNanos(waitTimeoutMs); boolean connected; try { while (!(connected = channel().finishConnect())) { Thread.sleep(waitTimeoutMs); connectTimeoutLeft -= waitTimeoutNs; if (connectTimeoutLeft <= 0) { break; } } if (!connected) { throw new ConnectException("Connection timed out. Cannot connect to " + inetSocketAddress + " within " + TimeUnit.NANOSECONDS.toMillis(connectTimeoutLeft) + "ms"); } return connected; } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw new IOException("Connection interrupted", e); } }
@param message the message @return {@literal true} if message was sent.
connect
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
MIT
@Override protected boolean isConnected(SocketChannel channel) { return channel.isConnected(); }
@param message the message @return {@literal true} if message was sent.
isConnected
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSender.java
MIT
@Override protected boolean connect() throws IOException { if (super.connect()) { this.sslEngine = sslContext.createSSLEngine(); this.sslEngine.setUseClientMode(true); this.sslSession = sslEngine.getSession(); // Begin handshake sslEngine.beginHandshake(); doHandshake(channel(), sslEngine, ByteBuffer.allocate(sslSession.getPacketBufferSize()), ByteBuffer.allocate(sslSession.getPacketBufferSize())); } return false; }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
connect
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
@Override protected boolean isConnected() throws IOException { SocketChannel socketChannel = channel(); return socketChannel != null && socketChannel.isOpen() && isConnected(socketChannel); }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
isConnected
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
@Override protected void write(ByteBuffer gelfBuffer) throws IOException { while (gelfBuffer.hasRemaining()) { read(); ByteBuffer myNetData = getNetworkBuffer(); // Generate SSL/TLS encoded data (handshake or application data) gelfBuffer.mark(); SSLEngineResult res = sslEngine.wrap(gelfBuffer, myNetData); // Process status of call if (res.getStatus() == SSLEngineResult.Status.BUFFER_OVERFLOW) { this.sslNetworkBuffers.set(enlargeBuffer(gelfBuffer, myNetData)); gelfBuffer.reset(); } if (res.getStatus() == SSLEngineResult.Status.OK) { myNetData.flip(); // Send SSL/TLS encoded data to peer while (myNetData.hasRemaining()) { int written = channel().write(myNetData); if (written == -1) { throw new SocketException("Channel closed"); } } } } }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
write
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
private void read() throws IOException { ByteBuffer myNetData = getNetworkBuffer(); ByteBuffer tempBuffer = getTempBuffer(); if (channel().read(myNetData) < 0) { throw new SocketException("Channel closed"); } // Process incoming handshaking data myNetData.flip(); sslEngine.unwrap(myNetData, tempBuffer); }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
read
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
private ByteBuffer getNetworkBuffer() { ByteBuffer networkBuffer = this.sslNetworkBuffers.get(); if (networkBuffer == null) { networkBuffer = ByteBuffer.allocateDirect(sslSession.getPacketBufferSize()); this.sslNetworkBuffers.set(networkBuffer); } networkBuffer.clear(); return networkBuffer; }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
getNetworkBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
private ByteBuffer getTempBuffer() { ByteBuffer tempBuffer = this.tempBuffers.get(); if (tempBuffer == null) { tempBuffer = ByteBuffer.allocateDirect(sslSession.getApplicationBufferSize()); this.tempBuffers.set(tempBuffer); } tempBuffer.clear(); return tempBuffer; }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
getTempBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
private ByteBuffer enlargeBuffer(ByteBuffer src, ByteBuffer dst) { // Could attempt to drain the dst buffer of any already obtained // data, but we'll just increase it to the size needed. ByteBuffer buffer = ByteBuffer.allocate(dst.capacity() + src.remaining()); dst.flip(); buffer.put(dst); return buffer; }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
enlargeBuffer
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
private void doHandshake(SocketChannel socketChannel, SSLEngine sslEngine, ByteBuffer myNetData, ByteBuffer peerNetData) throws IOException { // Create byte buffers to use for holding application data int appBufferSize = sslEngine.getSession().getApplicationBufferSize(); ByteBuffer myAppData = ByteBuffer.allocate(appBufferSize); ByteBuffer peerAppData = ByteBuffer.allocate(appBufferSize); long handshakeBegin = System.currentTimeMillis(); SSLEngineResult.HandshakeStatus hs = sslEngine.getHandshakeStatus(); // Process handshaking message while (hs != SSLEngineResult.HandshakeStatus.FINISHED && hs != SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING) { long handshakeDuration = System.currentTimeMillis() - handshakeBegin; if (handshakeDuration > connectTimeoutMs) { throw new SocketTimeoutException("SSL handshake timeout exceeded"); } if (!isConnected(socketChannel)) { throw new SocketException("Channel closed"); } switch (hs) { case NEED_UNWRAP: // Receive handshaking data from peer if (socketChannel.read(peerNetData) < 0) { throw new SocketException("Channel closed"); } // Process incoming handshaking data peerNetData.flip(); SSLEngineResult res = sslEngine.unwrap(peerNetData, peerAppData); peerNetData.compact(); hs = res.getHandshakeStatus(); // Check status switch (res.getStatus()) { case OK: // Handle OK status break; case BUFFER_OVERFLOW: peerAppData = enlargeBuffer(peerNetData, peerAppData); break; case BUFFER_UNDERFLOW: break; } break; case NEED_WRAP: // Empty the local network packet buffer. myNetData.clear(); // Generate handshaking data res = sslEngine.wrap(myAppData, myNetData); hs = res.getHandshakeStatus(); // Check status switch (res.getStatus()) { case OK: myNetData.flip(); // Send the handshaking data to peer while (myNetData.hasRemaining()) { if (socketChannel.write(myNetData) < 0) { // Handle closed channel } } break; case BUFFER_OVERFLOW: myNetData = enlargeBuffer(myAppData, myNetData); break; case BUFFER_UNDERFLOW: break; case CLOSED: if (sslEngine.isOutboundDone()) { return; } else { sslEngine.closeOutbound(); hs = sslEngine.getHandshakeStatus(); break; } default: throw new IOException("Cannot wrap data: " + res.getStatus()); } break; case NEED_TASK: Runnable task; while ((task = sslEngine.getDelegatedTask()) != null) { task.run(); } hs = sslEngine.getHandshakeStatus(); break; case FINISHED: return; } } }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
doHandshake
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
@Override public void close() { if (channel() != null) { try { closeSocketChannel(); } catch (IOException e) { reportError(e.getMessage(), e); } } super.close(); }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
close
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
@Override protected boolean isConnected(SocketChannel channel) { return super.isConnected(channel) && channel.isOpen(); }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
isConnected
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
private void closeSocketChannel() throws IOException { if (sslEngine != null) { sslEngine.closeOutbound(); if (sslSession != null) { doHandshake(channel(), sslEngine, ByteBuffer.allocate(sslSession.getPacketBufferSize()), ByteBuffer.allocate(sslSession.getPacketBufferSize())); } } }
@param host the host, must not be {@literal null}. @param port the port. @param connectTimeoutMs connection timeout, in {@link TimeUnit#MILLISECONDS}. @param readTimeoutMs read timeout, in {@link TimeUnit#MILLISECONDS}. @param deliveryAttempts number of delivery attempts. @param keepAlive {@literal true} to enable TCP keep-alive. @param backoff Backoff strategy to activate if a socket sender buffer is full and several attempts to write to the socket are unsuccessful due to it. @param writeBackoffThreshold attempts to write to a socket before a backoff will be activated. @param errorReporter the error reporter, must not be {@literal null}. @param sslContext the SSL context, must not be {@literal null}. @throws IOException in case of I/O errors
closeSocketChannel
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfTCPSSLSender.java
MIT
@Override protected ByteBuffer initialValue() { return ByteBuffer.allocateDirect(INITIAL_BUFFER_SIZE); }
@author https://github.com/t0xa/gelfj @author Mark Paluch
initialValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
MIT
@Override protected ByteBuffer initialValue() { return ByteBuffer.allocateDirect(INITIAL_BUFFER_SIZE); }
@author https://github.com/t0xa/gelfj @author Mark Paluch
initialValue
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
MIT
public boolean sendMessage(GelfMessage message) { if (INITIAL_BUFFER_SIZE == 0) { return sendDatagrams(message.toUDPBuffers()); } return sendDatagrams(GelfBuffers.toUDPBuffers(message, writeBuffers, tempBuffers)); }
@author https://github.com/t0xa/gelfj @author Mark Paluch
sendMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
MIT
private boolean sendDatagrams(ByteBuffer[] bytesList) { try { // (re)-connect if necessary if (!isConnected()) { synchronized (ioLock) { connect(); } } for (ByteBuffer buffer : bytesList) { synchronized (ioLock) { while (buffer.hasRemaining()) { channel().write(buffer); } } } } catch (IOException e) { reportError(e.getMessage(), new IOException("Cannot send data to " + getHost() + ":" + getPort(), e)); return false; } return true; }
@author https://github.com/t0xa/gelfj @author Mark Paluch
sendDatagrams
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
MIT
protected void connect() throws IOException { if (isConnected()) { return; } if (channel() == null) { setChannel(DatagramChannel.open()); } else if (!channel().isOpen()) { Closer.close(channel()); setChannel(DatagramChannel.open()); } channel().configureBlocking(false); InetSocketAddress inetSocketAddress = new InetSocketAddress(getHost(), getPort()); try { DatagramChannel connect = channel().connect(inetSocketAddress); setChannel(connect); } catch (UnresolvedAddressException | IOException e) { reportError(e.getMessage(), e); } }
@author https://github.com/t0xa/gelfj @author Mark Paluch
connect
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
MIT
@Override protected boolean isConnected(DatagramChannel channel) { return channel.isConnected(); }
@author https://github.com/t0xa/gelfj @author Mark Paluch
isConnected
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/GelfUDPSender.java
MIT
static Map<String, String> parse(URI uri) { Map<String, String> result = new HashMap<>(); String queryString = uri.getQuery(); if (queryString == null && uri.getSchemeSpecificPart() != null && uri.getSchemeSpecificPart().contains("?")) { queryString = uri.getSchemeSpecificPart().substring(uri.getSchemeSpecificPart().indexOf('?') + 1); } if (queryString == null) { return result; } StringTokenizer st = new StringTokenizer(queryString, "&;"); while (st.hasMoreTokens()) { String queryParam = st.nextToken(); int equalsIndex = queryParam.indexOf('='); if (equalsIndex != -1) { String key = queryParam.substring(0, equalsIndex); String value = queryParam.substring(equalsIndex + 1); result.put(key.toLowerCase(), value); } } return result; }
Parse the query part of an {@link URI} to a single-valued key-value map. All keys are transformed to lower-case. @param uri @return the key-value map.
parse
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
MIT
static long getTimeAsMs(Map<String, String> map, String key, long defaultTimeMs) { String value = map.get(key.toLowerCase()); if (value == null || value.trim().equals("")) { return defaultTimeMs; } int numbersEnd = 0; while (numbersEnd < value.length() && Character.isDigit(value.charAt(numbersEnd))) { numbersEnd++; } if (numbersEnd == 0) { return defaultTimeMs; } String numbers = value.substring(0, numbersEnd); long timeValue = Long.parseLong(numbers); String suffix = value.substring(numbersEnd); TimeUnit timeoutUnit = TIME_UNIT_MAP.get(suffix); if (timeoutUnit == null) { timeoutUnit = TimeUnit.MILLISECONDS; } return timeoutUnit.toMillis(timeValue); }
Parse the query part of an {@link URI} to a single-valued key-value map. All keys are transformed to lower-case. @param uri @return the key-value map.
getTimeAsMs
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
MIT
public static int getInt(Map<String, String> map, String key, int defaultValue) { String value = map.get(key.toLowerCase()); if (value == null || value.trim().equals("")) { return defaultValue; } return Integer.parseInt(value); }
Parse the query part of an {@link URI} to a single-valued key-value map. All keys are transformed to lower-case. @param uri @return the key-value map.
getInt
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
MIT
public static boolean getString(Map<String, String> map, String key, boolean defaultValue) { String value = map.get(key.toLowerCase()); if (value == null || value.trim().equals("")) { return defaultValue; } return "true".equalsIgnoreCase(value); }
Parse the query part of an {@link URI} to a single-valued key-value map. All keys are transformed to lower-case. @param uri @return the key-value map.
getString
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
MIT
public static String getHost(URI uri) { String host = uri.getHost(); if (host == null) { host = uri.getSchemeSpecificPart(); } if (host.contains("?")) { host = host.substring(0, host.indexOf('?')); } return host; }
Parse the query part of an {@link URI} to a single-valued key-value map. All keys are transformed to lower-case. @param uri @return the key-value map.
getHost
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/QueryStringParser.java
MIT
@Override public boolean supports(String host) { return host.startsWith(RedisSenderConstants.REDIS_SCHEME + ":") || host.startsWith(RedisSenderConstants.REDIS_SENTINEL_SCHEME + ":"); }
{@link GelfSenderProvider} to provide {@link GelfREDISSender}. @author https://github.com/Batigoal/logstash-gelf.git @since 1.4
supports
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisGelfSenderProvider.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisGelfSenderProvider.java
MIT
@Override public GelfSender create(GelfSenderConfiguration configuration) throws IOException { String graylogHost = configuration.getHost(); URI hostUri = URI.create(graylogHost); int port = hostUri.getPort(); if (port <= 0) { port = configuration.getPort(); } if (port <= 0) { port = Protocol.DEFAULT_PORT; } if (hostUri.getFragment() == null || hostUri.getFragment().trim().equals("")) { throw new IllegalArgumentException("Redis URI must specify fragment"); } if (hostUri.getHost() == null) { throw new IllegalArgumentException("Redis URI must specify host"); } Pool<Jedis> pool = RedisPoolHolder.getInstance().getJedisPool(hostUri, port); return new GelfREDISSender<>(pool, hostUri.getFragment(), configuration.getErrorReporter()); }
{@link GelfSenderProvider} to provide {@link GelfREDISSender}. @author https://github.com/Batigoal/logstash-gelf.git @since 1.4
create
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisGelfSenderProvider.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisGelfSenderProvider.java
MIT
public static RedisPoolHolder getInstance() { return INSTANCE; }
Pool holder for {@link Pool} that keeps track of Jedis pools identified by {@link URI}. This implementation synchronizes {@link #getJedisPool(URI, int)} and {@link Pool#destroy()} calls to avoid lingering resources and acquisition of disposed resources. creation @author Mark Paluch
getInstance
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
public Pool<Jedis> getJedisPool(URI hostURI, int configuredPort) { synchronized (mutex) { String lowerCasedConnectionString = hostURI.toString().toLowerCase(); final String cleanConnectionString = hostURI.getFragment() != null ? lowerCasedConnectionString.substring(0, lowerCasedConnectionString.length() - hostURI.getFragment().length()) : lowerCasedConnectionString; if (standalonePools.containsKey(cleanConnectionString)) { JedisPoolProxy poolProxy = standalonePools.get(cleanConnectionString); poolProxy.incrementRefCnt(); return poolProxy; } Pool<Jedis> jedisPool = JedisPoolFactory.createJedisPool(hostURI, configuredPort, Protocol.DEFAULT_TIMEOUT); JedisPoolProxy proxy = new JedisPoolProxy(jedisPool, new Runnable() { @Override public void run() { standalonePools.remove(cleanConnectionString); } }); standalonePools.put(cleanConnectionString, proxy); return proxy; } }
Pool holder for {@link Pool} that keeps track of Jedis pools identified by {@link URI}. This implementation synchronizes {@link #getJedisPool(URI, int)} and {@link Pool#destroy()} calls to avoid lingering resources and acquisition of disposed resources. creation @author Mark Paluch
getJedisPool
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public void run() { standalonePools.remove(cleanConnectionString); }
Pool holder for {@link Pool} that keeps track of Jedis pools identified by {@link URI}. This implementation synchronizes {@link #getJedisPool(URI, int)} and {@link Pool#destroy()} calls to avoid lingering resources and acquisition of disposed resources. creation @author Mark Paluch
run
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public String getScheme() { return RedisSenderConstants.REDIS_SCHEME; }
Singleton for administration of commonly used jedis pools @author https://github.com/Batigoal/logstash-gelf.git @author Mark Paluch
getScheme
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public redis.clients.jedis.util.Pool<Jedis> createPool(URI hostURI, int configuredPort, int timeoutMs) { String password = (hostURI.getUserInfo() != null) ? hostURI.getUserInfo().split(":", 2)[1] : null; int database = Protocol.DEFAULT_DATABASE; if (hostURI.getPath() != null && hostURI.getPath().length() > 1) { database = Integer.parseInt(hostURI.getPath().split("/", 2)[1]); } int port = hostURI.getPort() > 0 ? hostURI.getPort() : configuredPort; return new JedisPool(new JedisPoolConfig(), hostURI.getHost(), port, timeoutMs, password, database); }
Create a Jedis Pool for standalone Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
createPool
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public String getScheme() { return RedisSenderConstants.REDIS_SENTINEL_SCHEME; }
Create a Jedis Pool for standalone Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getScheme
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public redis.clients.jedis.util.Pool<Jedis> createPool(URI hostURI, int configuredPort, int timeoutMs) { Set<String> sentinels = getSentinels(hostURI); String masterName = getMasterName(hostURI); // No logging for Jedis Sentinel at all. Logger.getLogger(JedisSentinelPool.class.getName()).setLevel(Level.OFF); String password = (hostURI.getUserInfo() != null) ? hostURI.getUserInfo().split(":", 2)[1] : null; int database = Protocol.DEFAULT_DATABASE; if (hostURI.getPath() != null && hostURI.getPath().length() > 1) { database = Integer.parseInt(hostURI.getPath().split("/", 2)[1]); } return new JedisSentinelPool(masterName, sentinels, new JedisPoolConfig(), timeoutMs, password, database); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
createPool
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
protected String getMasterName(URI hostURI) { String masterName = "master"; if (hostURI.getQuery() != null) { String[] keyValues = hostURI.getQuery().split("\\&"); for (String keyValue : keyValues) { String[] parts = keyValue.split("\\="); if (parts.length != 2) { continue; } if (parts[0].equals(MASTER_ID)) { masterName = parts[1].trim(); } } } return masterName; }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getMasterName
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
protected Set<String> getSentinels(URI hostURI) { Set<String> sentinels = new HashSet<>(); String[] sentinelHostNames = hostURI.getHost().split("\\,"); for (String sentinelHostName : sentinelHostNames) { if (sentinelHostName.contains(":")) { sentinels.add(sentinelHostName); } else if (hostURI.getPort() > 0) { sentinels.add(sentinelHostName + ":" + hostURI.getPort()); } } return sentinels; }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getSentinels
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
public static redis.clients.jedis.util.Pool<Jedis> createJedisPool(URI hostURI, int configuredPort, int timeoutMs) { for (JedisPoolFactory provider : JedisPoolFactory.values()) { if (provider.getScheme().equals(hostURI.getScheme())) { return provider.createPool(hostURI, configuredPort, timeoutMs); } } throw new IllegalArgumentException("Scheme " + hostURI.getScheme() + " not supported"); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
createJedisPool
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public void close() { delegate.close(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
close
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public boolean isClosed() { return delegate.isClosed(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
isClosed
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public void initPool(GenericObjectPoolConfig<Jedis> poolConfig, PooledObjectFactory<Jedis> factory) { delegate.initPool(poolConfig, factory); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
initPool
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public Jedis getResource() { return delegate.getResource(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getResource
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public void returnResourceObject(Jedis resource) { throw new UnsupportedOperationException(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
returnResourceObject
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public void destroy() { synchronized (mutex) { long val = refCnt.decrementAndGet(); if (val == 0) { onDestroy.run(); delegate.destroy(); } } }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
destroy
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public int getNumActive() { return delegate.getNumActive(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getNumActive
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public int getNumIdle() { return delegate.getNumIdle(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getNumIdle
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public int getNumWaiters() { return delegate.getNumWaiters(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getNumWaiters
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public long getMeanBorrowWaitTimeMillis() { return delegate.getMeanBorrowWaitTimeMillis(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getMeanBorrowWaitTimeMillis
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public long getMaxBorrowWaitTimeMillis() { return delegate.getMaxBorrowWaitTimeMillis(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
getMaxBorrowWaitTimeMillis
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
@Override public void addObjects(int count) { throw new UnsupportedOperationException(); }
Create a Jedis Pool for sentinel Redis Operations. @param hostURI @param configuredPort @param timeoutMs @return Pool of Jedis
addObjects
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/intern/sender/RedisPoolHolder.java
MIT
public boolean isEnabled() { return enabled; }
Logging-Handler for GELF (Graylog Extended Logging Format). This Java-Util-Logging Handler creates GELF Messages and posts them using UDP (default) or TCP. Following parameters are supported/needed: <ul> <li>host (Mandatory): Hostname/IP-Address of the Logstash Host <ul> <li>(the host) for UDP, e.g. 127.0.0.1 or some.host.com</li> <li>See docs for more details</li> </ul> </li> <li>enabled (Optional): Whether this handler is enabled, default true</li> <li>port (Optional): Port, default 12201</li> <li>originHost (Optional): Originating Hostname, default FQDN Hostname</li> <li>extractStackTrace (Optional): Post Stack-Trace to StackTrace field (true/false/throwable reference [0 = throwable, 1 = throwable.cause, -1 = root cause]), default false</li> <li>filterStackTrace (Optional): Perform Stack-Trace filtering (true/false), default false</li> <li>includeLogMessageParameters (Optional): Include message parameters from the log event (see {@link LogRecord#getParameters()}, default true</li> <li>mdcProfiling (Optional): Perform Profiling (Call-Duration) based on MDC Data. See <a href="#mdcProfiling">MDC Profiling</a>, default false</li> <li>facility (Optional): Name of the Facility, default gelf-java</li> <li>level (Optional): Log-Level, default INFO</li> <li>filter (Optional): Class-Name of a Log-Filter, default none</li> <li>additionalFields(number) (Optional): Post additional fields. Eg. .GelfLogHandler.additionalFields=fieldName=Value,field2=value2</li> <li>additionalFieldTypes (Optional): Type specification for additional and MDC fields. Supported types: String, long, Long, double, Double and discover (default if not specified, discover field type on parseability). Eg. field=String,field2=double</li> <li>mdcFields (Optional): Post additional fields, pull Values from MDC. Name of the Fields are comma-separated .JBoss7GelfLogHandler.mdcFields=Application,Version,SomeOtherFieldName</li> <li>dynamicMdcFields (Optional): Dynamic MDC Fields allows you to extract MDC values based on one or more regular expressions. Multiple regex are comma-separated. The name of the MDC entry is used as GELF field name. .JBoss7GelfLogHandler.dynamicMdcFields=mdc.*,[mdc|MDC]fields</li> <li>dynamicMdcFieldTypes (Optional): Pattern-based type specification for additional and MDC fields. Key-value pairs are comma-separated. Supported types: String, long, Long, double, Double. Eg. my_field.*=String,business\..*\.field=double</li> <li>includeFullMdc (Optional): Include all fields from the MDC, default false</li> </ul> <a name="mdcProfiling"></a> <h2>MDC Profiling</h2> <p> MDC Profiling allows to calculate the runtime from request start up to the time until the log message was generated. You must set one value in the MDC: <ul> <li>profiling.requestStart.millis: Time Millis of the Request-Start (Long or String)</li> </ul> <p> Two values are set by the Log Appender: </p> <ul> <li>profiling.requestEnd: End-Time of the Request-End in Date.toString-representation</li> <li>profiling.requestDuration: Duration of the request (e.g. 205ms, 16sec)</li> </ul> The {@link #publish(LogRecord)} method is thread-safe and may be called by different threads at any time. @author Mark Paluch
isEnabled
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
public void setEnabled(boolean enabled) { this.enabled = enabled; }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
setEnabled
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
@Override protected void initializeDefaultFields() { gelfMessageAssembler.addFields(LogMessageField.getDefaultMapping(Time, Severity, ThreadName, SourceClassName, SourceMethodName, SourceSimpleClassName, LoggerName, NDC)); }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
initializeDefaultFields
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
@Override public boolean isLoggable(LogRecord record) { return enabled && super.isLoggable(record); }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
isLoggable
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
@Override public void publish(LogRecord record) { super.publish(ExtLogRecord.wrap(record)); }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
publish
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
@Override protected GelfMessageAssembler createGelfMessageAssembler() { return new MdcGelfMessageAssembler(); }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
createGelfMessageAssembler
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
@Override protected GelfMessage createGelfMessage(final LogRecord record) { return getGelfMessageAssembler().createGelfMessage(new JBoss7JulLogEvent((ExtLogRecord) record)); }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
createGelfMessage
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
public boolean isMdcProfiling() { return getGelfMessageAssembler().isMdcProfiling(); }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
isMdcProfiling
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
public boolean isIncludeFullMdc() { return getGelfMessageAssembler().isIncludeFullMdc(); }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
isIncludeFullMdc
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
private MdcGelfMessageAssembler getGelfMessageAssembler() { return (MdcGelfMessageAssembler) gelfMessageAssembler; }
Manually enable/disable the handler. This is also called by wildfly logger setup routines on server-startup with the value of the "enabled" attribute of {@code <custom-handler>}. @param enabled {@literal false} to disable this handler.
getGelfMessageAssembler
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jboss7/JBoss7GelfLogHandler.java
MIT
private void configure() { String cname = getClass().getName(); LogManager manager = LogManager.getLogManager(); String val = manager.getProperty(cname + ".fields"); if (val != null) { setFields(val); } val = manager.getProperty(cname + ".version"); if (val != null) { setVersion(val); } val = manager.getProperty(cname + ".facility"); if (val != null) { setFacility(val); } val = manager.getProperty(cname + ".extractStackTrace"); if (val != null) { setExtractStackTrace(val); } val = manager.getProperty(cname + ".filterStackTrace"); if (val != null) { setFilterStackTrace(Boolean.valueOf(val)); } val = manager.getProperty(cname + ".includeLogMessageParameters"); if (val != null) { setIncludeLogMessageParameters(Boolean.valueOf(val)); } val = manager.getProperty(cname + ".includeLocation"); if (val != null) { setIncludeLocation(Boolean.valueOf(val)); } val = manager.getProperty(cname + ".timestampPattern"); if (val != null) { setTimestampPattern(val); } val = manager.getProperty(cname + ".additionalFields"); if (val != null) { setAdditionalFields(val); } val = manager.getProperty(cname + ".additionalFieldTypes"); if (val != null) { setAdditionalFieldTypes(val); } val = manager.getProperty(cname + ".originHost"); if (val != null) { setOriginHost(val); } val = manager.getProperty(cname + ".linebreak"); if (val != null) { setLineBreak(val); } }
Log-Formatter for JSON using fields specified within GELF. This formatter will produce a JSON object for each log event. Example: <code> { "timestamp": "1439319236.722", "SourceClassName": "biz.paluch.logging.gelf.wildfly.WildFlyGelfLogFormatterTest", "SourceMethodName": "testDefaults", "level": "6", "SourceSimpleClassName": "WildFlyGelfLogFormatterTest", "facility": "logstash-gelf", "full_message": "foo bar test log message", "short_message": "foo bar test log message", "MySeverity": "INFO", "LoggerName": "biz.paluch.logging.gelf.wildfly.WildFlyGelfLogFormatterTest", "Thread": "main", "Time": "2015-08-11 20:53:56,0722" } </code> Following parameters are supported/needed: <ul> <li>lineBreak (Optional): End of line, platform dependent default value, see {@code System.getProperty("line.separator")}</li> <li>fields (Optional): Comma-separated list of log event fields that should be included in the JSON. Defaults to {@code Time, Severity, ThreadName, SourceClassName, SourceMethodName, SourceSimpleClassName, LoggerName}</li> <li>originHost (Optional): Originating Hostname, default FQDN Hostname</li> <li>extractStackTrace (Optional): Post Stack-Trace to StackTrace field (true/false/throwable reference [0 = throwable, 1 = throwable.cause, -1 = root cause]), default false</li> <li>filterStackTrace (Optional): Perform Stack-Trace filtering (true/false), default false</li> <li>includeLocation (Optional): Include source code location, default true</li> <li>includeLogMessageParameters (Optional): Include message parameters from the log event (see {@link LogRecord#getParameters()}, default true</li> <li>facility (Optional): Name of the Facility, default gelf-java</li> <li>additionalFields(number) (Optional): Post additional fields. Eg. fieldName=Value,field2=value2</li> <li>additionalFieldTypes (Optional): Type specification for additional and MDC fields. Supported types: String, long, Long, double, Double and discover (default if not specified, discover field type on parseability). Eg. field=String,field2=double</li> </ul> @author Greg Peterson @since 1.14.0
configure
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jul/GelfFormatter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jul/GelfFormatter.java
MIT
@Override public String format(final LogRecord record) { if (!wasSetFieldsCalled) { addFields(SUPPORTED_FIELDS); } GelfMessage gelfMessage = gelfMessageAssembler.createGelfMessage(new JulLogEvent(record)); return gelfMessage.toJson("") + lineBreak; }
Log-Formatter for JSON using fields specified within GELF. This formatter will produce a JSON object for each log event. Example: <code> { "timestamp": "1439319236.722", "SourceClassName": "biz.paluch.logging.gelf.wildfly.WildFlyGelfLogFormatterTest", "SourceMethodName": "testDefaults", "level": "6", "SourceSimpleClassName": "WildFlyGelfLogFormatterTest", "facility": "logstash-gelf", "full_message": "foo bar test log message", "short_message": "foo bar test log message", "MySeverity": "INFO", "LoggerName": "biz.paluch.logging.gelf.wildfly.WildFlyGelfLogFormatterTest", "Thread": "main", "Time": "2015-08-11 20:53:56,0722" } </code> Following parameters are supported/needed: <ul> <li>lineBreak (Optional): End of line, platform dependent default value, see {@code System.getProperty("line.separator")}</li> <li>fields (Optional): Comma-separated list of log event fields that should be included in the JSON. Defaults to {@code Time, Severity, ThreadName, SourceClassName, SourceMethodName, SourceSimpleClassName, LoggerName}</li> <li>originHost (Optional): Originating Hostname, default FQDN Hostname</li> <li>extractStackTrace (Optional): Post Stack-Trace to StackTrace field (true/false/throwable reference [0 = throwable, 1 = throwable.cause, -1 = root cause]), default false</li> <li>filterStackTrace (Optional): Perform Stack-Trace filtering (true/false), default false</li> <li>includeLocation (Optional): Include source code location, default true</li> <li>includeLogMessageParameters (Optional): Include message parameters from the log event (see {@link LogRecord#getParameters()}, default true</li> <li>facility (Optional): Name of the Facility, default gelf-java</li> <li>additionalFields(number) (Optional): Post additional fields. Eg. fieldName=Value,field2=value2</li> <li>additionalFieldTypes (Optional): Type specification for additional and MDC fields. Supported types: String, long, Long, double, Double and discover (default if not specified, discover field type on parseability). Eg. field=String,field2=double</li> </ul> @author Greg Peterson @since 1.14.0
format
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jul/GelfFormatter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jul/GelfFormatter.java
MIT
public void setFields(String fieldSpec) { String[] properties = fieldSpec.split(MULTI_VALUE_DELIMITTER); List<LogMessageField.NamedLogField> fields = new ArrayList<>(); for (String field : properties) { LogMessageField.NamedLogField namedLogField = LogMessageField.NamedLogField.byName(field.trim()); if (namedLogField == null) { throw new IllegalArgumentException("Cannot resolve field name '" + field + "' to a field. Supported field names are: " + SUPPORTED_FIELDS); } if (!SUPPORTED_FIELDS.contains(namedLogField)) { throw new IllegalArgumentException("Field '" + field + "' is not supported. Supported field names are: " + SUPPORTED_FIELDS); } fields.add(namedLogField); } addFields(fields); }
Log-Formatter for JSON using fields specified within GELF. This formatter will produce a JSON object for each log event. Example: <code> { "timestamp": "1439319236.722", "SourceClassName": "biz.paluch.logging.gelf.wildfly.WildFlyGelfLogFormatterTest", "SourceMethodName": "testDefaults", "level": "6", "SourceSimpleClassName": "WildFlyGelfLogFormatterTest", "facility": "logstash-gelf", "full_message": "foo bar test log message", "short_message": "foo bar test log message", "MySeverity": "INFO", "LoggerName": "biz.paluch.logging.gelf.wildfly.WildFlyGelfLogFormatterTest", "Thread": "main", "Time": "2015-08-11 20:53:56,0722" } </code> Following parameters are supported/needed: <ul> <li>lineBreak (Optional): End of line, platform dependent default value, see {@code System.getProperty("line.separator")}</li> <li>fields (Optional): Comma-separated list of log event fields that should be included in the JSON. Defaults to {@code Time, Severity, ThreadName, SourceClassName, SourceMethodName, SourceSimpleClassName, LoggerName}</li> <li>originHost (Optional): Originating Hostname, default FQDN Hostname</li> <li>extractStackTrace (Optional): Post Stack-Trace to StackTrace field (true/false/throwable reference [0 = throwable, 1 = throwable.cause, -1 = root cause]), default false</li> <li>filterStackTrace (Optional): Perform Stack-Trace filtering (true/false), default false</li> <li>includeLocation (Optional): Include source code location, default true</li> <li>includeLogMessageParameters (Optional): Include message parameters from the log event (see {@link LogRecord#getParameters()}, default true</li> <li>facility (Optional): Name of the Facility, default gelf-java</li> <li>additionalFields(number) (Optional): Post additional fields. Eg. fieldName=Value,field2=value2</li> <li>additionalFieldTypes (Optional): Type specification for additional and MDC fields. Supported types: String, long, Long, double, Double and discover (default if not specified, discover field type on parseability). Eg. field=String,field2=double</li> </ul> @author Greg Peterson @since 1.14.0
setFields
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jul/GelfFormatter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jul/GelfFormatter.java
MIT
private void addFields(Collection<LogMessageField.NamedLogField> fields) { gelfMessageAssembler.addFields(LogMessageField.getDefaultMapping(fields .toArray(new LogMessageField.NamedLogField[fields.size()]))); wasSetFieldsCalled = true; }
Log-Formatter for JSON using fields specified within GELF. This formatter will produce a JSON object for each log event. Example: <code> { "timestamp": "1439319236.722", "SourceClassName": "biz.paluch.logging.gelf.wildfly.WildFlyGelfLogFormatterTest", "SourceMethodName": "testDefaults", "level": "6", "SourceSimpleClassName": "WildFlyGelfLogFormatterTest", "facility": "logstash-gelf", "full_message": "foo bar test log message", "short_message": "foo bar test log message", "MySeverity": "INFO", "LoggerName": "biz.paluch.logging.gelf.wildfly.WildFlyGelfLogFormatterTest", "Thread": "main", "Time": "2015-08-11 20:53:56,0722" } </code> Following parameters are supported/needed: <ul> <li>lineBreak (Optional): End of line, platform dependent default value, see {@code System.getProperty("line.separator")}</li> <li>fields (Optional): Comma-separated list of log event fields that should be included in the JSON. Defaults to {@code Time, Severity, ThreadName, SourceClassName, SourceMethodName, SourceSimpleClassName, LoggerName}</li> <li>originHost (Optional): Originating Hostname, default FQDN Hostname</li> <li>extractStackTrace (Optional): Post Stack-Trace to StackTrace field (true/false/throwable reference [0 = throwable, 1 = throwable.cause, -1 = root cause]), default false</li> <li>filterStackTrace (Optional): Perform Stack-Trace filtering (true/false), default false</li> <li>includeLocation (Optional): Include source code location, default true</li> <li>includeLogMessageParameters (Optional): Include message parameters from the log event (see {@link LogRecord#getParameters()}, default true</li> <li>facility (Optional): Name of the Facility, default gelf-java</li> <li>additionalFields(number) (Optional): Post additional fields. Eg. fieldName=Value,field2=value2</li> <li>additionalFieldTypes (Optional): Type specification for additional and MDC fields. Supported types: String, long, Long, double, Double and discover (default if not specified, discover field type on parseability). Eg. field=String,field2=double</li> </ul> @author Greg Peterson @since 1.14.0
addFields
java
mp911de/logstash-gelf
src/main/java/biz/paluch/logging/gelf/jul/GelfFormatter.java
https://github.com/mp911de/logstash-gelf/blob/master/src/main/java/biz/paluch/logging/gelf/jul/GelfFormatter.java
MIT