MCPcopy Create free account
hub / github.com/FlaxEngine/FlaxEngine / Init

Method Init

Source/Engine/Core/Log.cpp:40–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38Delegate<LogType, const StringView&> Log::Logger::OnError;
39
40bool Log::Logger::Init()
41{
42 LogStartTime = Time::StartupTime;
43
44 // Skip if disabled
45 if (!IsLogEnabled())
46 return false;
47 PROFILE_MEM(Engine);
48
49 // Create logs directory (if is missing)
50#if USE_EDITOR
51 const String logsDirectory = Globals::ProjectFolder / TEXT("Logs");
52#else
53 const String logsDirectory = Globals::ProductLocalFolder / TEXT("Logs");
54#endif
55 if (FileSystem::CreateDirectory(logsDirectory))
56 {
57 return true;
58 }
59
60#if USE_EDITOR
61 // Remove old log files
62 int32 filesDeleted = 0;
63 Array<String> oldLogs;
64 if (!FileSystem::DirectoryGetFiles(oldLogs, logsDirectory, TEXT("*.txt"), DirectorySearchOption::TopDirectoryOnly))
65 {
66 // Check if there are any files to delete
67 const int32 maxLogFiles = 20;
68 int32 remaining = oldLogs.Count() - maxLogFiles + 1;
69 if (remaining > 0)
70 {
71 Sorting::QuickSort(oldLogs);
72
73 // Delete the oldest logs
74 int32 i = 0;
75 while (remaining > 0)
76 {
77 FileSystem::DeleteFile(oldLogs[i++]);
78 filesDeleted++;
79 remaining--;
80 }
81 }
82 }
83#endif
84
85 // Create log file path
86 const String filename = TEXT("Log_") + LogStartTime.ToFileNameString() + TEXT(".txt");
87 LogFilePath = logsDirectory / filename;
88
89 // Open file
90 LogFile = FileWriteStream::Open(LogFilePath);
91 if (LogFile == nullptr)
92 {
93 return true;
94 }
95 LogTotalErrorsCnt = 0;
96 LogAfterInit = true;
97#if LOG_ENABLE_WINDOWS_SINGLE_NEW_LINE_CHAR

Callers

nothing calls this directly

Calls 8

ToFileNameStringMethod · 0.80
WriteFunction · 0.70
QuickSortFunction · 0.50
FormatFunction · 0.50
CountMethod · 0.45
HasCharsMethod · 0.45
WriteBytesMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected