Respond to CR.

pull/1/head
Matthew Chen 7 years ago
parent e1049fdfcc
commit dd4f1babba

@ -4,18 +4,42 @@
NS_ASSUME_NONNULL_BEGIN NS_ASSUME_NONNULL_BEGIN
typedef NSString * (^OWSLogBlock)(void); static inline BOOL ShouldLogVerbose()
{
return ddLogLevel >= DDLogLevelVerbose;
}
static inline BOOL ShouldLogDebug()
{
return ddLogLevel >= DDLogLevelDebug;
}
static inline BOOL ShouldLogInfo()
{
return ddLogLevel >= DDLogLevelInfo;
}
static inline BOOL ShouldLogWarning()
{
return ddLogLevel >= DDLogLevelWarning;
}
static inline BOOL ShouldLogError()
{
return ddLogLevel >= DDLogLevelError;
}
/** /**
* A minimal DDLog wrapper for swift. * A minimal DDLog wrapper for swift.
*/ */
@interface OWSLogger : NSObject @interface OWSLogger : NSObject
+ (void)verbose:(OWSLogBlock)logBlock; + (void)verbose:(NSString *)logString;
+ (void)debug:(OWSLogBlock)logBlock; + (void)debug:(NSString *)logString;
+ (void)info:(OWSLogBlock)logBlock; + (void)info:(NSString *)logString;
+ (void)warn:(OWSLogBlock)logBlock; + (void)warn:(NSString *)logString;
+ (void)error:(OWSLogBlock)logBlock; + (void)error:(NSString *)logString;
+ (void)flush; + (void)flush;
@end @end

@ -8,29 +8,29 @@ NS_ASSUME_NONNULL_BEGIN
@implementation OWSLogger @implementation OWSLogger
+ (void)verbose:(OWSLogBlock)logBlock; + (void)verbose:(NSString *)logString;
{ {
DDLogVerbose(@"%@", logBlock()); DDLogVerbose(@"%@", logString);
} }
+ (void)debug:(OWSLogBlock)logBlock; + (void)debug:(NSString *)logString;
{ {
DDLogDebug(@"%@", logBlock()); DDLogDebug(@"%@", logString);
} }
+ (void)info:(OWSLogBlock)logBlock; + (void)info:(NSString *)logString;
{ {
DDLogInfo(@"%@", logBlock()); DDLogInfo(@"%@", logString);
} }
+ (void)warn:(OWSLogBlock)logBlock; + (void)warn:(NSString *)logString;
{ {
DDLogWarn(@"%@", logBlock()); DDLogWarn(@"%@", logString);
} }
+ (void)error:(OWSLogBlock)logBlock; + (void)error:(NSString *)logString;
{ {
DDLogError(@"%@", logBlock()); DDLogError(@"%@", logString);
} }
+ (void)flush + (void)flush

@ -7,9 +7,9 @@ import Foundation
// Once we're on Swift4.2 we can mark this as inlineable // Once we're on Swift4.2 we can mark this as inlineable
// @inlinable // @inlinable
public func owsFormatLogMessage(_ logString: String, public func owsFormatLogMessage(_ logString: String,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line) -> String { line: Int = #line) -> String {
let filename = (file as NSString).lastPathComponent let filename = (file as NSString).lastPathComponent
// We format the filename & line number in a format compatible // We format the filename & line number in a format compatible
// with XCode's "Open Quickly..." feature. // with XCode's "Open Quickly..." feature.
@ -25,49 +25,50 @@ open class Logger: NSObject {
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line) { line: Int = #line) {
#if DEBUG guard ShouldLogVerbose() else {
OWSLogger.verbose({ return
return owsFormatLogMessage(logString(), file: file, function: function, line: line) }
}) OWSLogger.verbose(owsFormatLogMessage(logString(), file: file, function: function, line: line))
#endif
} }
open class func debug(_ logString: @escaping @autoclosure () -> String, open class func debug(_ logString: @escaping @autoclosure () -> String,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line) { line: Int = #line) {
#if DEBUG guard ShouldLogDebug() else {
OWSLogger.debug({ return
return owsFormatLogMessage(logString(), file: file, function: function, line: line) }
}) OWSLogger.debug(owsFormatLogMessage(logString(), file: file, function: function, line: line))
#endif
} }
open class func info(_ logString: String, open class func info(_ logString: String,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line) { line: Int = #line) {
OWSLogger.info({ guard ShouldLogInfo() else {
return owsFormatLogMessage(logString, file: file, function: function, line: line) return
}) }
OWSLogger.info(owsFormatLogMessage(logString, file: file, function: function, line: line))
} }
open class func warn(_ logString: String, open class func warn(_ logString: String,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line) { line: Int = #line) {
OWSLogger.warn({ guard ShouldLogWarning() else {
return owsFormatLogMessage(logString, file: file, function: function, line: line) return
}) }
OWSLogger.warn(owsFormatLogMessage(logString, file: file, function: function, line: line))
} }
open class func error(_ logString: String, open class func error(_ logString: String,
file: String = #file, file: String = #file,
function: String = #function, function: String = #function,
line: Int = #line) { line: Int = #line) {
OWSLogger.error({ guard ShouldLogError() else {
return owsFormatLogMessage(logString, file: file, function: function, line: line) return
}) }
OWSLogger.error(owsFormatLogMessage(logString, file: file, function: function, line: line))
} }
open class func flush() { open class func flush() {

Loading…
Cancel
Save