FileLogHandler class
FileLogHandler
is a class that extends BDCleanableLogHandler
.
It is designed to handle logging records
BDLogRecord by writing them to files.
The class is initialized with several parameters, including logNamePrefix, maxLogSizeInMb, maxFilesCount, logFileDirectory, supportedLevels, and logFormatter. These parameters are used to control the behavior of the log handler.
The handleRecord method is used to write a BDLogRecord to the current log file.
If the current log file exceeds the maximum size maxLogSizeInMb, it closes the current log file and creates a new one.
The onFileExceededMaxSize
method is called when
the current log file exceeds the maximum size.
It flushes and closes the current file, increments the current log file index, and updates the current log file.
The removeOldLogFilesIfRequired method is used to remove old log files if the current count of log files exceeds the maximum files count maxFilesCount.
The initializeFileSink method is used to create a
new log file in the specified directory (logDir
).
The updateCurrentLogFile method is used to update the current log file with a newly created one.
The getLogFileIndex and getLatestLogFileIndex methods are used to get the index of a log file and the latest log file index, respectively.
- Inheritance
-
- Object
- BDLogHandler
- BDCleanableLogHandler
- FileLogHandler
Constructors
-
FileLogHandler.new({required String logNamePrefix, required int maxLogSizeInMb, required int maxFilesCount, required Directory logFileDirectory, List<
BDLevel> supportedLevels = const <BDLevel>[BDLevel.warning, BDLevel.success, BDLevel.error], BDLogFormatter logFormatter = const DefaultLogFormatter()}) - Create a new instance of FileLogHandler.
Properties
- currentLogFile ↔ File
-
The current log file that logs are written to.
If this log file exceeds maxLogSizeInMb, current log file will be closed
and new one will be created with updateCurrentLogFile method
getter/setter pair
- currentLogIndex ↔ int
-
The index of the current log file.
Will be incremented on every update of currentLogFile.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- logFileDirectory → Directory
-
Directory where to store the log files.
final
- logFormatter → BDLogFormatter
-
BDLogFormatter that define how BDLogRecord should be written.
final
- logNamePrefix → String
-
Prefix of each log files created by this FileLogHandler.
final
- maxFilesCount → int
-
Maximum count of files to keep.
final
- maxLogSizeInMb → int
-
Maximum size of a log file in MB.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
supportedLevels
→ List<
BDLevel> -
Supported BDLevel of BDLogRecord.
final
- writer ↔ RandomAccessFile?
-
The writer to perform operations on the currentLogFile
getter/setter pair
Methods
-
clean(
) → Future< void> -
Clean resources contained within this BDLogHandler.
override
-
getLatestLogFileIndex(
List< File> logFiles) → int -
Get latest log file index from
logFiles
. -
getLogFileIndex(
String fileName) → int -
Get the index of the log file from the
fileName
. -
getLogFiles(
) → List< File> - Get all the log files currently available in logFileDirectory.
-
handleRecord(
BDLogRecord record) → Future< void> -
Handle the BDLogRecord.
override
-
initializeFileSink(
Directory logDir) → RandomAccessFile - Create log file to written to.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onFileExceededMaxSize(
) → void - Called when the current log file exceeded maxLogSizeInMb.
-
removeOldLogFilesIfRequired(
) → void - Remove the old log files if the current count of log files exceed the number of log files.
-
sortFileByIndex(
List< File> logFiles) → List<File> - Sort the list of log files by their log indexes.
-
supportLevel(
BDLevel level) → bool -
Allow the BDLogHandler to specify
which BDLevel of BDLogRecord he can handle.
override
-
toString(
) → String -
A string representation of this object.
inherited
-
updateCurrentLogFile(
Directory logDir) → RandomAccessFile - Updates current log file with a newly created one
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Constants
- logFileNameSuffix → const String
- The suffix added after the logNamePrefix followed by the log file index.