Top Description Inners Fields Constructors Methods
io.undertow.server.handlers.accesslog

public Class DefaultAccessLogReceiver

extends Object
implements AccessLogReceiver, Runnable, Closeable
Class Inheritance
All Implemented Interfaces
java.io.Closeable, java.lang.AutoCloseable, java.lang.Runnable, io.undertow.server.handlers.accesslog.AccessLogReceiver
Imports
java.io.BufferedWriter, .Closeable, .File, .IOException, java.nio.charset.StandardCharsets, java.nio.file.Files, .Path, .StandardOpenOption, java.text.SimpleDateFormat, java.util.ArrayList, .Calendar, .Date, .Deque, .List, .Locale, java.util.concurrent.ConcurrentLinkedDeque, .Executor, java.util.concurrent.atomic.AtomicIntegerFieldUpdater, io.undertow.UndertowLogger

Log Receiver that stores logs in a directory under the specified file name, and rotates them after midnight.

Web threads do not touch the log file, but simply queue messages to be written later by a worker thread. A lightweight CAS based locking mechanism is used to ensure than only 1 thread is active writing messages at any given time

Author
Stuart Douglas

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private long
private volatile boolean
private String
private static final String
private final Path
private final LogFileHeaderGenerator
private boolean
private boolean
private final String
private final String
private final Executor
private final Path
private final Deque<String>
private final boolean
private volatile int
private static final AtomicIntegerFieldUpdater<DefaultAccessLogReceiver>
private BufferedWriter

Constructor Summary

AccessConstructor and Description
public
DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName)

public
DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName, final String logNameSuffix)

public
DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate)

public
DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName)

public
DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix)

public
DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate)

private
DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate, LogFileHeaderGenerator fileHeader)

Method Summary

Modifier and TypeMethod and Description
pack-priv void
awaitWrittenForTest()

For tests only.

public static DefaultAccessLogReceiver.Builder
private void
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

private void
public void
public void
rotate()

forces a log rotation.

public void
run()

Implements java.lang.Runnable.run.

processes all queued log messages

private void
writeMessage(final List<String> messages)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

changeOverPointback to summary
private long changeOverPoint
closedback to summary
private volatile boolean closed
currentDateStringback to summary
private String currentDateString
DEFAULT_LOG_SUFFIXback to summary
private static final String DEFAULT_LOG_SUFFIX
defaultLogFileback to summary
private final Path defaultLogFile
fileHeaderGeneratorback to summary
private final LogFileHeaderGenerator fileHeaderGenerator
forceLogRotationback to summary
private boolean forceLogRotation
initialRunback to summary
private boolean initialRun
logBaseNameback to summary
private final String logBaseName
logNameSuffixback to summary
private final String logNameSuffix
logWriteExecutorback to summary
private final Executor logWriteExecutor
outputDirectoryback to summary
private final Path outputDirectory
pendingMessagesback to summary
private final Deque<String> pendingMessages
rotateback to summary
private final boolean rotate
stateback to summary
private volatile int state
Annotations
@SuppressWarnings:unused
stateUpdaterback to summary
private static final AtomicIntegerFieldUpdater<DefaultAccessLogReceiver> stateUpdater
writerback to summary
private BufferedWriter writer

Constructor Detail

DefaultAccessLogReceiverback to summary
public DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName)
DefaultAccessLogReceiverback to summary
public DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName, final String logNameSuffix)
DefaultAccessLogReceiverback to summary
public DefaultAccessLogReceiver(final Executor logWriteExecutor, final File outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate)
DefaultAccessLogReceiverback to summary
public DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName)
DefaultAccessLogReceiverback to summary
public DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix)
DefaultAccessLogReceiverback to summary
public DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate)
DefaultAccessLogReceiverback to summary
private DefaultAccessLogReceiver(final Executor logWriteExecutor, final Path outputDirectory, final String logBaseName, final String logNameSuffix, boolean rotate, LogFileHeaderGenerator fileHeader)

