Fine Grained Logging when using CocoaLumberJack in Swift

I want to be able to open the debug logging layer for a specific file in an iOS app. We are using CocoaLumberJack in Swift as our logging framework. According to the documentation , this is possible in Objective C, but I couldn't find any documentation regarding Swift. Can this be done? If so, how?

Thanks, Omer

+3


source to share


1 answer


Finally figured out how to do it. I did it by creating another enum:

public enum CustomLogFlags : UInt{
    case test = 0b0100000
}

      

And then set the log level:



DDLog.logLevel = DDLogLevel(rawValue: DDLogLevel.error.rawValue | CustomLogFlags.test.rawValue) ?? DDLogLevel.error

      

You can now log messages using the new log level:

let logLevel = DDLogFlag(rawValue: CustomLogFlags.test.rawValue)
let logMsg = DDLogMessage(message: message(), level: logLevel, flag: flag, context: 0,
                    file: file, function: function, line: line,
                    tag: tag, options: DDLogMessageOptions(rawValue: 0), timestamp: nil)
DDLog.log(logAsync, message: logMsg)

      

0


source







All Articles