Classes

The following classes are available globally.

  • This class represents an NSColor replacement for CLI projects that don’t link with AppKit

    See more

    Declaration

    Objective-C

    @interface CLIColor : NSObject
  • This class provides the ability to capture the ASL (Apple System Logs)

    See more

    Declaration

    Objective-C

    
    @interface DDASLLogCapture : NSObject

    Swift

    class DDASLLogCapture : NSObject
  • This class provides a logger for the Apple System Log facility.

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

    • Apple System Log
    • 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 a tty logger. However, if you instead choose to use file logging (for faster performance), you may choose to use a file logger and a tty logger.

    See more

    Declaration

    Objective-C

    
    @interface DDASLLogger : DDAbstractLogger <DDLogger>

    Swift

    class DDASLLogger : DDAbstractLogger, DDLogger
  • This class provides an abstract implementation of a database logger.

    That is, it provides the base implementation for a database logger to build atop of. All that is needed for a concrete database logger is to extend this class and override the methods in the implementation file that are prefixed with “db_”.

    See more

    Declaration

    Objective-C

    @interface DDAbstractDatabaseLogger : DDAbstractLogger {
      NSUInteger _saveThreshold;
      NSTimeInterval _saveInterval;
      NSTimeInterval _maxAge;
      NSTimeInterval _deleteInterval;
      BOOL _deleteOnEverySave;
      NSInteger _saveTimerSuspended;
      NSUInteger _unsavedCount;
      dispatch_time_t _unsavedTime;
      dispatch_source_t _saveTimer;
      dispatch_time_t _lastDeleteTime;
      dispatch_source_t _deleteTimer;
    }

    Swift

    class DDAbstractDatabaseLogger : DDAbstractLogger
  • This class provides a log formatter that filters log statements from a logging context not on the whitelist.

    A log formatter can be added to any logger to format and/or filter its output. You can learn more about log formatters here: Documentation/CustomFormatters.md

    You can learn more about logging context’s here: Documentation/CustomContext.md

    But here’s a quick overview / refresher:

    Every log statement has a logging context. These come from the underlying logging macros defined in DDLog.h. The default logging context is zero. You can define multiple logging context’s for use in your application. For example, logically separate parts of your app each have a different logging context. Also 3rd party frameworks that make use of Lumberjack generally use their own dedicated logging context.

    See more

    Declaration

    Objective-C

    @interface DDContextWhitelistFilterLogFormatter : NSObject <DDLogFormatter>

    Swift

    class DDContextWhitelistFilterLogFormatter : NSObject, DDLogFormatter
  • This class provides a log formatter that filters log statements from a logging context on the blacklist.

    See more

    Declaration

    Objective-C

    @interface DDContextBlacklistFilterLogFormatter : NSObject <DDLogFormatter>

    Swift

    class DDContextBlacklistFilterLogFormatter : NSObject, DDLogFormatter
  • This class provides a log formatter that prints the dispatch_queue label instead of the mach_thread_id.

    A log formatter can be added to any logger to format and/or filter its output. You can learn more about log formatters here: Documentation/CustomFormatters.md

    A typical NSLog (or DDTTYLogger) prints detailed info as [<process_id>:<thread_id>]. For example:

    2011-10-17 20:21:45.435 AppName[19928:5207] Your log message here

    Where: - 19928 = process id - 5207 = thread id (mach_thread_id printed in hex)

    When using grand central dispatch (GCD), this information is less useful. This is because a single serial dispatch queue may be run on any thread from an internally managed thread pool. For example:

    2011-10-17 20:32:31.111 AppName[19954:4d07] Message from my_serial_dispatch_queue 2011-10-17 20:32:31.112 AppName[19954:5207] Message from my_serial_dispatch_queue 2011-10-17 20:32:31.113 AppName[19954:2c55] Message from my_serial_dispatch_queue

    This formatter allows you to replace the standard [box:info] with the dispatch_queue name. For example:

    2011-10-17 20:32:31.111 AppName[img-scaling] Message from my_serial_dispatch_queue 2011-10-17 20:32:31.112 AppName[img-scaling] Message from my_serial_dispatch_queue 2011-10-17 20:32:31.113 AppName[img-scaling] Message from my_serial_dispatch_queue

    If the dispatch_queue doesn’t have a set name, then it falls back to the thread name. If the current thread doesn’t have a set name, then it falls back to the mach_thread_id in hex (like normal).

    Note: If manually creating your own background threads (via NSThread/alloc/init or NSThread/detachNeThread), you can use [[NSThread currentThread] setName:(NSString *)].

    See more

    Declaration

    Objective-C

    @interface DDDispatchQueueLogFormatter : NSObject <DDLogFormatter>

    Swift

    class DDDispatchQueueLogFormatter : NSObject, DDLogFormatter

