MaxLogFilesOnDisk
MaxLogFilesOnDisk
#Overview
name: MaxLogFilesOnDisk
The value of this variable can be defined or overridden in .ini config files. 1
.ini config file referencing this setting variable.
It is referenced in 4
C++ source files.
#Summary
#Usage in the C++ source code
The purpose of MaxLogFilesOnDisk is to limit the number of log files stored on disk for Unreal Engine projects. This setting variable is part of the logging system and is used to manage disk space usage by automatically deleting older log files when the specified limit is reached.
The MaxLogFilesOnDisk setting is primarily used by the Core module of Unreal Engine, specifically in the file management and maintenance systems. It is also utilized in the NetcodeUnitTest plugin for managing unit test log files.
The value of this variable is typically set in the engine configuration file (GEngineIni) under the [LogFiles] section. It is read using the GConfig->GetInt() function in multiple locations within the engine code.
This variable interacts closely with another setting called PurgeLogsDays, which specifies the age threshold for deleting old log files. Together, these two variables provide a comprehensive log file management strategy.
Developers must be aware that setting MaxLogFilesOnDisk to a value that’s too low might result in the loss of potentially important log information. Conversely, setting it too high could lead to excessive disk space usage.
Best practices for using this variable include:
- Setting an appropriate value based on the project’s needs and available disk space.
- Regularly reviewing and adjusting the value as the project evolves.
- Considering the relationship between MaxLogFilesOnDisk and PurgeLogsDays to ensure a balanced log retention policy.
- Implementing additional log archiving or backup strategies for critical log information that needs to be retained beyond the specified limits.
- Monitoring disk space usage and log file accumulation to ensure the chosen settings are effective.
By properly configuring MaxLogFilesOnDisk, developers can maintain a clean and manageable log file system while ensuring that recent and relevant log information is readily available for debugging and analysis purposes.
#Setting Variables
#References In INI files
Location: <Workspace>/Engine/Config/BaseEngine.ini:2029, section: [LogFiles]
- INI Section:
LogFiles
- Raw value:
10
- Is Array:
False
#References in C++ code
#Callsites
This variable is referenced in the following C++ source code:
#Loc: <Workspace>/Engine/Plugins/NetcodeUnitTest/NetcodeUnitTest/Source/NetcodeUnitTest/Private/UnitTestManager.cpp:162
Scope (from outer to inner):
file
function void UUnitTestManager::InitializeLogs
class class FUnitLogPurger : public IPlatformFile::FDirectoryVisitor
Source code excerpt:
{
int32 PurgeLogsDays;
int32 MaxLogFilesOnDisk;
IFileManager& FM;
TMap<FString, FDateTime> DirList;
public:
FUnitLogPurger()
: PurgeLogsDays(INDEX_NONE)
, MaxLogFilesOnDisk(INDEX_NONE)
, FM(IFileManager::Get())
{
GConfig->GetInt(TEXT("LogFiles"), TEXT("PurgeLogsDays"), PurgeLogsDays, GEngineIni);
GConfig->GetInt(TEXT("LogFiles"), TEXT("MaxLogFilesOnDisk"), MaxLogFilesOnDisk, GEngineIni);
}
void ScanAndPurge()
{
if (PurgeLogsDays != INDEX_NONE || MaxLogFilesOnDisk != INDEX_NONE)
{
FM.IterateDirectory(*FPaths::ProjectLogDir(), *this);
DirList.ValueSort(TLess<FDateTime>());
// First purge directories older than a certain date
#Loc: <Workspace>/Engine/Plugins/NetcodeUnitTest/NetcodeUnitTest/Source/NetcodeUnitTest/Private/UnitTestManager.cpp:202
Scope (from outer to inner):
file
function void UUnitTestManager::InitializeLogs
class class FUnitLogPurger : public IPlatformFile::FDirectoryVisitor
function void ScanAndPurge
Source code excerpt:
// Now see how many directories are remaining, and if over the log file limit, purge the oldest ones first
if (MaxLogFilesOnDisk != INDEX_NONE && DirList.Num() > MaxLogFilesOnDisk)
{
int32 RemoveCount = DirList.Num() - MaxLogFilesOnDisk;
for (TMap<FString, FDateTime>::TIterator It(DirList); It && RemoveCount > 0; ++It, RemoveCount--)
{
UE_LOG(LogUnitTest, Log, TEXT("Deleting old unit test log directory: %s"), *It.Key());
FM.DeleteDirectory(*It.Key(), true, true);
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Misc/FileHelper.cpp:1154
Scope (from outer to inner):
file
function void FMaintenance::DeleteOldLogs
Source code excerpt:
SCOPED_BOOT_TIMING("FMaintenance::DeleteOldLogs");
int32 PurgeLogsDays = -1; // -1 means don't delete old files
int32 MaxLogFilesOnDisk = -1; // -1 means keep all files
GConfig->GetInt(TEXT("LogFiles"), TEXT("PurgeLogsDays"), PurgeLogsDays, GEngineIni);
GConfig->GetInt(TEXT("LogFiles"), TEXT("MaxLogFilesOnDisk"), MaxLogFilesOnDisk, GEngineIni);
if (PurgeLogsDays >= 0 || MaxLogFilesOnDisk >= 0)
{
// get list of files in the log directory (grouped by log name)
TMap<FString, TArray<FString>> LogToPaths;
{
TArray<FString> Files;
IFileManager::Get().FindFiles(Files, *FString::Printf(TEXT("%s*.*"), *FPaths::ProjectLogDir()), true, false);
#Loc: <Workspace>/Engine/Source/Runtime/Core/Private/Misc/FileHelper.cpp:1214
Scope (from outer to inner):
file
function void FMaintenance::DeleteOldLogs
Source code excerpt:
// trim the number of files on disk if desired
if (MaxLogFilesOnDisk >= 0 && FilePaths.Num() > MaxLogFilesOnDisk)
{
for (int32 PathIndex = FilePaths.Num() - 1; PathIndex >= 0 && FilePaths.Num() > MaxLogFilesOnDisk; --PathIndex)
{
if (FOutputDeviceFile::IsBackupCopy(*FilePaths[PathIndex]))
{
IFileManager::Get().Delete(*FilePaths[PathIndex]);
FilePaths.RemoveAt(PathIndex);
}