mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
Respond to CR.
This commit is contained in:
parent
e1049fdfcc
commit
dd4f1babba
3 changed files with 63 additions and 38 deletions
|
@ -4,18 +4,42 @@
|
|||
|
||||
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.
|
||||
*/
|
||||
@interface OWSLogger : NSObject
|
||||
|
||||
+ (void)verbose:(OWSLogBlock)logBlock;
|
||||
+ (void)debug:(OWSLogBlock)logBlock;
|
||||
+ (void)info:(OWSLogBlock)logBlock;
|
||||
+ (void)warn:(OWSLogBlock)logBlock;
|
||||
+ (void)error:(OWSLogBlock)logBlock;
|
||||
+ (void)verbose:(NSString *)logString;
|
||||
+ (void)debug:(NSString *)logString;
|
||||
+ (void)info:(NSString *)logString;
|
||||
+ (void)warn:(NSString *)logString;
|
||||
+ (void)error:(NSString *)logString;
|
||||
|
||||
+ (void)flush;
|
||||
|
||||
@end
|
||||
|
|
|
@ -8,29 +8,29 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
|
||||
@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
|
||||
|
|
|
@ -7,9 +7,9 @@ import Foundation
|
|||
// Once we're on Swift4.2 we can mark this as inlineable
|
||||
// @inlinable
|
||||
public func owsFormatLogMessage(_ logString: String,
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line) -> String {
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line) -> String {
|
||||
let filename = (file as NSString).lastPathComponent
|
||||
// We format the filename & line number in a format compatible
|
||||
// with XCode's "Open Quickly..." feature.
|
||||
|
@ -25,49 +25,50 @@ open class Logger: NSObject {
|
|||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line) {
|
||||
#if DEBUG
|
||||
OWSLogger.verbose({
|
||||
return owsFormatLogMessage(logString(), file: file, function: function, line: line)
|
||||
})
|
||||
#endif
|
||||
guard ShouldLogVerbose() else {
|
||||
return
|
||||
}
|
||||
OWSLogger.verbose(owsFormatLogMessage(logString(), file: file, function: function, line: line))
|
||||
}
|
||||
|
||||
open class func debug(_ logString: @escaping @autoclosure () -> String,
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line) {
|
||||
#if DEBUG
|
||||
OWSLogger.debug({
|
||||
return owsFormatLogMessage(logString(), file: file, function: function, line: line)
|
||||
})
|
||||
#endif
|
||||
guard ShouldLogDebug() else {
|
||||
return
|
||||
}
|
||||
OWSLogger.debug(owsFormatLogMessage(logString(), file: file, function: function, line: line))
|
||||
}
|
||||
|
||||
open class func info(_ logString: String,
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line) {
|
||||
OWSLogger.info({
|
||||
return owsFormatLogMessage(logString, file: file, function: function, line: line)
|
||||
})
|
||||
guard ShouldLogInfo() else {
|
||||
return
|
||||
}
|
||||
OWSLogger.info(owsFormatLogMessage(logString, file: file, function: function, line: line))
|
||||
}
|
||||
|
||||
open class func warn(_ logString: String,
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line) {
|
||||
OWSLogger.warn({
|
||||
return owsFormatLogMessage(logString, file: file, function: function, line: line)
|
||||
})
|
||||
guard ShouldLogWarning() else {
|
||||
return
|
||||
}
|
||||
OWSLogger.warn(owsFormatLogMessage(logString, file: file, function: function, line: line))
|
||||
}
|
||||
|
||||
open class func error(_ logString: String,
|
||||
file: String = #file,
|
||||
function: String = #function,
|
||||
line: Int = #line) {
|
||||
OWSLogger.error({
|
||||
return owsFormatLogMessage(logString, file: file, function: function, line: line)
|
||||
})
|
||||
guard ShouldLogError() else {
|
||||
return
|
||||
}
|
||||
OWSLogger.error(owsFormatLogMessage(logString, file: file, function: function, line: line))
|
||||
}
|
||||
|
||||
open class func flush() {
|
||||
|
|
Loading…
Reference in a new issue