This repository has been archived by the owner on Jun 29, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
265 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,6 @@ | ||
package biz.paluch.logging.gelf; | ||
|
||
import static biz.paluch.logging.gelf.GelfMessageBuilder.newInstance; | ||
import biz.paluch.logging.RuntimeContainer; | ||
import biz.paluch.logging.StackTraceFilter; | ||
import biz.paluch.logging.gelf.intern.GelfMessage; | ||
import biz.paluch.logging.gelf.intern.HostAndPortProvider; | ||
import static biz.paluch.logging.gelf.GelfMessageBuilder.*; | ||
|
||
import java.io.PrintWriter; | ||
import java.io.StringWriter; | ||
|
@@ -14,18 +10,26 @@ | |
import java.util.Date; | ||
import java.util.List; | ||
|
||
import biz.paluch.logging.RuntimeContainer; | ||
import biz.paluch.logging.StackTraceFilter; | ||
import biz.paluch.logging.gelf.intern.GelfMessage; | ||
import biz.paluch.logging.gelf.intern.HostAndPortProvider; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
* @since 26.09.13 15:05 | ||
*/ | ||
public class GelfMessageAssembler implements HostAndPortProvider { | ||
|
||
private static final int MAX_SHORT_MESSAGE_LENGTH = 250; | ||
private static final int MAX_PORT_NUMBER = 65535; | ||
private static final int MAX_MESSAGE_SIZE = Integer.MAX_VALUE; | ||
|
||
public static final String FIELD_MESSAGE_PARAM = "MessageParam"; | ||
public static final String FIELD_STACK_TRACE = "StackTrace"; | ||
|
||
private String host; | ||
private String version = GelfMessage.GELF_VERSION; | ||
private String originHost; | ||
private int port; | ||
private String facility; | ||
|
@@ -53,7 +57,7 @@ public void initialize(PropertyProvider propertyProvider) { | |
port = propertyProvider.getProperty(PropertyProvider.PROPERTY_GRAYLOG_PORT); | ||
} | ||
|
||
if (port != null) { | ||
if (port != null && !"".equals(port)) { | ||
this.port = Integer.parseInt(port); | ||
} | ||
|
||
|
@@ -63,6 +67,11 @@ public void initialize(PropertyProvider propertyProvider) { | |
|
||
setupStaticFields(propertyProvider); | ||
facility = propertyProvider.getProperty(PropertyProvider.PROPERTY_FACILITY); | ||
String version = propertyProvider.getProperty(PropertyProvider.PROPERTY_VERSION); | ||
|
||
if (version != null && !"".equals(version)) { | ||
this.version = version; | ||
} | ||
|
||
String messageSize = propertyProvider.getProperty(PropertyProvider.PROPERTY_MAX_MESSAGE_SIZE); | ||
if (messageSize != null) { | ||
|
@@ -88,6 +97,7 @@ public GelfMessage createGelfMessage(LogEvent logEvent) { | |
|
||
builder.withShortMessage(shortMessage).withFullMessage(message).withJavaTimestamp(logEvent.getLogTimestamp()); | ||
builder.withLevel(logEvent.getSyslogLevel()); | ||
builder.withVersion(getVersion()); | ||
|
||
for (MessageField field : fields) { | ||
Values values = getValues(logEvent, field); | ||
|
@@ -215,6 +225,9 @@ public int getPort() { | |
} | ||
|
||
public void setPort(int port) { | ||
if (port > MAX_PORT_NUMBER || port < 1) { | ||
throw new IllegalArgumentException("Invalid port number: " + port + ", supported range: 1-" + MAX_PORT_NUMBER); | ||
} | ||
this.port = port; | ||
} | ||
|
||
|
@@ -255,7 +268,26 @@ public int getMaximumMessageSize() { | |
} | ||
|
||
public void setMaximumMessageSize(int maximumMessageSize) { | ||
|
||
if (maximumMessageSize > MAX_MESSAGE_SIZE || maximumMessageSize < 1) { | ||
throw new IllegalArgumentException("Invalid maximum message size: " + maximumMessageSize + ", supported range: 1-" | ||
+ MAX_MESSAGE_SIZE); | ||
} | ||
|
||
this.maximumMessageSize = maximumMessageSize; | ||
} | ||
|
||
public String getVersion() { | ||
return version; | ||
} | ||
|
||
public void setVersion(String version) { | ||
|
||
if (!GelfMessage.GELF_VERSION_1_0.equals(version) && !GelfMessage.GELF_VERSION_1_1.equals(version)) { | ||
throw new IllegalArgumentException("Invalid GELF version: " + version + ", supported range: " | ||
+ GelfMessage.GELF_VERSION_1_0 + ", " + GelfMessage.GELF_VERSION_1_1); | ||
} | ||
|
||
this.version = version; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
package biz.paluch.logging.gelf.jul; | ||
|
||
import biz.paluch.logging.gelf.GelfUtil; | ||
import biz.paluch.logging.gelf.LogEvent; | ||
import biz.paluch.logging.gelf.LogMessageField; | ||
import biz.paluch.logging.gelf.MessageField; | ||
import biz.paluch.logging.gelf.Values; | ||
|
||
import java.lang.management.ManagementFactory; | ||
import java.lang.management.ThreadInfo; | ||
import java.lang.management.ThreadMXBean; | ||
|
@@ -18,6 +12,9 @@ | |
import java.util.logging.Level; | ||
import java.util.logging.LogRecord; | ||
|
||
import biz.paluch.logging.gelf.*; | ||
import biz.paluch.logging.gelf.intern.GelfMessage; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Paluch</a> | ||
* @since 26.09.13 15:22 | ||
|
@@ -130,7 +127,7 @@ private int levelToSyslogLevel(final Level level) { | |
} else if (level == Level.INFO) { | ||
syslogLevel = 6; | ||
} else { | ||
syslogLevel = 7; | ||
syslogLevel = GelfMessage.DEFAUL_LEVEL; | ||
} | ||
return syslogLevel; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.