From db109e51a06bfad840f725f2aa76e8bceba20239 Mon Sep 17 00:00:00 2001 From: Vladimir Byko-Ianko Date: Thu, 5 Mar 2015 10:21:33 +0300 Subject: (1) Writing log to a file on Android and iOS was implemented; (2) Memory tracking was implemented; --- platform/file_logging.cpp | 59 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 platform/file_logging.cpp (limited to 'platform/file_logging.cpp') diff --git a/platform/file_logging.cpp b/platform/file_logging.cpp new file mode 100644 index 0000000000..edaef6a4af --- /dev/null +++ b/platform/file_logging.cpp @@ -0,0 +1,59 @@ +#include "file_logging.hpp" + +#include "../base/mutex.hpp" + +#include "../std/chrono.hpp" + +#include "../coding/file_writer.hpp" + +#include "../platform/platform.hpp" + + +void LogMessageFile(my::LogLevel level, my::SrcPoint const & srcPoint, string const & msg) +{ + static threads::Mutex mutex; + + threads::MutexGuard guard(mutex); + UNUSED_VALUE(guard); + + static unique_ptr file; + + if (file == nullptr) + { + if (GetPlatform().WritableDir().empty()) + return; + auto const curTime = system_clock::now(); + time_t const curCTime = system_clock::to_time_t(curTime); + tm * curTimeTM = localtime(&curCTime); + assert(curTimeTM != nullptr); + stringstream fileName; + fileName << "logging_" << curTimeTM->tm_year + 1900 << "_" << curTimeTM->tm_mon + 1 << "_" << curTimeTM->tm_mday << "_" + << curTimeTM->tm_hour << "_" << curTimeTM->tm_min << "_" << curTimeTM->tm_sec << ".txt"; + file.reset(new FileWriter(GetPlatform().WritablePathForFile(fileName.str()))); + } + + string srcString = DebugPrint(srcPoint) + " " + msg + "\n"; + + file->Write(srcString.c_str(), srcString.size()); + file->Flush(); +} + +void LogMemoryInfo() +{ +#ifdef DEBUG + static unsigned long counter = 0; + const unsigned short writeLogEveryNthLocationUpdate = 3; + if (counter % writeLogEveryNthLocationUpdate == 0) + { + auto const curTime = system_clock::now(); + time_t const curCTime = system_clock::to_time_t(curTime); + tm * curTimeTM = localtime(&curCTime); + ASSERT(curTimeTM != nullptr, ()); + stringstream fileName; + fileName << " " << curTimeTM->tm_year + 1900 << "." << curTimeTM->tm_mon + 1 << "." << curTimeTM->tm_mday << " " + << curTimeTM->tm_hour << ":" << curTimeTM->tm_min << ":" << curTimeTM->tm_sec << " "; + LOG(LDEBUG, (fileName.str(), GetPlatform().GetMemoryInfo())); + } + ++counter; +#endif +} -- cgit v1.2.3