1 void CLogService::kkLog2(const char* pszName, const char* fmt, ) { 2 cocos2d::CCFileUtils *pCCFileUtils = cocos2d::CCFileUtils::sharedFileUtils(); 3 #if defined(WIN32) || defined(_WIN32) 4 SSString path = getExePath().c_str(); 5 path += "log/"; 6 #elif defined(IOS) || defined(__APPLE__) 7 SSString path = pCCFileUtils->getWritablePath(); 8 path += "log/"; 9 #else 10 SSString path = "/mnt/sdcard/external-sd/"; 11 #endif 12 13 SSString filename = path + pszName; 14 15 va_list ap; 16 va_start(ap, fmt); 17 char buf[1024]; 18 vsprintf(buf, fmt, ap); 19 va_end(ap); 20 21 std::string strTime; 22 ___getTime(strTime); 23 strTime += " "; 24 25 #if defined(_WIN32) || defined(WIN32) 26 std::string strLogText = strTime + buf + "\r\n"; 27 ::OutputDebugStringA((LPCSTR)strLogText.c_str()); 28 #endif 29 30 // ensure the path is exist 31 _create_dir(path.c_str()); 32 33 FILE *fp = fopen(filename.c_str(), "ab+"); 34 if(fp) { 35 fwrite(strTime.c_str(), strTime.length(), 1, fp); 36 fwrite(buf, strlen(buf), 1, fp); 37 fputs("\r\n", fp); 38 fclose(fp); 39 } 40 }
|