@Override public void close() throws IOException { accepting = false; synchronized(this) { syslogHandler.close(); } }
/** * 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 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())); } }
private OutputStream createOutputStream() { if (address != null || port >= 0) { try { final ClientSocketFactory socketFactory = getClientSocketFactory(); if (protocol == Protocol.UDP) { return new UdpOutputStream(socketFactory); } return new TcpOutputStream(socketFactory, blockOnReconnect); } catch (IOException e) { reportError("Failed to create socket output stream", e, ErrorManager.OPEN_FAILURE); } } return null; }
/** * Sets the protocol used to connect to the syslog server * * @param type the protocol */ public void setProtocol(final Protocol type) { checkAccess(this); synchronized (outputLock) { this.protocol = type; initializeConnection = true; } }
@Override public void setOutputStream(final OutputStream outputStream) { synchronized (outputLock) { this.outputStream = outputStream == null ? null : new CountingOutputStream(outputStream); super.setOutputStream(this.outputStream); } }
/** {@inheritDoc} */ public void setOutputStream(final OutputStream outputStream) { super.setOutputStream(wrap(outputStream)); } }
/** {@inheritDoc} */ public void setOutputStream(final OutputStream outputStream) { synchronized (outputLock) { this.outputStream = outputStream == null ? null : new CountingOutputStream(outputStream); super.setOutputStream(this.outputStream); } }
/** * Set the maximum backup index (the number of log files to keep around). * * @param maxBackupIndex the maximum backup index */ public void setMaxBackupIndex(final int maxBackupIndex) { checkAccess(this); synchronized (outputLock) { this.maxBackupIndex = maxBackupIndex; } }
/** * Construct a new instance with the given output file and append setting. * * @param fileName the file name * @param append {@code true} to append, {@code false} to overwrite * @throws FileNotFoundException if the file could not be found on open */ public FileHandler(final String fileName, final boolean append) throws FileNotFoundException { this.append = append; setFileName(fileName); }
/** * Set the rotation size, in bytes. * * @param rotateSize the number of bytes before the log is rotated */ public void setRotateSize(final long rotateSize) { checkAccess(this); synchronized (outputLock) { this.rotateSize = rotateSize; } }
/** * Construct a new instance. * * @param limit the queue length to use */ public QueueHandler(final int limit) { if (limit < 1) { throw badQueueLength(); } this.limit = limit; }
/** * Get the target encoding. * * @return the target encoding, or {@code null} if the platform default is being used */ public String getEncoding() { synchronized (outputLock) { return super.getEncoding(); } }
public void setLength(final int newLength) { if (newLength > length) { // grow reserve(newLength - length, true); } length = newLength; }
private static OutputStream wrap(final OutputStream outputStream) { return outputStream == null ? null : outputStream instanceof UncloseableOutputStream ? outputStream : new UncloseableOutputStream(outputStream); }
/** * Sets the client socket factory used to create sockets. * * @param clientSocketFactory the client socket factory to use */ public void setClientSocketFactory(final ClientSocketFactory clientSocketFactory) { checkAccess(this); synchronized (outputLock) { this.clientSocketFactory = clientSocketFactory; initializeConnection = true; } }
/** * Set the rotation size, in bytes. * * @param rotateSize the number of bytes before the log is rotated */ public void setRotateSize(final long rotateSize) { checkAccess(this); synchronized (outputLock) { this.rotateSize = rotateSize; } }
/** * Sets the maximum length, in bytes, of the message allowed to tbe sent. Note that the message length includes the * header and the message itself. * * @param maxLen the maximum length, in bytes, allowed to be sent to the syslog server */ public void setMaxLength(final int maxLen) { checkAccess(this); synchronized (outputLock) { this.maxLen = maxLen; } }
/** * Sets the message delimiter to be used if {@link #setUseMessageDelimiter(boolean) use message * delimiter} is set to {@code true}. * * @param delimiter the delimiter to use for the message */ public void setMessageDelimiter(final String delimiter) { checkAccess(this); synchronized (outputLock) { this.delimiter = delimiter; } }