DDAtomicCountable

  • The standard implementation for a file logger

    See more

    Declaration

    Objective-C

    @interface DDFileLogger : DDAbstractLogger <DDLogger>

    Swift

    class DDFileLogger : DDAbstractLogger, DDLogger
  • Default log file manager.

    All log files are placed inside the logsDirectory. If a specific logsDirectory isn’t specified, the default directory is used. On Mac, this is in ~/Library/Logs/<Application Name>. On iPhone, this is in ~/Library/Caches/Logs.

    Log files are named "<bundle identifier> <date> <time>.log" Example: com.organization.myapp 2013-12-03 17-14.log

    Archived log files are automatically deleted according to the maximumNumberOfLogFiles property.

    See more

    Declaration

    Objective-C

    @interface DDLogFileManagerDefault : NSObject <DDLogFileManager>

    Swift

    class DDLogFileManagerDefault : NSObject, DDLogFileManager
  • Most users will want file log messages to be prepended with the date and time. Rather than forcing the majority of users to write their own formatter, we will supply a logical default formatter. Users can easily replace this formatter with their own by invoking the setLogFormatter: method. It can also be removed by calling setLogFormatter:, and passing a nil parameter.

    In addition to the convenience of having a logical default formatter, it will also provide a template that makes it easy for developers to copy and change.

    See more

    Declaration

    Objective-C

    @interface DDLogFileFormatterDefault : NSObject <DDLogFormatter>

    Swift

    class DDLogFileFormatterDefault : NSObject, DDLogFormatter
  • DDLogFileInfo is a simple class that provides access to various file attributes. It provides good performance as it only fetches the information if requested, and it caches the information to prevent duplicate fetches.

    It was designed to provide quick snapshots of the current state of log files, and to help sort log files in an array.

    This class does not monitor the files, or update it’s cached attribute values if the file changes on disk. This is not what the class was designed for.

    If you absolutely must get updated values, you can invoke the reset method which will clear the cache.

    See more

    Declaration

    Objective-C

    @interface DDLogFileInfo : NSObject

    Swift

    class DDLogFileInfo : NSObject
  • The main class, exposes all logging mechanisms, loggers, … For most of the users, this class is hidden behind the logging functions like DDLogInfo

    See more

    Declaration

    Objective-C

    @interface DDLog : NSObject

    Swift

    class DDLog : NSObject
  • The DDLogMessage class encapsulates information about the log message. If you write custom loggers or formatters, you will be dealing with objects of this class.

    See more

    Declaration

    Objective-C

    @interface DDLogMessage : NSObject <NSCopying> {
      NSString *_message;
      DDLogLevel _level;
      DDLogFlag _flag;
      NSInteger _context;
      NSString *_file;
      NSString *_fileName;
      NSString *_function;
      NSUInteger _line;
      id _representedObject;
      DDLogMessageOptions _options;
      NSDate *_timestamp;
      NSString *_threadID;
      NSString *_threadName;
      NSString *_queueLabel;
      NSUInteger _qos;
    }

    Swift

    class DDLogMessage : NSObject, NSCopying
  • The DDLogger protocol specifies that an optional formatter can be added to a logger. Most (but not all) loggers will want to support formatters.

    However, writing getters and setters in a thread safe manner, while still maintaining maximum speed for the logging process, is a difficult task.

    To do it right, the implementation of the getter/setter has strict requirements:

    • Must NOT require the logMessage: method to acquire a lock.
    • Must NOT require the logMessage: method to access an atomic property (also a lock of sorts).

    To simplify things, an abstract logger is provided that implements the getter and setter.

    Logger implementations may simply extend this class, and they can ACCESS THE FORMATTER VARIABLE DIRECTLY from within their logMessage: method!

    See more

    Declaration

    Objective-C

    @interface DDAbstractLogger : NSObject <DDLogger> {
      id<DDLogFormatter> _logFormatter;
      dispatch_queue_t _loggerQueue;
    }

    Swift

    class DDAbstractLogger : NSObject, DDLogger
  • /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    See more

    Declaration

    Objective-C

    @interface DDLoggerInformation : NSObject

    Swift

    class DDLoggerInformation : NSObject
  • This formatter can be used to chain different formatters together. The log message will processed in the order of the formatters added.

    See more

    Declaration

    Objective-C

    @interface DDMultiFormatter : NSObject <DDLogFormatter>

    Swift

    class DDMultiFormatter : NSObject, DDLogFormatter
  • This class provides a logger for the Apple os_log facility.

    See more

    Declaration

    Objective-C

    
    @interface DDOSLogger : DDAbstractLogger <DDLogger>

    Swift

    class DDOSLogger : DDAbstractLogger, DDLogger
  • 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.

    See more

    Declaration

    Objective-C

    @interface DDTTYLogger : DDAbstractLogger <DDLogger>

    Swift

    class DDTTYLogger : DDAbstractLogger, DDLogger