All Downloads are FREE. Search and download functionalities are using the official Maven repository.

biz.paluch.logging.gelf.jboss7.JBoss7GelfLogHandler Maven / Gradle / Ivy

There is a newer version: 1.15.1
Show newest version
package biz.paluch.logging.gelf.jboss7;

import static biz.paluch.logging.gelf.LogMessageField.NamedLogField.LoggerName;
import static biz.paluch.logging.gelf.LogMessageField.NamedLogField.NDC;
import static biz.paluch.logging.gelf.LogMessageField.NamedLogField.Severity;
import static biz.paluch.logging.gelf.LogMessageField.NamedLogField.SourceClassName;
import static biz.paluch.logging.gelf.LogMessageField.NamedLogField.SourceMethodName;
import static biz.paluch.logging.gelf.LogMessageField.NamedLogField.SourceSimpleClassName;
import static biz.paluch.logging.gelf.LogMessageField.NamedLogField.ThreadName;
import static biz.paluch.logging.gelf.LogMessageField.NamedLogField.Time;

import java.util.logging.LogRecord;
import org.jboss.logmanager.ExtLogRecord;

import biz.paluch.logging.gelf.DynamicMdcMessageField;
import biz.paluch.logging.gelf.GelfMessageAssembler;
import biz.paluch.logging.gelf.LogMessageField;
import biz.paluch.logging.gelf.MdcGelfMessageAssembler;
import biz.paluch.logging.gelf.MdcMessageField;
import biz.paluch.logging.gelf.StaticMessageField;
import biz.paluch.logging.gelf.intern.GelfMessage;

/**
 * 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:
 * 

*

    *
  • graylogHost (Mandatory): Hostname/IP-Address of the Logstash Host *
      *
    • tcp:(the host) for TCP, e.g. tcp:127.0.0.1 or tcp:some.host.com
    • *
    • udp:(the host) for UDP, e.g. udp:127.0.0.1 or udp:some.host.com
    • *
    • (the host) for UDP, e.g. 127.0.0.1 or some.host.com
    • *
    *
  • *
  • port (Optional): Port, default 12201
  • *
  • originHost (Optional): Originating Hostname, default FQDN Hostname
  • *
  • extractStacktrace (Optional): Post Stack-Trace to StackTrace field, default false
  • *
  • filterStackTrace (Optional): Perform Stack-Trace filtering (true/false), default false
  • *
  • mdcProfiling (Optional): Perform Profiling (Call-Duration) based on MDC Data. See MDC * Profiling, default false
  • *
  • facility (Optional): Name of the Facility, default gelf-java
  • *
  • level (Optional): Log-Level, default INFO
  • *
  • filter (Optional): Class-Name of a Log-Filter, default none
  • *
  • additionalFields(number) (Optional): Post additional fields. Eg. * .GelfLogHandler.additionalFields=fieldName=Value,field2=value2
  • *
  • mdcFields (Optional): Post additional fields, pull Values from MDC. Name of the Fields are comma-separated * .JBoss7GelfLogHandler.mdcFields=Application,Version,SomeOtherFieldName
  • *
  • 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
  • *
  • includeFullMdc (Optional): Include all fields from the MDC, default false
  • *
*

* *

MDC Profiling

*

* 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: *

    *
  • profiling.requestStart.millis: Time Millis of the Request-Start (Long or String)
  • *
*

* Two values are set by the Log Appender: *

    *
  • profiling.requestEnd: End-Time of the Request-End in Date.toString-representation
  • *
  • profiling.requestDuration: Duration of the request (e.g. 205ms, 16sec)
  • *
*

*

*/ public class JBoss7GelfLogHandler extends biz.paluch.logging.gelf.jul.GelfLogHandler { public JBoss7GelfLogHandler() { super(); } protected void initializeDefaultFields() { gelfMessageAssembler.addFields(LogMessageField.getDefaultMapping(Time, Severity, ThreadName, SourceClassName, SourceMethodName, SourceSimpleClassName, LoggerName, NDC)); } @Override public void publish(LogRecord record) { super.publish(ExtLogRecord.wrap(record)); } @Override protected GelfMessageAssembler createGelfMessageAssembler() { return new MdcGelfMessageAssembler(); } protected GelfMessage createGelfMessage(final LogRecord record) { return getGelfMessageAssembler().createGelfMessage(new JBoss7JulLogEvent((ExtLogRecord) record)); } public void setAdditionalFields(String fieldSpec) { String[] properties = fieldSpec.split(","); for (String field : properties) { final int index = field.indexOf('='); if (-1 != index) { getGelfMessageAssembler().addField( new StaticMessageField(field.substring(0, index), field.substring(index + 1))); } } } public void setMdcFields(String fieldSpec) { String[] fields = fieldSpec.split(","); for (String field : fields) { getGelfMessageAssembler().addField(new MdcMessageField(field.trim(), field.trim())); } } public void setDynamicMdcFields(String fieldSpec) { String[] fields = fieldSpec.split(","); for (String field : fields) { gelfMessageAssembler.addField(new DynamicMdcMessageField(field.trim())); } } public boolean isMdcProfiling() { return getGelfMessageAssembler().isMdcProfiling(); } public void setMdcProfiling(boolean mdcProfiling) { getGelfMessageAssembler().setMdcProfiling(mdcProfiling); } public boolean isIncludeFullMdc() { return getGelfMessageAssembler().isIncludeFullMdc(); } public void setIncludeFullMdc(boolean includeFullMdc) { getGelfMessageAssembler().setIncludeFullMdc(includeFullMdc); } private MdcGelfMessageAssembler getGelfMessageAssembler() { return (MdcGelfMessageAssembler) gelfMessageAssembler; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy