/** * Creates a new audit endpoint that logs to syslog server. */ SyslogAuditEndpoint(Builder builder) throws IOException { SyslogHandler.Protocol protocol = builder.ssl ? Protocol.SSL_TCP : builder.tcp ? Protocol.TCP : Protocol.UDP; syslogHandler = new SyslogHandler(checkNotNullParam("serverAddress", builder.serverAddress), builder.port, Facility.SECURITY, null, protocol, checkNotNullParam("hostName", builder.hostName)); if (builder.tcp && builder.socketFactory != null) { syslogHandler.setOutputStream(new TcpOutputStream(builder.socketFactory, builder.serverAddress, builder.port) { // anonymous class to access protected constructor }); } }
@Override public void close() throws IOException { accepting = false; synchronized(this) { syslogHandler.close(); } }
@Override public void accept(EventPriority priority, String message) throws IOException { if (!accepting) return; synchronized(this) { if (!accepting) return; syslogHandler.doPublish(new ExtLogRecord(toLevel(priority), message, SyslogAuditEndpoint.class.getName())); } }
handler = new SyslogHandler(syslogServerAddress, port, facility.convert(), syslogType, protocol, hostName == null ? InetAddressUtil.getLocalHostName() : hostName); handler.setAppName(appName); handler.setTruncate(truncate); if (maxLength != 0) { handler.setMaxLength(maxLength); handler.setSyslogType(syslogType); handler.setErrorManager(errorManager); handler.setUseCountingFraming(false); handler.setMessageDelimiter("\n"); handler.setUseMessageDelimiter(true); } else { handler.setUseCountingFraming(true); handler.setMessageDelimiter(null); handler.setUseMessageDelimiter(false); handler.setOutputStream(new SSLContextOutputStream(context, syslogServerAddress, port)); } else { handler.setOutputStream(new AuditLogTcpOutputStream(syslogServerAddress, port)); handler.setProtocol(transport == Transport.TCP ? Protocol.TCP : Protocol.SSL_TCP); if (handler != null) { try { handler.close(); } catch (Exception ignore){}
handler = new SyslogHandler(syslogServerAddress, port, facility.convert(), syslogType, protocol, hostName == null ? InetAddressUtil.getLocalHostName() : hostName); handler.setEscapeEnabled(false); //Escaping is handled by the formatter handler.setAppName(appName); handler.setTruncate(truncate); if (maxLength != 0) { handler.setMaxLength(maxLength); handler.setSyslogType(syslogType); handler.setUseCountingFraming(false); handler.setMessageDelimiter("\n"); handler.setUseMessageDelimiter(true); } else { handler.setUseCountingFraming(true); handler.setMessageDelimiter(null); handler.setUseMessageDelimiter(false); handler.setOutputStream(new SSLContextOutputStream(context, syslogServerAddress, port)); } else { handler.setProtocol(transport == Transport.TCP ? Protocol.TCP : Protocol.SSL_TCP);
/** * Sets the output stream for the syslog handler to write to. * <p/> * Setting the output stream closes any already established connections or open output streams and will not open * any new connections until the output stream is set to {@code null}. The {@link * #setProtocol(org.jboss.logmanager.handlers.SyslogHandler.Protocol) protocol}, {@link * #setServerAddress(java.net.InetAddress), server address}, {@link #setServerHostname(String) server hostname} or * {@link #setPort(int) port} have no effect when the output stream is set. * * @param out the output stream to write to */ public void setOutputStream(final OutputStream out) { checkAccess(this); setOutputStream(out, true); }
private void init() { if (initializeConnection && !outputStreamSet) { if (serverAddress == null || port < 0 || protocol == null) { throw new IllegalStateException("Invalid connection parameters. The port, server address and protocol must be set."); } initializeConnection = false; final OutputStream out; // Check the sockets try { final ClientSocketFactory clientSocketFactory = getClientSocketFactory(); if (protocol == Protocol.UDP) { out = new UdpOutputStream(clientSocketFactory); } else { out = new TcpOutputStream(clientSocketFactory, blockOnReconnect); } setOutputStream(out, false); } catch (IOException e) { throw new IllegalStateException("Could not set " + protocol + " output stream.", e); } } }
public void setFacility(Facility facility) { assert facility != null; this.facility = facility; //This gets updated immediately if (handler != null) { handler.setFacility(facility.convert()); } }
public void setAppName(String appName) { assert appName != null; this.appName = appName; //This gets updated immediately if (handler != null) { handler.setAppName(appName); } }
@Override void writeLogItem(String formattedItem) throws IOException { handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName())); }
handler = new SyslogHandler(syslogServerAddress, port, facility.convert(), syslogType, protocol, hostName == null ? InetAddressUtil.getLocalHostName() : hostName); handler.setAppName(appName); handler.setTruncate(truncate); if (maxLength != 0) { handler.setMaxLength(maxLength); handler.setSyslogType(syslogType); handler.setErrorManager(errorManager); handler.setUseCountingFraming(false); handler.setMessageDelimiter("\n"); handler.setUseMessageDelimiter(true); } else { handler.setUseCountingFraming(true); handler.setMessageDelimiter(null); handler.setUseMessageDelimiter(false); handler.setOutputStream(new SSLContextOutputStream(context, syslogServerAddress, port)); } else { handler.setOutputStream(new AuditLogTcpOutputStream(syslogServerAddress, port)); handler.setProtocol(transport == Transport.TCP ? Protocol.TCP : Protocol.SSL_TCP); if (handler != null) { try { handler.close(); } catch (Exception ignore){}
public void setFacility(Facility facility) { assert facility != null; this.facility = facility; //This gets updated immediately if (handler != null) { handler.setFacility(facility.convert()); } }
public void setAppName(String appName) { assert appName != null; // filter any non-printing characters, or ascii spaces to - this.appName = appName.replaceAll(APPNAME_FILTER, APPNAME_REPLACE_VALUE); //This gets updated immediately if (handler != null) { handler.setAppName(appName); } }
@Override void writeLogItem(String formattedItem) throws IOException { boolean reconnect = isReconnect(); if (!reconnect) { handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName())); errorManager.getAndThrowError(); } else { ControllerLogger.MGMT_OP_LOGGER.attemptingReconnectToSyslog(name, reconnectTimeout); try { // Reinitialise the delegating syslog handler if required, if we're already connected we don't need to // establish a new connection if (!connected) { stop(); initialize(); } handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName())); errorManager.getAndThrowError(); lastErrorTime = -1; } catch (Exception e) { // A failure has occurred and initialization should be reattempted connected = false; lastErrorTime = System.currentTimeMillis(); errorManager.throwAsIoOrRuntimeException(e); } } }
/** * Creates a new audit endpoint that logs to syslog server. */ SyslogAuditEndpoint(Builder builder) throws IOException { SyslogHandler.Protocol protocol = builder.ssl ? Protocol.SSL_TCP : builder.tcp ? Protocol.TCP : Protocol.UDP; syslogHandler = new SyslogHandler(checkNotNullParam("serverAddress", builder.serverAddress), builder.port, Facility.SECURITY, null, protocol, checkNotNullParam("hostName", builder.hostName)); if (builder.tcp && builder.socketFactory != null) { syslogHandler.setOutputStream(new TcpOutputStream(builder.socketFactory, builder.serverAddress, builder.port) { // anonymous class to access protected constructor }); } }
@Override public void close() throws IOException { accepting = false; synchronized(this) { syslogHandler.close(); } }
@Override public void accept(EventPriority priority, String message) throws IOException { if (!accepting) return; synchronized(this) { if (!accepting) return; syslogHandler.doPublish(new ExtLogRecord(toLevel(priority), message, SyslogAuditEndpoint.class.getName())); } }
public void setFacility(Facility facility) { assert facility != null; this.facility = facility; //This gets updated immediately if (handler != null) { handler.setFacility(facility.convert()); } }
public void setAppName(String appName) { assert appName != null; // filter any non-printing characters, or ascii spaces to - this.appName = appName.replaceAll(APPNAME_FILTER, APPNAME_REPLACE_VALUE); //This gets updated immediately if (handler != null) { handler.setAppName(appName); } }
@Override void writeLogItem(String formattedItem) throws IOException { boolean reconnect = isReconnect(); if (!reconnect) { handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName())); errorManager.getAndThrowError(); } else { ControllerLogger.MGMT_OP_LOGGER.attemptingReconnectToSyslog(name, reconnectTimeout); try { // Reinitialise the delegating syslog handler if required, if we're already connected we don't need to // establish a new connection if (!connected) { stop(); initialize(); } handler.publish(new ExtLogRecord(Level.WARN, formattedItem, SyslogAuditLogHandler.class.getName())); errorManager.getAndThrowError(); lastErrorTime = -1; } catch (Exception e) { // A failure has occurred and initialization should be reattempted connected = false; lastErrorTime = System.currentTimeMillis(); errorManager.throwAsIoOrRuntimeException(e); } } }