DDLog
Objective-C
@interface DDLog : NSObject
Swift
class DDLog : NSObject
The main class, exposes all logging mechanisms, loggers, …
For most of the users, this class is hidden behind the logging functions like DDLogInfo
-
Returns the singleton
DDLog
. The instance is used byDDLog
class methods.Declaration
Objective-C
@property (class, nonatomic, strong, readonly) DDLog *_Nonnull sharedInstance;
Swift
class var sharedInstance: DDLog { get }
-
Provides access to the underlying logging queue. This may be helpful to Logger classes for things like thread synchronization.
Declaration
Objective-C
@property (class, nonatomic, strong, readonly) dispatch_queue_t _Nonnull loggingQueue;
Swift
class var loggingQueue: DispatchQueue { get }
-
Logging Primitive.
This method is used by the macros or logging functions. It is suggested you stick with the macros as they’re easier to use.
Declaration
Objective-C
+ (void)log:(BOOL)asynchronous level:(DDLogLevel)level flag:(DDLogFlag)flag context:(NSInteger)context file:(nonnull const char *)file function:(nullable const char *)function line:(NSUInteger)line tag:(nullable id)tag format:(nonnull NSString *)format, ...;
Parameters
asynchronous
YES if the logging is done async, NO if you want to force sync
level
the log level
flag
the log flag
context
the context (if any is defined)
file
the current file
function
the current function
line
the current code line
tag
potential tag
format
the log format
-
Logging Primitive.
This method is used by the macros or logging functions. It is suggested you stick with the macros as they’re easier to use.
Declaration
Objective-C
- (void)log:(BOOL)asynchronous level:(DDLogLevel)level flag:(DDLogFlag)flag context:(NSInteger)context file:(nonnull const char *)file function:(nullable const char *)function line:(NSUInteger)line tag:(nullable id)tag format:(nonnull NSString *)format, ...;
Parameters
asynchronous
YES if the logging is done async, NO if you want to force sync
level
the log level
flag
the log flag
context
the context (if any is defined)
file
the current file
function
the current function
line
the current code line
tag
potential tag
format
the log format
-
Logging Primitive.
This method can be used if you have a prepared va_list. Similar to
log:level:flag:context:file:function:line:tag:format:...
Declaration
Objective-C
+ (void)log:(BOOL)asynchronous level:(DDLogLevel)level flag:(DDLogFlag)flag context:(NSInteger)context file:(nonnull const char *)file function:(nullable const char *)function line:(NSUInteger)line tag:(nullable id)tag format:(nonnull NSString *)format args:(struct __va_list_tag *)argList;
Swift
class func log(asynchronous: Bool, level: DDLogLevel, flag: DDLogFlag, context: Int, file: UnsafePointer<Int8>, function: UnsafePointer<Int8>?, line: UInt, tag: Any?, format: String, arguments argList: CVaListPointer)
Parameters
asynchronous
YES if the logging is done async, NO if you want to force sync
level
the log level
flag
the log flag
context
the context (if any is defined)
file
the current file
function
the current function
line
the current code line
tag
potential tag
format
the log format
argList
the arguments list as a va_list
-
Logging Primitive.
This method can be used if you have a prepared va_list. Similar to
log:level:flag:context:file:function:line:tag:format:...
Declaration
Objective-C
- (void)log:(BOOL)asynchronous level:(DDLogLevel)level flag:(DDLogFlag)flag context:(NSInteger)context file:(nonnull const char *)file function:(nullable const char *)function line:(NSUInteger)line tag:(nullable id)tag format:(nonnull NSString *)format args:(struct __va_list_tag *)argList;
Swift
func log(asynchronous: Bool, level: DDLogLevel, flag: DDLogFlag, context: Int, file: UnsafePointer<Int8>, function: UnsafePointer<Int8>?, line: UInt, tag: Any?, format: String, arguments argList: CVaListPointer)
Parameters
asynchronous
YES if the logging is done async, NO if you want to force sync
level
the log level
flag
the log flag
context
the context (if any is defined)
file
the current file
function
the current function
line
the current code line
tag
potential tag
format
the log format
argList
the arguments list as a va_list
-
Logging Primitive.
This method can be used if you manually prepared DDLogMessage.
Declaration
Objective-C
+ (void)log:(BOOL)asynchronous message:(nonnull DDLogMessage *)logMessage;
Swift
class func log(asynchronous: Bool, message logMessage: DDLogMessage)
Parameters
asynchronous
YES if the logging is done async, NO if you want to force sync
logMessage
the log message stored in a
DDLogMessage
model object -
Logging Primitive.
This method can be used if you manually prepared DDLogMessage.
Declaration
Objective-C
- (void)log:(BOOL)asynchronous message:(nonnull DDLogMessage *)logMessage;
Swift
func log(asynchronous: Bool, message logMessage: DDLogMessage)
Parameters
asynchronous
YES if the logging is done async, NO if you want to force sync
logMessage
the log message stored in a
DDLogMessage
model object -
Since logging can be asynchronous, there may be times when you want to flush the logs. The framework invokes this automatically when the application quits.
Declaration
Objective-C
+ (void)flushLog;
Swift
class func flushLog()
-
Since logging can be asynchronous, there may be times when you want to flush the logs. The framework invokes this automatically when the application quits.
Declaration
Objective-C
- (void)flushLog;
Swift
func flushLog()
-
Adds the logger to the system.
The level that you provide here is a preemptive filter (for performance). That is, the level specified here will be used to filter out logMessages so that the logger is never even invoked for the messages.
More information: When you issue a log statement, the logging framework iterates over each logger, and checks to see if it should forward the logMessage to the logger. This check is done using the level parameter passed to this method.
For example:
[DDLog addLogger:consoleLogger withLogLevel:DDLogLevelVerbose];
[DDLog addLogger:fileLogger withLogLevel:DDLogLevelWarning];
DDLogError(@"oh no");
=> gets forwarded to consoleLogger & fileLoggerDDLogInfo(@"hi");
=> gets forwarded to consoleLogger onlyIt is important to remember that Lumberjack uses a BITMASK. Many developers & third party frameworks may define extra log levels & flags. For example:
#define SOME_FRAMEWORK_LOG_FLAG_TRACE (1 << 6) // 0...1000000
So if you specify
DDLogLevelVerbose
to this method, you won’t see the framework’s trace messages.(SOME_FRAMEWORK_LOG_FLAG_TRACE & DDLogLevelVerbose) => (01000000 & 00011111) => NO
Consider passing
DDLogLevelAll
to this method, which has all bits set. You can also use the exclusive-or bitwise operator to get a bitmask that has all flags set, except the ones you explicitly don’t want. For example, if you wanted everything except verbose & debug:((DDLogLevelAll ^ DDLogLevelVerbose) | DDLogLevelInfo)
Declaration
Objective-C
+ (void)addLogger:(nonnull id<DDLogger>)logger withLevel:(DDLogLevel)level;
Swift
class func add(_ logger: DDLogger, with level: DDLogLevel)
-
Adds the logger to the system.
The level that you provide here is a preemptive filter (for performance). That is, the level specified here will be used to filter out logMessages so that the logger is never even invoked for the messages.
More information: When you issue a log statement, the logging framework iterates over each logger, and checks to see if it should forward the logMessage to the logger. This check is done using the level parameter passed to this method.
For example:
[DDLog addLogger:consoleLogger withLogLevel:DDLogLevelVerbose];
[DDLog addLogger:fileLogger withLogLevel:DDLogLevelWarning];
DDLogError(@"oh no");
=> gets forwarded to consoleLogger & fileLoggerDDLogInfo(@"hi");
=> gets forwarded to consoleLogger onlyIt is important to remember that Lumberjack uses a BITMASK. Many developers & third party frameworks may define extra log levels & flags. For example:
#define SOME_FRAMEWORK_LOG_FLAG_TRACE (1 << 6) // 0...1000000
So if you specify
DDLogLevelVerbose
to this method, you won’t see the framework’s trace messages.(SOME_FRAMEWORK_LOG_FLAG_TRACE & DDLogLevelVerbose) => (01000000 & 00011111) => NO
Consider passing
DDLogLevelAll
to this method, which has all bits set. You can also use the exclusive-or bitwise operator to get a bitmask that has all flags set, except the ones you explicitly don’t want. For example, if you wanted everything except verbose & debug:((DDLogLevelAll ^ DDLogLevelVerbose) | DDLogLevelInfo)
Declaration
Objective-C
- (void)addLogger:(nonnull id<DDLogger>)logger withLevel:(DDLogLevel)level;
Swift
func add(_ logger: DDLogger, with level: DDLogLevel)
-
Remove all the current loggers
Declaration
Objective-C
+ (void)removeAllLoggers;
Swift
class func removeAllLoggers()
-
Remove all the current loggers
Declaration
Objective-C
- (void)removeAllLoggers;
Swift
func removeAllLoggers()
-
Return all the current loggers
Declaration
Objective-C
@property (nonatomic, copy, readonly) NSArray<id<DDLogger>> *_Nonnull allLoggers;
Swift
var allLoggers: [DDLogger] { get }
-
Return all the current loggers with their level (aka DDLoggerInformation).
Declaration
Objective-C
@property (class, nonatomic, copy, readonly) NSArray<DDLoggerInformation *> *_Nonnull allLoggersWithLevel;
Swift
class var allLoggersWithLevel: [DDLoggerInformation] { get }
-
Return all the current loggers with their level (aka DDLoggerInformation).
Declaration
Objective-C
@property (nonatomic, copy, readonly) NSArray<DDLoggerInformation *> *_Nonnull allLoggersWithLevel;
Swift
var allLoggersWithLevel: [DDLoggerInformation] { get }
-
Returns an array with the classes that are using registered dynamic logging
Declaration
Objective-C
@property (class, nonatomic, copy, readonly) NSArray<Class> *_Nonnull registeredClasses;
Swift
class var registeredClasses: [AnyClass] { get }
-
Returns an array with the classes names that are using registered dynamic logging
Declaration
Objective-C
@property (class, nonatomic, copy, readonly) NSArray<NSString *> *_Nonnull registeredClassNames;
Swift
class var registeredClassNames: [String] { get }
-
Returns the current log level for a certain class
Declaration
Objective-C
+ (DDLogLevel)levelForClass:(nonnull Class)aClass;
Swift
class func level(for aClass: AnyClass) -> DDLogLevel
Parameters
aClass
Class
param -
Returns the current log level for a certain class
Declaration
Objective-C
+ (DDLogLevel)levelForClassWithName:(nonnull NSString *)aClassName;
Swift
class func levelForClass(withName aClassName: String) -> DDLogLevel
Parameters
aClassName
string param
-
Set the log level for a certain class
Declaration
Objective-C
+ (void)setLevel:(DDLogLevel)level forClass:(nonnull Class)aClass;
Swift
class func setLevel(_ level: DDLogLevel, for aClass: AnyClass)
Parameters
level
the new level
aClass
Class
param -
Set the log level for a certain class
Declaration
Objective-C
+ (void)setLevel:(DDLogLevel)level forClassWithName:(nonnull NSString *)aClassName;
Swift
class func setLevel(_ level: DDLogLevel, forClassWithName aClassName: String)
Parameters
level
the new level
aClassName
string param