cocos2dx 写错误日志到文件

bool saveFile(char* pContent, std::string pFileName){
    std::string path = FileUtils::getInstance()->getWritablePath() + pFileName;

    FILE* file = fopen(path.c_str(), "at+");
    if (file) {
        fputs(pContent, file);
        fputs("\n", file);

        fclose(file);
    }
    else
        printf("save file error.\n");

    return false;
}

使用样例

    char s[64];
    sprintf(s, "%d %d", COCOS2D_DEBUG, CC_CODE_IDE_DEBUG_SUPPORT);
    CCLOG("COCOS2D_DEBUG = %d, CC_CODE_IDE_DEBUG_SUPPORT = %d", COCOS2D_DEBUG, CC_CODE_IDE_DEBUG_SUPPORT);
    saveFile(s, "error.log");
    __asm int 3;

你可能感兴趣的:(cocos2dx 写错误日志到文件)