MCPcopy Create free account
hub / github.com/axmolengine/axmol / writeLog

Function writeLog

core/base/Logging.cpp:170–233  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

168}
169
170AX_DLL void writeLog(LogItem& item, const char* tag)
171{
172#if defined(__ANDROID__)
173 int prio;
174 switch (item.level_)
175 {
176 case LogLevel::Info:
177 prio = ANDROID_LOG_INFO;
178 break;
179 case LogLevel::Warn:
180 prio = ANDROID_LOG_WARN;
181 break;
182 case LogLevel::Error:
183 prio = ANDROID_LOG_ERROR;
184 break;
185 default:
186 prio = ANDROID_LOG_DEBUG;
187 }
188 struct trim_one_eol
189 {
190 explicit trim_one_eol(std::string& v) : value(v)
191 {
192 trimed = !v.empty() && v.back() == '\n';
193 if (trimed)
194 value.back() = '\0';
195 }
196 ~trim_one_eol()
197 {
198 if (trimed)
199 value.back() = '\n';
200 }
201 operator const char* const() const { return value.c_str(); }
202 std::string& value;
203 bool trimed{false};
204 };
205 __android_log_print(prio, tag, "%s",
206 static_cast<const char*>(trim_one_eol{item.qualified_message_} + item.prefix_size_));
207#else
208 AX_UNUSED_PARAM(tag);
209# if defined(_WIN32)
210 if (::IsDebuggerPresent())
211 OutputDebugStringW(ntcvt::from_chars(item.message()).c_str());
212# endif
213
214 // write normal color text to console
215# if defined(_WIN32)
216 auto hStdout = ::GetStdHandle(item.level_ != LogLevel::Error ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);
217 if (hStdout)
218 {
219 // print to console if possible
220 // since we use win32 API, the ::fflush call doesn't required.
221 // see: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-flushfilebuffers#return-value
222 ::WriteFile(hStdout, item.qualified_message_.c_str(), static_cast<DWORD>(item.qualified_message_.size()),
223 nullptr, nullptr);
224 }
225# else
226 // Linux, Mac, iOS, etc
227 auto outfp = item.level_ != LogLevel::Error ? stdout : stderr;

Callers 1

outputLogFunction · 0.85

Calls 5

from_charsFunction · 0.85
writeFunction · 0.50
c_strMethod · 0.45
messageMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected