MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / print_log

Method print_log

lite/src/misc.cpp:105–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

103}
104
105void lite::print_log(LiteLogLevel level, const char* format, ...) {
106 if (!format)
107 return;
108 if (static_cast<uint32_t>(level) < static_cast<uint32_t>(get_log_level())) {
109 return;
110 }
111 using namespace std::chrono;
112
113 auto now = system_clock::now();
114 auto now_time_t = system_clock::to_time_t(now);
115
116 tm now_tm;
117
118#if _WIN32
119 localtime_s(&now_tm, &now_time_t);
120#else
121 localtime_r(&now_time_t, &now_tm);
122#endif
123
124 auto now_trunc_to_sec = system_clock::from_time_t(mktime(&now_tm));
125 auto microsec = duration_cast<microseconds>(now - now_trunc_to_sec);
126
127 char time_buffer[100];
128 snprintf(
129 time_buffer, log_detail::countof(time_buffer), "%02d:%02d:%02d.%06ld ",
130 now_tm.tm_hour, now_tm.tm_min, now_tm.tm_sec, long(microsec.count()));
131
132 const char* prefix[] = {"LITE[DBG] ", "LITE[INF] ", "LITE[WRN] ", "LITE[ERR] "};
133 std::string out;
134 out += prefix[int(level)];
135 out += time_buffer;
136
137 va_list ap;
138 va_start(ap, format);
139 auto ret = svsprintf(format, ap);
140 va_end(ap);
141 out += ret;
142
143#ifdef __ANDROID__
144 __android_log_print(ANDROID_LOG_INFO, "lite", "%s", out.c_str());
145#elif defined(__OHOS__)
146 OH_LOG_Print(LOG_APP, LOG_INFO, LOG_DOMAIN, "lite", "%s", out.c_str());
147#else
148 fprintf(stderr, "%s\n", out.c_str());
149#endif
150}
151
152// vim: syntax=cpp.doxygen foldmethod=marker foldmarker=f{{{,f}}}

Callers

nothing calls this directly

Calls 3

countofFunction · 0.85
svsprintfFunction · 0.70
countMethod · 0.45

Tested by

no test coverage detected