AWSDDTTYLogger

Objective-C

@interface AWSDDTTYLogger : AWSDDAbstractLogger <AWSDDLogger>

Swift

class AWSDDTTYLogger : AWSDDAbstractLogger, AWSDDLogger

This class provides a logger for Terminal output or Xcode console output, depending on where you are running your code.

As described in the “Getting Started” page, the traditional NSLog() function directs it’s output to two places:

  • Apple System Log (so it shows up in Console.app)
  • StdErr (if stderr is a TTY, so log statements show up in Xcode console)

To duplicate NSLog() functionality you can simply add this logger and an asl logger. However, if you instead choose to use file logging (for faster performance), you may choose to use only a file logger and a tty logger.

  • Singleton instance. Returns nil if the initialization of the AWSDDTTYLogger fails.

    Declaration

    Objective-C

    @property (class, nonatomic, strong, readonly, nullable) AWSDDTTYLogger *sharedInstance;

    Swift

    class var sharedInstance: AWSDDTTYLogger? { get }
  • Want to use different colors for different log levels? Enable this property.

    If you run the application via the Terminal (not Xcode), the logger will map colors to xterm-256color or xterm-color (if available).

    Xcode does NOT natively support colors in the Xcode debugging console. You’ll need to install the XcodeColors plugin to see colors in the Xcode console. https://github.com/robbiehanson/XcodeColors

    The default value is NO.

    Declaration

    Objective-C

    @property BOOL colorsEnabled;

    Swift

    var colorsEnabled: Bool { get set }
  • 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 }
  • Unavailable

    Using this initializer is not supported. Please use AWSDDTTYLogger.sharedInstance. *

    Declaration

    Objective-C

    - (nonnull instancetype)init;
  • The default color set (foregroundColor, backgroundColor) is:

    • AWSDDLogFlagError = (red, nil)
    • AWSDDLogFlagWarning = (orange, nil)

    You can customize the colors however you see fit. Please note that you are passing a flag, NOT a level.

    GOOD : [ttyLogger setForegroundColor:pink backgroundColor:nil forFlag:AWSDDLogFlagInfo]; // <- Good :) BAD : [ttyLogger setForegroundColor:pink backgroundColor:nil forFlag:AWSDDLogLevelInfo]; // <- BAD! :(

    AWSDDLogFlagInfo = 0…00100 AWSDDLogLevelInfo = 0…00111 <- Would match AWSDDLogFlagInfo and AWSDDLogFlagWarning and AWSDDLogFlagError

    If you run the application within Xcode, then the XcodeColors plugin is required.

    If you run the application from a shell, then AWSDDTTYLogger will automatically map the given color to the closest available color. (xterm-256color or xterm-color which have 256 and 16 supported colors respectively.)

    This method invokes setForegroundColor:backgroundColor:forFlag:context: and applies it to LOG_CONTEXT_ALL.

    Declaration

    Objective-C

    - (void)setForegroundColor:(nullable AWSDDColor *)txtColor
               backgroundColor:(nullable AWSDDColor *)bgColor
                       forFlag:(AWSDDLogFlag)mask;

    Swift

    func setForegroundColor(_ txtColor: UIColor?, backgroundColor bgColor: UIColor?, for mask: AWSDDLogFlag)
  • Just like setForegroundColor:backgroundColor:flag, but allows you to specify a particular logging context.

    A logging context is often used to identify log messages coming from a 3rd party framework, although logging context’s can be used for many different functions.

    Use LOG_CONTEXT_ALL to set the default color for all contexts that have no specific color set defined.

    Logging context’s are explained in further detail here: Documentation/CustomContext.md

    Declaration

    Objective-C

    - (void)setForegroundColor:(nullable AWSDDColor *)txtColor
               backgroundColor:(nullable AWSDDColor *)bgColor
                       forFlag:(AWSDDLogFlag)mask
                       context:(NSInteger)ctxt;

    Swift

    func setForegroundColor(_ txtColor: UIColor?, backgroundColor bgColor: UIColor?, for mask: AWSDDLogFlag, context ctxt: Int)
  • Similar to the methods above, but allows you to map AWSDDLogMessage->tag to a particular color profile. For example, you could do something like this:

    static NSString *const PurpleTag = @“PurpleTag”;

    #define AWSDDLogPurple(frmt, …) LOG_OBJC_TAG_MACRO(NO, 0, 0, 0, PurpleTag, frmt, ##VA_ARGS)

    And then where you configure CocoaLumberjack:

    purple = AWSDDMakeColor((64/255.0), (0/255.0), (128/255.0));

    or any UIColor/NSColor constructor.

    Note: For CLI OS X projects that don’t link with AppKit use AWSCLIColor objects instead

    [[AWSDDTTYLogger sharedInstance] setForegroundColor:purple backgroundColor:nil forTag:PurpleTag]; [AWSDDLog addLogger:[AWSDDTTYLogger sharedInstance]];

    This would essentially give you a straight NSLog replacement that prints in purple:

    AWSDDLogPurple(@“I’m a purple log message!”);

    Declaration

    Objective-C

    - (void)setForegroundColor:(nullable AWSDDColor *)txtColor
               backgroundColor:(nullable AWSDDColor *)bgColor
                        forTag:(nonnull id<NSCopying>)tag;

    Swift

    func setForegroundColor(_ txtColor: UIColor?, backgroundColor bgColor: UIColor?, forTag tag: NSCopying)
  • Clearing color profiles.

    Declaration

    Objective-C

    - (void)clearColorsForFlag:(AWSDDLogFlag)mask;

    Swift

    func clearColors(for mask: AWSDDLogFlag)
  • Undocumented

    Declaration

    Objective-C

    - (void)clearColorsForFlag:(AWSDDLogFlag)mask context:(NSInteger)context;

    Swift

    func clearColors(for mask: AWSDDLogFlag, context: Int)
  • Undocumented

    Declaration

    Objective-C

    - (void)clearColorsForTag:(id <NSCopying>)tag;

    Swift

    func clearColors(forTag tag: NSCopying)
  • Undocumented

    Declaration

    Objective-C

    - (void)clearColorsForAllFlags;

    Swift

    func clearColorsForAllFlags()
  • Undocumented

    Declaration

    Objective-C

    - (void)clearColorsForAllTags;

    Swift

    func clearColorsForAllTags()
  • Undocumented

    Declaration

    Objective-C

    - (void)clearAllColors;

    Swift

    func clearAllColors()