DDLogFormatter
Objective-C
@protocol DDLogFormatter <NSObject>
Swift
protocol DDLogFormatter : NSObjectProtocol
This protocol describes the behavior of a log formatter
-
Formatters may optionally be added to any logger. This allows for increased flexibility in the logging environment. For example, log messages for log files may be formatted differently than log messages for the console.
For more information about formatters, see the “Custom Formatters” page: Documentation/CustomFormatters.md
The formatter may also optionally filter the log message by returning nil, in which case the logger will not log the message.
Declaration
Objective-C
- (nullable NSString *)formatLogMessage:(nonnull DDLogMessage *)logMessage;
Swift
func format(message logMessage: DDLogMessage) -> String?
-
A single formatter instance can be added to multiple loggers. These methods provides hooks to notify the formatter of when it’s added/removed.
This is primarily for thread-safety. If a formatter is explicitly not thread-safe, it may wish to throw an exception if added to multiple loggers. Or if a formatter has potentially thread-unsafe code (e.g. NSDateFormatter with 10.0 behavior), it could possibly use these hooks to switch to thread-safe versions of the code.
-
- A single formatter instance can be added to multiple loggers.
- These methods provides hooks to notify the formatter of when it’s added/removed. *
- This is primarily for thread-safety.
- If a formatter is explicitly not thread-safe, it may wish to throw an exception if added to multiple loggers.
- Or if a formatter has potentially thread-unsafe code (e.g. NSDateFormatter with 10.0 behavior),
- it could possibly use these hooks to switch to thread-safe versions of the code or use dispatch_set_specific() .* to add its own specific values. *