AWSDDLogFormatter

Objective-C

@protocol AWSDDLogFormatter <NSObject>

Swift

protocol AWSDDLogFormatter : 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

    - (NSString *_Nullable)formatLogMessage:(nonnull AWSDDLogMessage *)logMessage;

    Swift

    func format(message logMessage: AWSDDLogMessage) -> 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), it could possibly use these hooks to switch to thread-safe versions of the code.

    Declaration

    Objective-C

    - (void)didAddToLogger:(nonnull id<AWSDDLogger>)logger;

    Swift

    optional func didAdd(to logger: AWSDDLogger)
    • 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),
    • 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. *

    Declaration

    Objective-C

    - (void)didAddToLogger:(nonnull id<AWSDDLogger>)logger
                   inQueue:(nonnull dispatch_queue_t)queue;

    Swift

    optional func didAdd(to logger: AWSDDLogger, in queue: DispatchQueue)
  • See the above description for didAddToLogger:

    Declaration

    Objective-C

    - (void)willRemoveFromLogger:(nonnull id<AWSDDLogger>)logger;

    Swift

    optional func willRemove(from logger: AWSDDLogger)