之前一直想找cocos 打印寫log文件日志
因為之前一直都是控制臺輸出
后來自己也寫了一個寫log文件日志
公司項目里面也支持安卓寫log文件日志
偶然發(fā)現(xiàn)quick 3.3 翻金幣demo里面有debug.log文件
打開看了一下 發(fā)現(xiàn)就是把控制臺輸出到文件了
覺得挺不錯
然后在3.10的框架里面找 沒有發(fā)現(xiàn)
然后又翻底層
經(jīng)過反向搜索文件名 發(fā)現(xiàn)
string ProjectConfig::getDebugLogFilePath() const
{
auto path(getProjectDir());
path.append("debug.log");
return path;
}
找到ProjectConfig
通過ProjectConfig在3.10的框架里面發(fā)現(xiàn)了命令行代碼段
3.3代碼
void ProjectConfig::parseCommandLine(const vector<string> &args)
{
...
else if (arg.compare("-write-debug-log") == 0) //開啟寫文件日志
{
setWriteDebugLogToFile(true);
}
else if (arg.compare("-disable-write-debug-log") == 0) //關(guān)閉寫文件日志
{
setWriteDebugLogToFile(false);
}
...
}
3.10代碼
//使用樣例 -write-debug-log debug.log
void ProjectConfig::parseCommandLine(const vector<string> &args)
{
...
else if (arg.compare("-write-debug-log") == 0) //支持輸入log文件名*it就是文件名
{
++it;
if (it == args.end()) break;
setDebugLogFilePath((*it));
setWriteDebugLogToFile(true);
}
...
}
發(fā)現(xiàn)命令行后 有4種方式可以配置
設(shè)置visul studio下項目的屬性了:
右鍵項目 -> 屬性 -> 配置屬性 -> 調(diào)試 -> 命令參數(shù) -> 編輯 -> 在后面加入 -write-debug-log $(ProjectDir)debug.log
然后就ok了注意 要空格哦!看到編輯里面原有的值烁试,你就會豁然開朗……這里設(shè)置的這些值就是要傳入mian函數(shù)的參數(shù)了雇初,注意每個參數(shù)之間要空格,至于$(ProjectDir)debug.log 這個參數(shù)可以自定義减响,因為cocos代碼中第一個字段是開關(guān)抵皱,然后*(++it)才是路徑值.
這個方法我試過了 在vs里面運行有效 直接運行exe無效
而且路徑需要你自己折騰
-workdir $(ProjectDir)../../../ -write-debug-log $(OutDir)../../../../simulator/win32/debug.log //輸出到 XX/Debug.win32
-workdir $(ProjectDir)../../../ -write-debug-log $(ProjectDir)debug.log //輸出到sln同級目錄
-workdir $(ProjectDir)../../../ -write-debug-log debug.log //輸出到exe同級目錄建立start.bat批處理文件
文件內(nèi)容
START FLuaFrame.exe -write-debug-log debug.log
其他樣例
START FLuaFrame.exe -workdir %~dp0 -file src/main.lua -size 640x1136 -scale 0.8打開控制臺 輸入exe路徑 后面帶命令行參數(shù)
創(chuàng)建快捷方式 在快捷方式點擊屬性 后面帶命令行參數(shù)