|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectch.qos.logback.core.spi.ContextAwareBase
ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>
me.moocar.logbackgelf.GelfAppender
public class GelfAppender
Responsible for Formatting a log event and sending it to a Graylog2 Server. Note that you can't swap in a different Layout since the GELF format is static.
| Field Summary |
|---|
| Fields inherited from class ch.qos.logback.core.AppenderBase |
|---|
name, started |
| Fields inherited from class ch.qos.logback.core.spi.ContextAwareBase |
|---|
context |
| Constructor Summary | |
|---|---|
GelfAppender()
|
|
| Method Summary | |
|---|---|
void |
addAdditionalField(String keyValue)
Add an additional field. |
void |
addStaticAdditionalField(String keyValue)
Add a staticAdditional field. |
protected void |
append(ch.qos.logback.classic.spi.ILoggingEvent logEvent)
The main append method. |
Map<String,String> |
getAdditionalFields()
additional fields to add to the gelf message. |
int |
getChunkThreshold()
|
String |
getFacility()
The name of your service. |
String |
getGraylog2ServerHost()
The hostname of the graylog2 server to send messages to |
int |
getGraylog2ServerPort()
The port of the graylog2 server to send messages to |
String |
getGraylog2ServerVersion()
|
String |
getHostName()
Override the local hostname using a config option |
String |
getMessagePattern()
|
int |
getShortMessageLength()
The length of the message to truncate to |
String |
getShortMessagePattern()
|
Map<String,String> |
getStaticAdditionalFields()
static additional fields to add to every gelf message. |
boolean |
isIncludeFullMDC()
Indicates if all values from the MDC should be included in the gelf message or only the once listed as additional fields. |
boolean |
isUseLoggerName()
If true, an additional field call "_loggerName" will be added to each gelf message. |
boolean |
isUseMarker()
|
boolean |
isUseThreadName()
If true, an additional field call "_threadName" will be added to each gelf message. |
void |
setAdditionalFields(Map<String,String> additionalFields)
|
void |
setChunkThreshold(int chunkThreshold)
|
void |
setFacility(String facility)
|
void |
setGraylog2ServerHost(String graylog2ServerHost)
|
void |
setGraylog2ServerPort(int graylog2ServerPort)
|
void |
setGraylog2ServerVersion(String graylog2ServerVersion)
|
void |
setHostName(String hostName)
|
void |
setIncludeFullMDC(boolean includeFullMDC)
|
void |
setMessagePattern(String messagePattern)
|
void |
setShortMessageLength(int shortMessageLength)
|
void |
setShortMessagePattern(String shortMessagePattern)
|
void |
setStaticAdditionalFields(Map<String,String> staticAdditionalFields)
|
void |
setUseLoggerName(boolean useLoggerName)
|
void |
setUseMarker(boolean useMarker)
|
void |
setUseThreadName(boolean useThreadName)
|
void |
start()
|
| Methods inherited from class ch.qos.logback.core.AppenderBase |
|---|
addFilter, clearAllFilters, doAppend, getCopyOfAttachedFiltersList, getFilterChainDecision, getName, isStarted, setName, stop, toString |
| Methods inherited from class ch.qos.logback.core.spi.ContextAwareBase |
|---|
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, getDeclaredOrigin, getStatusManager, setContext |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface ch.qos.logback.core.spi.ContextAware |
|---|
addError, addError, addInfo, addInfo, addStatus, addWarn, addWarn, getContext, setContext |
| Constructor Detail |
|---|
public GelfAppender()
| Method Detail |
|---|
protected void append(ch.qos.logback.classic.spi.ILoggingEvent logEvent)
append in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>logEvent - The event that we are loggingpublic void start()
start in interface ch.qos.logback.core.spi.LifeCyclestart in class ch.qos.logback.core.AppenderBase<ch.qos.logback.classic.spi.ILoggingEvent>public String getFacility()
public void setFacility(String facility)
public String getGraylog2ServerHost()
public void setGraylog2ServerHost(String graylog2ServerHost)
public int getGraylog2ServerPort()
public void setGraylog2ServerPort(int graylog2ServerPort)
public boolean isUseLoggerName()
public void setUseLoggerName(boolean useLoggerName)
public boolean isUseMarker()
public void setUseMarker(boolean useMarker)
public boolean isUseThreadName()
public void setUseThreadName(boolean useThreadName)
public Map<String,String> getAdditionalFields()
... MDC.put("ipAddress", "44.556.345.657"); ... Now, to
include the ip address in the gelf message, i just add the following to my logback.groovy:
appender("GELF", GelfAppender) { ... additionalFields = [identity:"_identity"] ... } in the
additionalFields map, the key is the name of the MDC to look up. the value is the name that should be given to
the key in the additional field in the gelf message.
public void setAdditionalFields(Map<String,String> additionalFields)
public Map<String,String> getStaticAdditionalFields()
public void setStaticAdditionalFields(Map<String,String> staticAdditionalFields)
public boolean isIncludeFullMDC()
additional fields.
If true, the gelf message will contain all values available
in the MDC. Each MDC key will be converted to a gelf custom field by
adding an underscore prefix. If an entry exists in
additional field it will be used instead.
If false, only the fields listed in
additional field will be included in the
message.
public void setIncludeFullMDC(boolean includeFullMDC)
public String getHostName()
public void setHostName(String hostName)
public void addAdditionalField(String keyValue)
keyValue - This must be in format key:value where key is the MDC key, and value is the GELF field
name. e.g "ipAddress:_ip_address"public void addStaticAdditionalField(String keyValue)
keyValue - This must be in format key:value where key is the additional field key, and value is a static
string. e.g "_node_name:www013"public int getShortMessageLength()
public void setShortMessageLength(int shortMessageLength)
public String getGraylog2ServerVersion()
public void setGraylog2ServerVersion(String graylog2ServerVersion)
public int getChunkThreshold()
public void setChunkThreshold(int chunkThreshold)
public String getMessagePattern()
public void setMessagePattern(String messagePattern)
public String getShortMessagePattern()
public void setShortMessagePattern(String shortMessagePattern)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||