在ipod5上的IOS7中使用Lumberjack,我向DDLog添加了DDASLLogger,并记录了一些内容。并使用“asl_search”获取日志,但一无所获。当我在ios7 iphone模拟器上执行此操作时,我得到了准确记录的内容。是DDASLLogger的错误吗?

最佳答案

我终于找到了答案,是的。这是一个记录到“asl_search only finds messages with ReadUID set”的错误。将消息发送到ASL时,我们需要为它设置ReadUID属性。否则,asl_search找不到它。

DDASLLogger中发送消息的代码如下:

- (void)logMessage:(DDLogMessage *)logMessage
{
    NSString *logMsg = logMessage->logMsg;

    if (formatter)
    {
        logMsg = [formatter formatLogMessage:logMessage];
    }

    if (logMsg)
    {
        const char *msg = [logMsg UTF8String];

        int aslLogLevel;
        switch (logMessage->logFlag)
        {
            // Note: By default ASL will filter anything above level 5 (Notice).
            // So our mappings shouldn't go above that level.

            case LOG_FLAG_ERROR : aslLogLevel = ASL_LEVEL_ALERT;   break;
            case LOG_FLAG_WARN  : aslLogLevel = ASL_LEVEL_CRIT;    break;
            case LOG_FLAG_INFO  : aslLogLevel = ASL_LEVEL_ERR;     break;
            case LOG_FLAG_DEBUG : aslLogLevel = ASL_LEVEL_WARNING; break;
            default             : aslLogLevel = ASL_LEVEL_NOTICE;  break;
        }

        asl_log(client, NULL, aslLogLevel, "%s", msg);
    }
}

我们只需要改变
        asl_log(client, NULL, aslLogLevel, "%s", msg);


        aslmsg m = asl_new(ASL_TYPE_MSG);
        asl_set(m, ASL_KEY_READ_UID, "501");
        asl_log(client, m, aslLogLevel, "%s", msg);

有用。谢谢。

关于ios - 在真实设备上使用IOS7中的DDASLLogger不记录任何内容,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20244303/

10-10 23:30