Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2015-03-05 10:21:33 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 02:40:30 +0300
commitdb109e51a06bfad840f725f2aa76e8bceba20239 (patch)
tree0a696e78440aa7d90ee8bba60bfc250254dbb141 /platform/file_logging.cpp
parentaa6d49feb3078f6abdcdb14bdab3544da0896b20 (diff)
(1) Writing log to a file on Android and iOS was implemented; (2) Memory tracking was implemented;
Diffstat (limited to 'platform/file_logging.cpp')
-rw-r--r--platform/file_logging.cpp59
1 files changed, 59 insertions, 0 deletions
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<FileWriter> 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
+}