Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions indra/newview/llappviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#include "llconversationlog.h"
#if LL_WINDOWS
#include "lldxhardware.h"
#include <shellapi.h>
#endif
#include "lltexturestats.h"
#include "lltrace.h"
Expand Down Expand Up @@ -2298,6 +2299,12 @@ void errorHandler(const std::string& title_string, const std::string& message_st
}
}

namespace
{
std::string getStartupLogFileName();
std::string getOldLogFileName(const std::string& log_file);
}

void LLAppViewer::initLoggingAndGetLastDuration()
{
//
Expand All @@ -2323,13 +2330,10 @@ void LLAppViewer::initLoggingAndGetLastDuration()
else
{
// Remove the last ".old" log file.
std::string old_log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,
"SecondLife.old");
std::string log_file = getStartupLogFileName();
std::string old_log_file = getOldLogFileName(log_file);
LLFile::remove(old_log_file);

// Get name of the log file
std::string log_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,
"SecondLife.log");
/*
* Before touching any log files, compute the duration of the last run
* by comparing the ctime of the previous start marker file with the ctime
Expand Down Expand Up @@ -2376,7 +2380,7 @@ void LLAppViewer::initLoggingAndGetLastDuration()
// Rename current log file to ".old"
LLFile::rename(log_file, old_log_file);

// Set the log file to SecondLife.log
// Set the log file.
LLError::logToFile(log_file);
LL_INFOS() << "Started logging to " << log_file << LL_ENDL;
if (!duration_log_msg.empty())
Expand Down Expand Up @@ -2515,6 +2519,76 @@ namespace
LLStringUtil::null,
OSMB_OK);
}

std::string getStartupLogFileName()
{
if (LLControlVariable* user_log_file = gSavedSettings.getControl("UserLogFile"))
Comment thread
akleshchev marked this conversation as resolved.
{
std::string log_file = user_log_file->getValue().asString();
if (!log_file.empty())
{
return log_file;
}
}

#if LL_WINDOWS
int argc = 0;
LPWSTR* argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if (argv)
{
std::string log_file;
for (int i = 1; i < argc; ++i)
{
std::string option = ll_convert_wide_to_string(argv[i]);
if ((option == "--logfile" || option == "-logfile" || option == "/logfile") &&
i + 1 < argc)
{
log_file = ll_convert_wide_to_string(argv[i + 1]);
}
else if (option.compare(0, 10, "--logfile=") == 0)
{
log_file = option.substr(10);
}
else if (option.compare(0, 9, "-logfile=") == 0)
{
log_file = option.substr(9);
}
else if (option.compare(0, 9, "/logfile:") == 0)
{
log_file = option.substr(9);
}
}
LocalFree(argv);

if (!log_file.empty())
{
return log_file;
}
}
#endif

return gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "SecondLife.log");
}

std::string getOldLogFileName(const std::string& log_file)
{
std::string old_log_file = log_file;
size_t separator = old_log_file.find_last_of("/\\");
size_t basename_start = (separator == std::string::npos) ? 0 : separator + 1;
size_t extension = old_log_file.find_last_of('.');

if (extension != std::string::npos &&
extension > basename_start)
{
old_log_file.replace(extension, std::string::npos, ".old");
}
else
{
old_log_file += ".old";
}
Comment on lines +2575 to +2588
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getOldLogFileName() treats any filename with a '.' as having an extension, including dotfiles like .viewerlog. For such inputs extension == 0, so this will replace the whole name with .old rather than producing something like .viewerlog.old, which can cause surprising renames and collisions. Consider treating a leading '.' (after the last path separator) as “no extension” when deriving the .old name.

Copilot uses AI. Check for mistakes.

return old_log_file;
}
} // anonymous namespace

// Set a named control temporarily for this session, as when set via the command line --set option.
Expand Down
Loading