zixun / GodEye

Automaticly display Log,Crash,Network,ANR,Leak,CPU,RAM,FPS,NetFlow,Folder and etc with one line of code based on Swift. Just like God opened his eyes
MIT License
3.85k stars 351 forks source link

Signal Crash #13

Closed GLChan closed 7 years ago

GLChan commented 7 years ago

直接点击Signal Crash 重新打开app没有发现crash日志,然后进入app再重新点击Exception Crash才会把前面那个Signle的日志打印出来

zixun commented 7 years ago

感谢反馈。我刚刚试了3次,都能正常打印,能否提供更多细节

GLChan commented 7 years ago

点击Singal Crash的 cell 导致崩溃之后,不能在Crash日志里面看到崩溃的信息,这个是原来就这样的还是?

zixun commented 7 years ago

原来就是可以正常打印=。=,我试了几次也能正常打印,好奇怪

GLChan commented 7 years ago

我是直接下的源码跑真机的😂

zixun commented 7 years ago

对了,crash相关的你不能连着Xcode的debugger,Xcode的debugger优先级比较高,会导致crash监控被debugger吃掉😂

GLChan commented 7 years ago

装完拔掉线重新打开app测试的,🤔

zixun commented 7 years ago

ConsoleController+Eye.swift文件中:

//MARK: - CrashEye
extension ConsoleController: CrashEyeDelegate {

    /// god's crash eye callback
    func crashEyeDidCatchCrash(with model:CrashModel) {
        let model = CrashRecordModel(model: model)
        model.insertSync(complete: { [unowned self] (success:Bool) in
            self.addRecord(model: model)
        })
    }
}

你用Log4G打印几条日志输出下CrashModel看

GLChan commented 7 years ago

没发现有打印什么= =

GLChan commented 7 years ago
extension ConsoleController: CrashEyeDelegate {

    /// god's crash eye callback
    func crashEyeDidCatchCrash(with model:CrashModel) {
        let model = CrashRecordModel(model: model)
        model.insertSync(complete: { [unowned self] (success:Bool) in
            self.addRecord(model: model)
        })
        Log4G.log("😈CrashModel: \(model)")
    }
}
zixun commented 7 years ago

放在第一行:

func crashEyeDidCatchCrash(with model:CrashModel) {
        Log4G.log("😈CrashModel: \(model)")
        let model = CrashRecordModel(model: model)
        model.insertSync(complete: { [unowned self] (success:Bool) in
            self.addRecord(model: model)
        })
    }

因为系统在crash的时候留给app做处理的时间极短,而这边又需要将crash数据保存到数据库中,需要一些I/O,因此你放后面可能就执行不到了。。。

zixun commented 7 years ago

不过照你的说法Exception Crash后会把之前的Signle日志打印出来,至少能说明crash数据当时是正常保存的

GLChan commented 7 years ago
  1. 刚刚重装试了一下只点击Exception Crash, 但是只出现了Signal的日志
  2. 清除所有打印日志,bug日志 之后再次尝试点击Signal Crash,没有打印出结果😈
  3. 再次清除所有日志,点击Exception Crash,有log日志😈,但是没有bug日志 😂😂😂😂😂
zixun commented 7 years ago

找到原因了,在Swift的代码Crash的Signal Crash都是通过SIGTRAP信号往上抛的,我没监听这个信号,所以你没看到crash堆栈,(奇怪的是在模拟器是通过SIGILL信号往上抛,所以模拟器能捕获到)。

参考[http://stackoverflow.com/questions/36325140/how-to-catch-a-swift-crash-and-do-some-logging]()

然后,迷惑的来了,在Swift中OC的类Crash,也就是Exception Crash的同时会抛出一个SIGABRT信号,所以当你点击Exception Crash后发现,可以看到SIGNAL Crash的堆栈,其实并不是之前的堆栈,而是一个新的堆栈、、这个问题我暂时没想到完美的方式把这个SIGNAL屏蔽掉,等后续观察再看,不影响主功能。

我下班后把这个问题解决一下,结合之前修复的几个小问题再发布一个小版本

感谢反馈~

GLChan commented 7 years ago

不明觉厉,我说怎么有时候打印两个,一个或者不打印😂

zixun commented 7 years ago

fixed in CrashEye