Class RollingFileManager
java.lang.Object
org.apache.logging.log4j.core.appender.AbstractManager
org.apache.logging.log4j.core.appender.OutputStreamManager
org.apache.logging.log4j.core.appender.FileManager
org.apache.logging.log4j.core.appender.rolling.RollingFileManager
- All Implemented Interfaces:
AutoCloseable, ByteBufferDestination
- Direct Known Subclasses:
RollingRandomAccessFileManager
The Rolling File Manager.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classPerforms actions asynchronously.private static classprivate static classFactory data.private static classFactory to create a RollingFileManager.Nested classes/interfaces inherited from class AbstractManager
AbstractManager.AbstractFactoryData -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ExecutorServiceprivate final booleanprivate static final FileTimeprivate static RollingFileManager.RollingFileManagerFactoryprivate Stringprivate booleanprivate longprivate static final intprivate static final intprivate PatternProcessorprivate static final AtomicReferenceFieldUpdater<RollingFileManager, PatternProcessor> private booleanprivate final CopyOnWriteArrayList<RolloverListener> private RolloverStrategyprivate static final AtomicReferenceFieldUpdater<RollingFileManager, RolloverStrategy> private final Semaphoreprotected longprivate final Log4jThreadFactoryprivate TriggeringPolicyprivate static final AtomicReferenceFieldUpdater<RollingFileManager, TriggeringPolicy> Fields inherited from class OutputStreamManager
byteBuffer, layoutFields inherited from class AbstractManager
count, LOGGER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRollingFileManager(String fileName, String pattern, OutputStream os, boolean append, long size, long initialTime, TriggeringPolicy triggeringPolicy, RolloverStrategy rolloverStrategy, String advertiseURI, Layout<? extends Serializable> layout, boolean writeHeader, ByteBuffer buffer) Deprecated.protectedRollingFileManager(String fileName, String pattern, OutputStream os, boolean append, long size, long initialTime, TriggeringPolicy triggeringPolicy, RolloverStrategy rolloverStrategy, String advertiseURI, Layout<? extends Serializable> layout, int bufferSize, boolean writeHeader) Deprecated.protectedRollingFileManager(LoggerContext loggerContext, String fileName, String pattern, OutputStream os, boolean append, boolean createOnDemand, long size, long initialTime, TriggeringPolicy triggeringPolicy, RolloverStrategy rolloverStrategy, String advertiseURI, Layout<? extends Serializable> layout, boolean writeHeader, ByteBuffer buffer) Deprecated.protectedRollingFileManager(LoggerContext loggerContext, String fileName, String pattern, OutputStream os, boolean append, boolean createOnDemand, long size, long initialTime, TriggeringPolicy triggeringPolicy, RolloverStrategy rolloverStrategy, String advertiseURI, Layout<? extends Serializable> layout, String filePermissions, String fileOwner, String fileGroup, boolean writeHeader, ByteBuffer buffer) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddRolloverListener(RolloverListener listener) Add a RolloverListener.voidcheckRollover(LogEvent event) Determines if a rollover should occur.protected voidprotected voidcreateParentDir(File file) static RollingFileManagergetFileManager(String fileName, String pattern, boolean append, boolean bufferedIO, TriggeringPolicy policy, RolloverStrategy strategy, String advertiseURI, Layout<? extends Serializable> layout, int bufferSize, boolean immediateFlush, boolean createOnDemand, String filePermissions, String fileOwner, String fileGroup, Configuration configuration) Returns a RollingFileManager.Returns the name of the File being managed.longReturns the current size of the file.longReturns the time the file was created.Returns the pattern processor.Returns the rollover strategy.(package private) SemaphorePackage-private access for tests only.<T extends TriggeringPolicy>
TReturns the triggering policy.private static longinitialFileTime(File file) voidbooleanbooleanbooleanreleaseSub(long timeout, TimeUnit timeUnit) Default hook to write footer during close.voidremoveRolloverListener(RolloverListener listener) Remove a RolloverListener.voidrollover()voidprivate booleanrollover(RolloverStrategy strategy) voidsetPatternProcessor(PatternProcessor patternProcessor) voidsetRenameEmptyFiles(boolean renameEmptyFiles) voidsetRolloverStrategy(RolloverStrategy rolloverStrategy) voidsetTriggeringPolicy(TriggeringPolicy triggeringPolicy) voidupdateData(Object data) Updates the RollingFileManager's data during a reconfiguration.protected voidwrite(byte[] bytes, int offset, int length, boolean immediateFlush) Some output streams synchronize writes while others do not.protected voidwriteToDestination(byte[] bytes, int offset, int length) OverridesOutputStreamManager.writeToDestination(byte[], int, int)to add support for file locking.Methods inherited from class FileManager
createOutputStream, defineAttributeView, getBufferSize, getContentFormat, getFileGroup, getFileManager, getFileOwner, getFilePermissions, isAppend, isAttributeViewEnabled, isCreateOnDemand, isLockingMethods inherited from class OutputStreamManager
closeOutputStream, drain, flush, flushBuffer, flushDestination, getByteBuffer, getManager, getOutputStream, hasOutputStream, isOpen, setOutputStream, skipFooter, write, write, write, writeBytes, writeBytes, writeFooter, writeHeaderMethods inherited from class AbstractManager
close, getCount, getLoggerContext, getManager, getName, getStrSubstitutor, hasManager, log, logDebug, logError, logger, logWarn, narrow, release, stop
-
Field Details
-
factory
-
MAX_TRIES
private static final int MAX_TRIES- See Also:
-
MIN_DURATION
private static final int MIN_DURATION- See Also:
-
EPOCH
-
size
protected long size -
initialTime
private long initialTime -
patternProcessor
-
semaphore
-
threadFactory
-
triggeringPolicy
-
rolloverStrategy
-
renameEmptyFiles
private volatile boolean renameEmptyFiles -
initialized
private volatile boolean initialized -
fileName
-
directWrite
private final boolean directWrite -
rolloverListeners
-
asyncExecutor
-
triggeringPolicyUpdater
private static final AtomicReferenceFieldUpdater<RollingFileManager, TriggeringPolicy> triggeringPolicyUpdater -
rolloverStrategyUpdater
private static final AtomicReferenceFieldUpdater<RollingFileManager, RolloverStrategy> rolloverStrategyUpdater -
patternProcessorUpdater
private static final AtomicReferenceFieldUpdater<RollingFileManager, PatternProcessor> patternProcessorUpdater
-
-
Constructor Details
-
RollingFileManager
@Deprecated protected RollingFileManager(String fileName, String pattern, OutputStream os, boolean append, long size, long initialTime, TriggeringPolicy triggeringPolicy, RolloverStrategy rolloverStrategy, String advertiseURI, Layout<? extends Serializable> layout, int bufferSize, boolean writeHeader) Deprecated. -
RollingFileManager
@Deprecated protected RollingFileManager(String fileName, String pattern, OutputStream os, boolean append, long size, long initialTime, TriggeringPolicy triggeringPolicy, RolloverStrategy rolloverStrategy, String advertiseURI, Layout<? extends Serializable> layout, boolean writeHeader, ByteBuffer buffer) Deprecated. -
RollingFileManager
@Deprecated protected RollingFileManager(LoggerContext loggerContext, String fileName, String pattern, OutputStream os, boolean append, boolean createOnDemand, long size, long initialTime, TriggeringPolicy triggeringPolicy, RolloverStrategy rolloverStrategy, String advertiseURI, Layout<? extends Serializable> layout, boolean writeHeader, ByteBuffer buffer) Deprecated. -
RollingFileManager
protected RollingFileManager(LoggerContext loggerContext, String fileName, String pattern, OutputStream os, boolean append, boolean createOnDemand, long size, long initialTime, TriggeringPolicy triggeringPolicy, RolloverStrategy rolloverStrategy, String advertiseURI, Layout<? extends Serializable> layout, String filePermissions, String fileOwner, String fileGroup, boolean writeHeader, ByteBuffer buffer) - Since:
- 2.9
-
-
Method Details
-
initialize
public void initialize() -
getFileManager
public static RollingFileManager getFileManager(String fileName, String pattern, boolean append, boolean bufferedIO, TriggeringPolicy policy, RolloverStrategy strategy, String advertiseURI, Layout<? extends Serializable> layout, int bufferSize, boolean immediateFlush, boolean createOnDemand, String filePermissions, String fileOwner, String fileGroup, Configuration configuration) Returns a RollingFileManager.- Parameters:
fileName- The file name.pattern- The pattern for rolling file.append- true if the file should be appended to.bufferedIO- true if data should be buffered.policy- The TriggeringPolicy.strategy- The RolloverStrategy.advertiseURI- the URI to use when advertising the filelayout- The Layout.bufferSize- buffer size to use if bufferedIO is trueimmediateFlush- flush on every write or notcreateOnDemand- true if you want to lazy-create the file (a.k.a. on-demand.)filePermissions- File permissionsfileOwner- File ownerfileGroup- File groupconfiguration- The configuration.- Returns:
- A RollingFileManager.
-
addRolloverListener
Add a RolloverListener.- Parameters:
listener- The RolloverListener.
-
removeRolloverListener
Remove a RolloverListener.- Parameters:
listener- The RolloverListener.
-
getFileName
Returns the name of the File being managed.- Overrides:
getFileNamein classFileManager- Returns:
- The name of the File being managed.
-
createParentDir
- Overrides:
createParentDirin classFileManager
-
isDirectWrite
public boolean isDirectWrite() -
getFileExtension
-
write
protected void write(byte[] bytes, int offset, int length, boolean immediateFlush) Description copied from class:OutputStreamManagerSome output streams synchronize writes while others do not. Synchronizing here insures that log events won't be intertwined.- Overrides:
writein classFileManager- Parameters:
bytes- The serialized Log event.offset- The offset into the byte array.length- The number of bytes to write.immediateFlush- flushes immediately after writing.
-
writeToDestination
protected void writeToDestination(byte[] bytes, int offset, int length) Description copied from class:FileManagerOverridesOutputStreamManager.writeToDestination(byte[], int, int)to add support for file locking.- Overrides:
writeToDestinationin classFileManager- Parameters:
bytes- the array containing dataoffset- from where to writelength- how many bytes to write
-
isRenameEmptyFiles
public boolean isRenameEmptyFiles() -
setRenameEmptyFiles
public void setRenameEmptyFiles(boolean renameEmptyFiles) -
getFileSize
public long getFileSize()Returns the current size of the file.- Returns:
- The size of the file in bytes.
-
getFileTime
public long getFileTime()Returns the time the file was created.- Returns:
- The time the file was created.
-
checkRollover
Determines if a rollover should occur.- Parameters:
event- The LogEvent.
-
releaseSub
Description copied from class:OutputStreamManagerDefault hook to write footer during close.- Overrides:
releaseSubin classOutputStreamManager- Parameters:
timeout- timeouttimeUnit- timeout time unit- Returns:
- true if all resources were closed normally, false otherwise.
-
rollover
-
rollover
public void rollover() -
createFileAfterRollover
- Throws:
IOException
-
getPatternProcessor
Returns the pattern processor.- Returns:
- The PatternProcessor.
-
setTriggeringPolicy
-
setRolloverStrategy
-
setPatternProcessor
-
getTriggeringPolicy
Returns the triggering policy.- Type Parameters:
T- TriggeringPolicy type- Returns:
- The TriggeringPolicy
-
getSemaphore
Semaphore getSemaphore()Package-private access for tests only.- Returns:
- The semaphore that controls access to the rollover operation.
-
getRolloverStrategy
Returns the rollover strategy.- Returns:
- The RolloverStrategy
-
rollover
-
updateData
Updates the RollingFileManager's data during a reconfiguration. This method should be considered private. It is not thread safe and calling it outside of a reconfiguration may lead to errors. This method may be made protected in a future release.- Overrides:
updateDatain classAbstractManager- Parameters:
data- The data to update.
-
initialFileTime
-