Crashlytics日志功能在CLSUserLogging.m中崩溃

时间:2017-04-10 12:18:04

标签: crashlytics google-fabric

Fabric Crashlytics偶尔会在调用CLSLogv方法时崩溃。崩溃非常随机,不确定它的输入是什么输入。

以下是崩溃日志:

Crashed: com.apple.main-thread
0  CoreFoundation                 0x18289d688 __CFStringAppendFormatCore + 12780
1  CoreFoundation                 0x18289a464 _CFStringCreateWithFormatAndArgumentsAux2 + 244
2  Foundation                     0x1831b6320 -[NSPlaceholderString initWithFormat:locale:arguments:] + 168
3  Dream11                        0x1004823e4 CLSLogv (CLSUserLogging.m:368)
4  Dream11                        0x1001d73a8 specialized crashlyticsLog(format : String, [CVarArg], file : String, function : String, line : Int) -> () (LogManager.swift)`

这是方法。

func VERBOSELOG(_ format: String = "",
            _ args:[CVarArg] = [],
            file: String = #file,
            function: String = #function,
            line: Int = #line) {
    if ENABLED_LOGGING.contains("VERBOSE") {
        do {
           try crashlyticsLog(format: "\nVERBOSE: " + format, args, file: file, function: function, line: line)
        } catch let error {
           print(error)
        }
    }
}

func crashlyticsLog(format: String = "",
                _ args:[CVarArg] = [],
                file: String = #file,
                function: String = #function,
                line: Int = #line) throws {
     let filename = file.components(separatedBy: "/").last!.components(separatedBy: ".").first!
     #if SWIFT_DEBUG
         print("\(filename).\(function) line \(line) $ \(format)")
     #else
         CLSLogv("\(filename).\(function) line \(line) $ \(format)", getVaList(args))
     #endif
}

2 个答案:

答案 0 :(得分:0)

它是NSLog的字符限制,我对NSLogCLSLogv造成了同样的崩溃。不适用于print

答案 1 :(得分:0)

我遇到了类似的崩溃,该崩溃随以下堆栈跟踪而随机发生

0  CoreFoundation                 0x1b99b84d4 __CFStringAppendFormatCore + 6000
1  CoreFoundation                 0x1b99ba5bc _CFStringCreateWithFormatAndArgumentsAux2 + 136
2  flockmail                      0x1006725ec CLSLogv + 374 (CLSUserLogging.m:374)

我后来发现的问题是我记录消息的方式。

CLSLogv(message, getVaList([])) // Incorrect

我正在以以下格式传递消息,因此,如果消息中包含某些%@%d%0或类似的内容,则它将寻找vaList来替换它。

修正为

CLSLogv("%@", getVaList([message]))

在这种情况下,似乎格式是从外部提供的,只需确保format字符串参数与args参数是同步的。

更多参考资料: https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Strings/Articles/FormatStrings.html https://docs.fabric.io/apple/crashlytics/enhanced-reports.html#custom-logs