MCPcopy Create free account
hub / github.com/OGSR/OGSR-Engine / AddOne

Function AddOne

ogsr_engine/xrCore/log.cpp:15–88  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

13string_path logFName{};
14
15static void AddOne(std::string& split, bool first_line)
16{
17 static std::recursive_mutex logCS;
18 std::scoped_lock lock(logCS);
19
20 if (IsDebuggerPresent())
21 { //Вывод в отладчик студии
22 OutputDebugString(split.c_str());
23 OutputDebugString("\n");
24 }
25
26 if (LogCB)
27 LogCB(split.c_str()); //Вывод в логкаллбек
28
29 auto insert_time = [&] {
30 if (first_line)
31 {
32 string64 buf, curTime;
33 using namespace std::chrono;
34 const auto now = system_clock::now();
35 const auto time = system_clock::to_time_t(now);
36 const auto ms = duration_cast<milliseconds>(now.time_since_epoch()) - duration_cast<seconds>(now.time_since_epoch());
37 std::strftime(buf, sizeof(buf), "%d.%m.%y %H:%M:%S", std::localtime(&time));
38 sprintf_s(curTime, "\n[%s.%03lld] [%u] ", buf, ms.count(), _Thrd_id());
39 split = curTime + split;
40 }
41 else
42 {
43 split = "\n" + split;
44 }
45 };
46
47 if (!logstream.is_open())
48 insert_time();
49
50 static std::string last_str;
51 static int items_count;
52
53 //LogFile.push_back(split); //Вывод в консоль
54
55 if (last_str == split)
56 {
57 std::string tmp = split;
58
59 if (items_count == 0)
60 items_count = 2;
61 else
62 items_count++;
63
64 tmp += " [";
65 tmp += std::to_string(items_count);
66 tmp += "]";
67
68 LogFile.erase(LogFile.end() - 1);
69 LogFile.push_back(tmp);
70 }
71 else
72 {

Callers 1

LogFunction · 0.85

Calls 7

to_stringFunction · 0.85
c_strMethod · 0.45
countMethod · 0.45
eraseMethod · 0.45
endMethod · 0.45
push_backMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected