Bug 1574882 - Always add .moz_log to target logging filenames, r=erahm

Differential Revision: https://phabricator.services.mozilla.com/D42487

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Honza Bambas 2019-08-23 16:51:40 +00:00
parent 5002898256
commit bf7dde4bf0
3 changed files with 31 additions and 8 deletions

View File

@ -38,6 +38,7 @@
#include "mozilla/ipc/BrowserProcessSubThread.h"
#include "mozilla/ipc/EnvironmentMap.h"
#include "mozilla/LinkedList.h"
#include "mozilla/Logging.h"
#include "mozilla/Maybe.h"
#include "mozilla/Omnijar.h"
#include "mozilla/RecordReplay.h"
@ -765,6 +766,13 @@ void BaseProcessLauncher::GetChildLogName(const char* origLogName,
buffer.Append(origLogName);
}
// Remove .moz_log extension to avoid its duplication, it will be added
// automatically by the logging backend
static NS_NAMED_LITERAL_CSTRING(kMozLogExt, MOZ_LOG_FILE_EXTENSION);
if (StringEndsWith(buffer, kMozLogExt)) {
buffer.Truncate(buffer.Length() - kMozLogExt.Length());
}
// Append child-specific postfix to name
buffer.AppendLiteral(".child-");
buffer.AppendInt(gChildCounter);

View File

@ -113,16 +113,27 @@ class LogFile {
LogFile* mNextToRelease;
};
static const char* ExpandPIDMarker(const char* aFilename,
char (&buffer)[2048]) {
static const char* ExpandLogFileName(const char* aFilename,
char (&buffer)[2048]) {
MOZ_ASSERT(aFilename);
static const char kPIDToken[] = "%PID";
static const char kMOZLOGExt[] = MOZ_LOG_FILE_EXTENSION;
bool hasMozLogExtension = StringEndsWith(nsDependentCString(aFilename),
nsLiteralCString(kMOZLOGExt));
const char* pidTokenPtr = strstr(aFilename, kPIDToken);
if (pidTokenPtr &&
SprintfLiteral(
buffer, "%.*s%s%d%s", static_cast<int>(pidTokenPtr - aFilename),
aFilename, XRE_IsParentProcess() ? "-main." : "-child.",
base::GetCurrentProcId(), pidTokenPtr + strlen(kPIDToken)) > 0) {
SprintfLiteral(buffer, "%.*s%s%d%s%s",
static_cast<int>(pidTokenPtr - aFilename), aFilename,
XRE_IsParentProcess() ? "-main." : "-child.",
base::GetCurrentProcId(), pidTokenPtr + strlen(kPIDToken),
hasMozLogExtension ? "" : kMOZLOGExt) > 0) {
return buffer;
}
if (!hasMozLogExtension &&
SprintfLiteral(buffer, "%s%s", aFilename, kMOZLOGExt) > 0) {
return buffer;
}
@ -258,7 +269,7 @@ class LogModuleManager {
if (logFile && logFile[0]) {
char buf[2048];
logFile = detail::ExpandPIDMarker(logFile, buf);
logFile = detail::ExpandLogFileName(logFile, buf);
mOutFilePath.reset(strdup(logFile));
if (mRotate > 0) {
@ -288,7 +299,7 @@ class LogModuleManager {
const char* filename = aFilename ? aFilename : "";
char buf[2048];
filename = detail::ExpandPIDMarker(filename, buf);
filename = detail::ExpandLogFileName(filename, buf);
// Can't use rotate at runtime yet.
MOZ_ASSERT(mRotate == 0,

View File

@ -30,6 +30,10 @@
# define MOZ_LOGGING_ENABLED 0
#endif
// The mandatory extension we add to log files. Note that rotate will append
// the file piece number still at the end.
#define MOZ_LOG_FILE_EXTENSION ".moz_log"
namespace mozilla {
// While not a 100% mapping to PR_LOG's numeric values, mozilla::LogLevel does