2

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
}
4

2 回答 2

1

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

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

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

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

我以格式传递消息,所以如果消息有一些%@'s 或%d's%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#自定义日志

于 2020-02-11T07:13:47.083 回答
0

是不是 NSLog 的字符限制,我也遇到了NSLogCLSLogv. 不是为了print

于 2018-03-29T05:59:14.280 回答