Method Detail

awaitWrittenForTestback to summary
pack-priv void awaitWrittenForTest() throws InterruptedException

For tests only. Blocks the current thread until all messages are written Just does a busy wait.

DO NOT USE THIS OUTSIDE OF A TEST

builderback to summary
public static DefaultAccessLogReceiver.Builder builder()
calculateChangeOverPointback to summary
private void calculateChangeOverPoint()
closeback to summary
public void close() throws IOException

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs
doRotateback to summary
private void doRotate()
logMessageback to summary
public void logMessage(final String message)

Implements io.undertow.server.handlers.accesslog.AccessLogReceiver.logMessage.

Annotations
@Override
rotateback to summary
public void rotate()

forces a log rotation. This rotation is performed in an async manner, you cannot rely on the rotation being performed immediately after this method returns.

runback to summary
public void run()

Implements java.lang.Runnable.run.

processes all queued log messages

Annotations
@Override
writeMessageback to summary
private void writeMessage(final List<String> messages)
io.undertow.server.handlers.accesslog back to summary

public Class DefaultAccessLogReceiver.Builder

extends Object
Class Inheritance
  • java.lang.Object
  • io.undertow.server.handlers.accesslog.DefaultAccessLogReceiver.Builder

Field Summary

Modifier and TypeField and Description
private String
private LogFileHeaderGenerator
private String
private Executor
private Path
private boolean

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public DefaultAccessLogReceiver
public String
public LogFileHeaderGenerator
public String
public Executor
public Path
public boolean
public DefaultAccessLogReceiver.Builder
setLogBaseName(String logBaseName)

public DefaultAccessLogReceiver.Builder
public DefaultAccessLogReceiver.Builder
setLogNameSuffix(String logNameSuffix)

public DefaultAccessLogReceiver.Builder
setLogWriteExecutor(Executor logWriteExecutor)

public DefaultAccessLogReceiver.Builder
setOutputDirectory(Path outputDirectory)

public DefaultAccessLogReceiver.Builder
setRotate(boolean rotate)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logBaseNameback to summary
private String logBaseName
logFileHeaderGeneratorback to summary
private LogFileHeaderGenerator logFileHeaderGenerator
logNameSuffixback to summary
private String logNameSuffix
logWriteExecutorback to summary
private Executor logWriteExecutor
outputDirectoryback to summary
private Path outputDirectory
rotateback to summary
private boolean rotate

Constructor Detail

Builderback to summary
public Builder()

Method Detail

buildback to summary
public DefaultAccessLogReceiver build()
getLogBaseNameback to summary
public String getLogBaseName()
getLogFileHeaderGeneratorback to summary
public LogFileHeaderGenerator getLogFileHeaderGenerator()
getLogNameSuffixback to summary
public String getLogNameSuffix()
getLogWriteExecutorback to summary
public Executor getLogWriteExecutor()
getOutputDirectoryback to summary
public Path getOutputDirectory()
isRotateback to summary
public boolean isRotate()
setLogBaseNameback to summary
public DefaultAccessLogReceiver.Builder setLogBaseName(String logBaseName)
setLogFileHeaderGeneratorback to summary
public DefaultAccessLogReceiver.Builder setLogFileHeaderGenerator(LogFileHeaderGenerator logFileHeaderGenerator)
setLogNameSuffixback to summary
public DefaultAccessLogReceiver.Builder setLogNameSuffix(String logNameSuffix)
setLogWriteExecutorback to summary
public DefaultAccessLogReceiver.Builder setLogWriteExecutor(Executor logWriteExecutor)
setOutputDirectoryback to summary
public DefaultAccessLogReceiver.Builder setOutputDirectory(Path outputDirectory)
setRotateback to summary
public DefaultAccessLogReceiver.Builder setRotate(boolean rotate)