| 46 | ThreadLocal<LogContextThreadData> GlobalLogContexts; |
| 47 | |
| 48 | void LogContext::Print(LogType verbosity) |
| 49 | { |
| 50 | #if LOG_ENABLE |
| 51 | auto& stack = GlobalLogContexts.Get(); |
| 52 | if (stack.Count == 0) |
| 53 | return; |
| 54 | const StringView indentation(TEXT(" ")); |
| 55 | StringBuilder msg; |
| 56 | for (int32 index = (int32)stack.Count - 1; index >= 0; index--) |
| 57 | { |
| 58 | LogContextData& context = stack.Ptr[index]; |
| 59 | |
| 60 | // Skip duplicates |
| 61 | if (index < (int32)stack.Count - 1 && stack.Ptr[stack.Count - 1] == context) |
| 62 | continue; |
| 63 | |
| 64 | // Build call hierarchy via indentation |
| 65 | msg.Clear(); |
| 66 | for (uint32 i = index; i < stack.Count; i++) |
| 67 | msg.Append(indentation); |
| 68 | |
| 69 | if (context.ObjectID != Guid::Empty) |
| 70 | { |
| 71 | // Object reference context |
| 72 | msg.Append(TEXT(" Referenced by ")); |
| 73 | if (ScriptingObject* object = Scripting::TryFindObject(context.ObjectID)) |
| 74 | { |
| 75 | const StringAnsiView typeName(object->GetType().Fullname); |
| 76 | if (Asset* asset = ScriptingObject::Cast<Asset>(object)) |
| 77 | { |
| 78 | msg.AppendFormat(TEXT("asset '{}' ({}, {})"), asset->GetPath(), asset->GetTypeName(), context.ObjectID); |
| 79 | } |
| 80 | else if (Actor* actor = ScriptingObject::Cast<Actor>(object)) |
| 81 | { |
| 82 | msg.AppendFormat(TEXT("actor '{}' ({}, {})"), actor->GetNamePath(), String(typeName), context.ObjectID); |
| 83 | } |
| 84 | else if (Script* script = ScriptingObject::Cast<Script>(object)) |
| 85 | { |
| 86 | msg.AppendFormat(TEXT("script '{}' ({}, {})"), script->GetNamePath(), String(typeName), context.ObjectID); |
| 87 | } |
| 88 | else |
| 89 | { |
| 90 | msg.AppendFormat(TEXT("object {} ({})"), String(typeName), context.ObjectID); |
| 91 | } |
| 92 | } |
| 93 | else if (Asset* asset = Content::GetAsset(context.ObjectID)) |
| 94 | { |
| 95 | msg.AppendFormat(TEXT("asset '{}' ({}, {})"), asset->GetPath(), asset->GetTypeName(), context.ObjectID); |
| 96 | } |
| 97 | else |
| 98 | { |
| 99 | msg.AppendFormat(TEXT("object {}"), context.ObjectID); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // Print message |
| 104 | Log::Logger::Write(verbosity, msg.ToStringView()); |
| 105 | } |
nothing calls this directly
no test coverage detected