本文整理汇总了Java中org.apache.logging.log4j.core.net.Protocol类的典型用法代码示例。如果您正苦于以下问题:Java Protocol类的具体用法?Java Protocol怎么用?Java Protocol使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Protocol类属于org.apache.logging.log4j.core.net包,在下文中一共展示了Protocol类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSocketManager
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
/**
* Creates an AbstractSocketManager for TCP, UDP, and SSL.
*
* @throws IllegalArgumentException
* if the protocol cannot be handled.
*/
protected static AbstractSocketManager createSocketManager(final String name, Protocol protocol, final String host,
final int port, final int connectTimeoutMillis, final SslConfiguration sslConfig,
final int reconnectDelayMillis, final boolean immediateFail, final Layout<? extends Serializable> layout,
final int bufferSize, final SocketOptions socketOptions) {
if (protocol == Protocol.TCP && sslConfig != null) {
// Upgrade TCP to SSL if an SSL config is specified.
protocol = Protocol.SSL;
}
if (protocol != Protocol.SSL && sslConfig != null) {
LOGGER.info("Appender {} ignoring SSL configuration for {} protocol", name, protocol);
}
switch (protocol) {
case TCP:
return TcpSocketManager.getSocketManager(host, port, connectTimeoutMillis, reconnectDelayMillis,
immediateFail, layout, bufferSize, socketOptions);
case UDP:
return DatagramSocketManager.getSocketManager(host, port, layout, bufferSize);
case SSL:
return SslSocketManager.getSocketManager(sslConfig, host, port, connectTimeoutMillis, reconnectDelayMillis,
immediateFail, layout, bufferSize, socketOptions);
default:
throw new IllegalArgumentException(protocol.toString());
}
}
示例2: newSyslogAppenderBuilder
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
protected Builder newSyslogAppenderBuilder(final String protocol, final String format, final boolean newLine) {
// @formatter:off
return SyslogAppender.newSyslogAppenderBuilder()
.withPort(PORTNUM)
.withProtocol(EnglishEnums.valueOf(Protocol.class, protocol))
.withReconnectDelayMillis(-1)
.withName("TestApp")
.withIgnoreExceptions(false)
.setId("Audit")
.setEnterpriseNumber(18060)
.setMdcId("RequestContext")
.setNewLine(newLine)
.setAppName("TestApp")
.setMsgId("Test")
.setFormat(format);
// @formatter:on
}
示例3: initTargetAppender
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
@Override
public void initTargetAppender() {
targetAppender = SyslogAppender.newSyslogAppenderBuilder()
.withName(getTargetAppenderName())
.withHost("localhost")
.withPort(514)
.withProtocol(Protocol.UDP)
.withLayout(
PatternLayout.newBuilder().withPattern("%d{ISO8601} %-5level %logger - %msg%n").build())
.setFacility(Facility.LOCAL1)
.build();
}
示例4: createSocketManager
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
protected static AbstractSocketManager createSocketManager(final Protocol p, final String host, final int port,
final int delay, final boolean immediateFail,
final Layout<? extends Serializable> layout) {
switch (p) {
case TCP:
return TCPSocketManager.getSocketManager(host, port, delay, immediateFail, layout);
case UDP:
return DatagramSocketManager.getSocketManager(host, port, layout);
default:
return null;
}
}
示例5: build
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
@SuppressWarnings({"resource", "unchecked"})
@Override
public SyslogAppender build() {
final Protocol protocol = getProtocol();
final SslConfiguration sslConfiguration = getSslConfiguration();
final boolean useTlsMessageFormat = sslConfiguration != null || protocol == Protocol.SSL;
final Configuration configuration = getConfiguration();
Layout<? extends Serializable> layout = getLayout();
if (layout == null) {
layout = RFC5424.equalsIgnoreCase(format)
? Rfc5424Layout.createLayout(facility, id, enterpriseNumber, includeMdc, mdcId, mdcPrefix,
eventPrefix, newLine, escapeNL, appName, msgId, excludes, includes, required,
exceptionPattern, useTlsMessageFormat, loggerFields, configuration)
:
// @formatter:off
SyslogLayout.newBuilder()
.setFacility(facility)
.setIncludeNewLine(newLine)
.setEscapeNL(escapeNL)
.setCharset(charsetName)
.build();
// @formatter:off
}
final String name = getName();
if (name == null) {
LOGGER.error("No name provided for SyslogAppender");
return null;
}
final AbstractSocketManager manager = createSocketManager(name, protocol, getHost(), getPort(), getConnectTimeoutMillis(),
sslConfiguration, getReconnectDelayMillis(), getImmediateFail(), layout, Constants.ENCODER_BYTE_BUFFER_SIZE, null);
return new SyslogAppender(name, layout, getFilter(), isIgnoreExceptions(), isImmediateFlush(), manager,
getAdvertise() ? configuration.getAdvertiser() : null);
}
示例6: build
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
@SuppressWarnings("resource")
@Override
public SocketAppender build() {
boolean immediateFlush = isImmediateFlush();
final boolean bufferedIo = isBufferedIo();
final Layout<? extends Serializable> layout = getLayout();
if (layout == null) {
AbstractLifeCycle.LOGGER.error("No layout provided for SocketAppender");
return null;
}
final String name = getName();
if (name == null) {
AbstractLifeCycle.LOGGER.error("No name provided for SocketAppender");
return null;
}
final Protocol protocol = getProtocol();
final Protocol actualProtocol = protocol != null ? protocol : Protocol.TCP;
if (actualProtocol == Protocol.UDP) {
immediateFlush = true;
}
final AbstractSocketManager manager = SocketAppender.createSocketManager(name, actualProtocol, getHost(), getPort(),
getConnectTimeoutMillis(), getSslConfiguration(), getReconnectDelayMillis(), getImmediateFail(), layout, getBufferSize(), getSocketOptions());
return new SocketAppender(name, layout, getFilter(), manager, isIgnoreExceptions(),
!bufferedIo || immediateFlush, getAdvertise() ? getConfiguration().getAdvertiser() : null);
}
示例7: createAppender
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
/**
* Creates a socket appender.
*
* @param host
* The name of the host to connect to.
* @param port
* The port to connect to on the target host.
* @param protocol
* The Protocol to use.
* @param sslConfig
* The SSL configuration file for TCP/SSL, ignored for UPD.
* @param connectTimeoutMillis
* the connect timeout in milliseconds.
* @param reconnectDelayMillis
* The interval in which failed writes should be retried.
* @param immediateFail
* True if the write should fail if no socket is immediately available.
* @param name
* The name of the Appender.
* @param immediateFlush
* "true" if data should be flushed on each write.
* @param ignoreExceptions
* If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise they
* are propagated to the caller.
* @param layout
* The layout to use. Required, there is no default.
* @param filter
* The Filter or null.
* @param advertise
* "true" if the appender configuration should be advertised, "false" otherwise.
* @param configuration
* The Configuration
* @return A SocketAppender.
* @deprecated Deprecated in 2.7; use {@link #newBuilder()}
*/
@Deprecated
@PluginFactory
public static SocketAppender createAppender(
// @formatter:off
final String host,
final int port,
final Protocol protocol,
final SslConfiguration sslConfig,
final int connectTimeoutMillis,
final int reconnectDelayMillis,
final boolean immediateFail,
final String name,
final boolean immediateFlush,
final boolean ignoreExceptions,
final Layout<? extends Serializable> layout,
final Filter filter,
final boolean advertise,
final Configuration configuration) {
// @formatter:on
// @formatter:off
return newBuilder()
.withAdvertise(advertise)
.setConfiguration(configuration)
.withConnectTimeoutMillis(connectTimeoutMillis)
.withFilter(filter)
.withHost(host)
.withIgnoreExceptions(ignoreExceptions)
.withImmediateFail(immediateFail)
.withLayout(layout)
.withName(name)
.withPort(port)
.withProtocol(protocol)
.withReconnectDelayMillis(reconnectDelayMillis)
.withSslConfiguration(sslConfig)
.build();
// @formatter:on
}
示例8: testUdpAppender
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
@Test
public void testUdpAppender() throws Exception {
try {
udpServer.latch.await();
} catch (final InterruptedException ex) {
ex.printStackTrace();
}
// @formatter:off
final SocketAppender appender = SocketAppender.newBuilder()
.withProtocol(Protocol.UDP)
.withPort(tcpServer.getLocalPort())
.withReconnectDelayMillis(-1)
.withName("test")
.withImmediateFail(false)
.withLayout(JsonLayout.newBuilder().setProperties(true).build())
.build();
// @formatter:on
appender.start();
// set appender on root and set level to debug
logger.addAppender(appender);
logger.setAdditive(false);
logger.setLevel(Level.DEBUG);
logger.debug("This is a udp message");
final LogEvent event = udpServer.getQueue().poll(3, TimeUnit.SECONDS);
assertNotNull("No event retrieved", event);
assertTrue("Incorrect event", event.getMessage().getFormattedMessage().equals("This is a udp message"));
assertTrue("Message not delivered via UDP", udpServer.getCount() > 0);
}
示例9: createAppender
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
/**
*
* @param host The name of the host to connect to.
* @param portNum The port to connect to on the target host.
* @param protocol The Protocol to use.
* @param delay The interval in which failed writes should be retried.
* @param immediateFail True if the write should fail if no socket is immediately available.
* @param name The name of the Appender.
* @param immediateFlush "true" if data should be flushed on each write.
* @param ignore If {@code "true"} (default) exceptions encountered when appending events are logged; otherwise
* they are propagated to the caller.
* @param layout The layout to use (defaults to SerializedLayout).
* @param filter The Filter or null.
* @param advertise "true" if the appender configuration should be advertised, "false" otherwise.
* @param config The Configuration
* @return A SocketAppender.
*/
@PluginFactory
public static SocketAppender createAppender(
@PluginAttribute("host") final String host,
@PluginAttribute("port") final String portNum,
@PluginAttribute("protocol") final String protocol,
@PluginAttribute("reconnectionDelay") final String delay,
@PluginAttribute("immediateFail") final String immediateFail,
@PluginAttribute("name") final String name,
@PluginAttribute("immediateFlush") final String immediateFlush,
@PluginAttribute("ignoreExceptions") final String ignore,
@PluginElement("Layout") Layout<? extends Serializable> layout,
@PluginElement("Filters") final Filter filter,
@PluginAttribute("advertise") final String advertise,
@PluginConfiguration final Configuration config) {
boolean isFlush = Booleans.parseBoolean(immediateFlush, true);
final boolean isAdvertise = Boolean.parseBoolean(advertise);
final boolean ignoreExceptions = Booleans.parseBoolean(ignore, true);
final boolean fail = Booleans.parseBoolean(immediateFail, true);
final int reconnectDelay = AbstractAppender.parseInt(delay, 0);
final int port = AbstractAppender.parseInt(portNum, 0);
if (layout == null) {
layout = SerializedLayout.createLayout();
}
if (name == null) {
LOGGER.error("No name provided for SocketAppender");
return null;
}
final Protocol p = EnglishEnums.valueOf(Protocol.class, protocol != null ? protocol : Protocol.TCP.name());
if (p.equals(Protocol.UDP)) {
isFlush = true;
}
final AbstractSocketManager manager = createSocketManager(p, host, port, reconnectDelay, fail, layout);
if (manager == null) {
return null;
}
return new SocketAppender(name, layout, filter, manager, ignoreExceptions, isFlush,
isAdvertise ? config.getAdvertiser() : null);
}
示例10: getProtocol
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
public Protocol getProtocol() {
return protocol;
}
示例11: withProtocol
import org.apache.logging.log4j.core.net.Protocol; //导入依赖的package包/类
public B withProtocol(final Protocol protocol) {
this.protocol = protocol;
return asBuilder();
}