DDFileLogger
Objective-C
@interface DDFileLogger : DDAbstractLogger <DDLogger>
Swift
class DDFileLogger : DDAbstractLogger, DDLogger
The standard implementation for a file logger
-
Default initializer.
Declaration
Objective-C
- (nonnull instancetype)init;
Swift
convenience init()
-
Designated initializer, requires a
DDLogFileManager
instance. A global queue w/ default priority is used to run callbacks. If needed, specify queue usinginitWithLogFileManager:completionQueue:
.Declaration
Objective-C
- (nonnull instancetype)initWithLogFileManager: (nonnull id<DDLogFileManager>)logFileManager;
Swift
convenience init(logFileManager: DDLogFileManager)
-
Designated initializer, requires a
DDLogFileManager
instance. The completionQueue is used to executedidArchiveLogFile:wasRolled:
, and the callback inrollLogFileWithCompletionBlock:
. If nil, a global queue w/ default priority is used.Declaration
Objective-C
- (nonnull instancetype) initWithLogFileManager:(nonnull id<DDLogFileManager>)logFileManager completionQueue:(nullable dispatch_queue_t)dispatchQueue;
Swift
init(logFileManager: DDLogFileManager, completionQueue dispatchQueue: DispatchQueue?)
-
Deprecated
Use -willLogMessage:
Deprecated. Use
willLogMessage:
Declaration
Objective-C
- (void)willLogMessage;
Swift
func willLogMessage()
-
Deprecated
Use -didLogMessage:
Deprecated. Use
didLogMessage:
Declaration
Objective-C
- (void)didLogMessage;
Swift
func didLogMessage()
-
Called when the logger is about to write message. Call super before your implementation.
Declaration
Objective-C
- (void)willLogMessage:(nonnull DDLogFileInfo *)logFileInfo;
Swift
func willLogMessage(_ logFileInfo: DDLogFileInfo)
-
Called when the logger wrote message. Call super after your implementation.
Declaration
Objective-C
- (void)didLogMessage:(nonnull DDLogFileInfo *)logFileInfo;
Swift
func didLogMessage(_ logFileInfo: DDLogFileInfo)
-
Writes all in-memory log data to the permanent storage. Call super before your implementation. Don’t call this method directly, instead use the
[DDLog flushLog]
to ensure all log messages are included in flush.Declaration
Objective-C
- (void)flush;
Swift
func flush()
-
Called when the logger checks archive or not current log file. Override this method to extend standard behavior. By default returns NO. This is executed directly on the logger’s internal queue, so keep processing light!
Declaration
Objective-C
- (BOOL)shouldArchiveRecentLogFileInfo: (nonnull DDLogFileInfo *)recentLogFileInfo;
Swift
func shouldArchiveRecentLogFileInfo(_ recentLogFileInfo: DDLogFileInfo) -> Bool
-
Log File Rolling:
maximumFileSize
: The approximate maximum size (in bytes) to allow log files to grow. If a log file is larger than this value after a log statement is appended, then the log file is rolled.rollingFrequency
How often to roll the log file. The frequency is given as anNSTimeInterval
, which is a double that specifies the interval in seconds. Once the log file gets to be this old, it is rolled.doNotReuseLogFiles
When set, will always create a new log file at application launch.Both the
maximumFileSize
and therollingFrequency
are used to manage rolling. Whichever occurs first will cause the log file to be rolled.For example: The
rollingFrequency
is 24 hours, but the log file surpasses themaximumFileSize
after only 20 hours. The log file will be rolled at that 20 hour mark. A new log file will be created, and the 24 hour timer will be restarted.You may optionally disable rolling due to filesize by setting
maximumFileSize
to zero. If you do so, rolling is based solely onrollingFrequency
.You may optionally disable rolling due to time by setting
rollingFrequency
to zero (or any non-positive number). If you do so, rolling is based solely onmaximumFileSize
.If you disable both
maximumFileSize
androllingFrequency
, then the log file won’t ever be rolled. This is strongly discouraged.Declaration
Objective-C
@property unsigned long long maximumFileSize;
Swift
var maximumFileSize: UInt64 { get set }
-
See description for
maximumFileSize
Declaration
Objective-C
@property NSTimeInterval rollingFrequency;
Swift
var rollingFrequency: TimeInterval { get set }
-
See description for
maximumFileSize
Declaration
Objective-C
@property BOOL doNotReuseLogFiles;
Swift
var doNotReuseLogFiles: Bool { get set }
-
The DDLogFileManager instance can be used to retrieve the list of log files, and configure the maximum number of archived log files to keep.
See
DDLogFileManager.maximumNumberOfLogFilesDeclaration
Objective-C
@property (nonatomic, strong, readonly) id<DDLogFileManager> _Nonnull logFileManager;
Swift
var logFileManager: DDLogFileManager { get }
-
When using a custom formatter you can set the
logMessage
method not to append\n
character after each output. This allows for some greater flexibility with custom formatters. Default value is YES.Declaration
Objective-C
@property (nonatomic) BOOL automaticallyAppendNewlineForCustomFormatters;
Swift
var automaticallyAppendNewlineForCustomFormatters: Bool { get set }
-
You can optionally force the current log file to be rolled with this method. CompletionBlock will be called on main queue.
Declaration
Objective-C
- (void)rollLogFileWithCompletionBlock:(nullable void (^)(void))completionBlock;
Swift
func rollLogFile(withCompletion completionBlock: (() -> Void)? = nil)
-
Deprecated
Use -rollLogFileWithCompletionBlock:
Method is deprecated. @deprecated Use
rollLogFileWithCompletionBlock:
method instead.Declaration
Objective-C
- (void)rollLogFile;
Swift
func rollLogFile()
-
Returns the log file that should be used. If there is an existing log file that is suitable, within the constraints of
maximumFileSize
androllingFrequency
, then it is returned.Otherwise a new file is created and returned. If this failes,
NULL
is returned.Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) DDLogFileInfo *currentLogFileInfo;
Swift
var currentLogFileInfo: DDLogFileInfo? { get }
-
Undocumented
Declaration
Objective-C
- (instancetype)wrapWithBuffer;
Swift
func wrapWithBuffer() -> Self
-
Undocumented
Declaration
Objective-C
- (instancetype)unwrapFromBuffer;
Swift
func unwrapFromBuffer() -> Self