MCPcopy Create free account
hub / github.com/defold/defold / LogInternal

Function LogInternal

engine/dlib/src/dlib/log.cpp:664–775  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

662
663
664void LogInternal(LogSeverity severity, const char* domain, const char* format, ...)
665{
666 if (severity < dmLog::g_LogLevel)
667 {
668 return;
669 }
670
671 // In release mode, if there are no custom listeners, and no log.txt file, we'll return here
672 bool is_debug_mode = dLib::IsDebugMode();
673 if (!is_debug_mode && !dmLog::g_LogFile && (dmAtomicGet32(&dmLog::g_ListenersCount) == 0))
674 {
675 return;
676 }
677
678 va_list lst;
679 va_start(lst, format);
680
681 const char* severity_str = 0;
682 switch (severity)
683 {
684 case LOG_SEVERITY_DEBUG: severity_str = "DEBUG"; break;
685 case LOG_SEVERITY_USER_DEBUG: severity_str = "DEBUG"; break;
686 case LOG_SEVERITY_INFO: severity_str = "INFO"; break;
687 case LOG_SEVERITY_WARNING: severity_str = "WARNING"; break;
688 case LOG_SEVERITY_ERROR: severity_str = "ERROR"; break;
689 case LOG_SEVERITY_FATAL: severity_str = "FATAL"; break;
690 default:
691 assert(0);
692 break;
693 }
694
695 char tmp_buf[sizeof(dmLog::LogMessage) + dmLog::MAX_STRING_SIZE];
696 dmLog::LogMessage* msg = (dmLog::LogMessage*) &tmp_buf[0];
697 char* str_buf = &tmp_buf[sizeof(dmLog::LogMessage)];
698
699 int n = 0;
700 n += dmSnPrintf(str_buf + n, dmLog::MAX_STRING_SIZE - n, "%s:%s: ", severity_str, domain);
701 if (n < dmLog::MAX_STRING_SIZE)
702 {
703 int length = vsnprintf(str_buf + n, dmLog::MAX_STRING_SIZE - n, format, lst);
704 if (length > 0)
705 {
706 n += length;
707 }
708 }
709
710 if (n < dmLog::MAX_STRING_SIZE)
711 {
712 dmSnPrintf(str_buf + n, dmLog::MAX_STRING_SIZE - n, "\n");
713 ++n; // Since dmSnPrintf returns -1 on truncation, don't add the return value to n, and instead increment n separately
714 }
715
716 if (n >= dmLog::MAX_STRING_SIZE)
717 {
718 strcpy(&str_buf[dmLog::MAX_STRING_SIZE - (strlen(dmLog::LOG_OUTPUT_TRUNCATED_MESSAGE) + 1)], dmLog::LOG_OUTPUT_TRUNCATED_MESSAGE);
719 }
720
721 str_buf[dmLog::MAX_STRING_SIZE-1] = '\0';

Callers

nothing calls this directly

Calls 12

IsDebugModeFunction · 0.85
dmAtomicGet32Function · 0.85
dmSnPrintfFunction · 0.85
MinFunction · 0.85
DoLogPlatformFunction · 0.85
IsServerInitializedFunction · 0.85
DoLogSynchronizedFunction · 0.85
FeaturesSupportedFunction · 0.85
dmStrlCpyFunction · 0.85
GetCurrentThreadFunction · 0.70
PostFunction · 0.70
assertFunction · 0.50

Tested by

no test coverage detected