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

biz.paluch.logging.gelf.log4j2.HostnameConverter Maven / Gradle / Ivy

The newest version!
package biz.paluch.logging.gelf.log4j2;

import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.pattern.ConverterKeys;
import org.apache.logging.log4j.core.pattern.LogEventPatternConverter;

import biz.paluch.logging.RuntimeContainer;

/**
 * Provides the servername/Hostname.
 *
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
OptionDescription
* host
*   {["fqdn"
*   |"simple"
*   |"address"]}
*

* Outputs either the FQDN hostname, the simple hostname or the local address. *

*

* You can follow the throwable conversion word with an option in the form %host{option}. *

*

* %host{fqdn} default setting, outputs the FQDN hostname, e.g. www.you.host.name.com. *

*

* %host{simple} outputs simple hostname, e.g. www. *

*

* %host{address} outputs the local IP address of the found hostname, e.g. 1.2.3.4 or affe:affe:affe::1. *

*
* * @author Mark Paluch */ @Plugin(name = "HostnameConverter", category = "Converter") @ConverterKeys({ "host", }) public class HostnameConverter extends LogEventPatternConverter { public HostnameConverter(String style) { super(HostnameConverter.class.getSimpleName(), style); } public static HostnameConverter newInstance(String[] format) { String style = null; if (format.length > 0) { style = format[0]; } return new HostnameConverter(style); } @Override public void format(LogEvent event, StringBuilder toAppendTo) { if (getStyle() == null || getStyle().equals("") || getStyle().equals("fqdn")) { toAppendTo.append(RuntimeContainer.FQDN_HOSTNAME); } if (getStyle() != null && getStyle().equals("simple")) { toAppendTo.append(RuntimeContainer.HOSTNAME); } if (getStyle() != null && getStyle().equals("address")) { toAppendTo.append(RuntimeContainer.ADDRESS); } } public String getStyle() { return getStyleClass(null); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy