当前位置: 代码迷 >> 综合 >> 日志写入删除
  详细解决方案

日志写入删除

热度:12   发布时间:2024-02-19 21:34:01.0

-- 将日志信息写入文件中
function writeLog2File(msg)
    if cc.Application:getInstance():getTargetPlatform() == cc.PLATFORM_OS_WINDOWS then  -- win
        local logFilePath = cc.FileUtils:getInstance():getWritablePath() .. "debug_log.txt"
        io.writefile(logFilePath , string.format("%s: %s\n", os.date(), msg), "a+")  
    end
end

-- 删除本地文件
function deleteLogFile()
    if cc.Application:getInstance():getTargetPlatform() ~= cc.PLATFORM_OS_WINDOWS then return end
    local logFilePath = cc.FileUtils:getInstance():getWritablePath() .. "debug_log.txt"
    local isExist = cc.FileUtils:getInstance():isFileExist(logFilePath)
    if isExist then
        cc.FileUtils:getInstance():removeFile(logFilePath)
    end
end
deleteLogFile()
 

  相关解决方案