Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit bf7dde4

Browse files
committed
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
1 parent 5002898 commit bf7dde4

3 files changed

Lines changed: 31 additions & 8 deletions

File tree

ipc/glue/GeckoChildProcessHost.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "mozilla/ipc/BrowserProcessSubThread.h"
3939
#include "mozilla/ipc/EnvironmentMap.h"
4040
#include "mozilla/LinkedList.h"
41+
#include "mozilla/Logging.h"
4142
#include "mozilla/Maybe.h"
4243
#include "mozilla/Omnijar.h"
4344
#include "mozilla/RecordReplay.h"
@@ -765,6 +766,13 @@ void BaseProcessLauncher::GetChildLogName(const char* origLogName,
765766
buffer.Append(origLogName);
766767
}
767768

769+
// Remove .moz_log extension to avoid its duplication, it will be added
770+
// automatically by the logging backend
771+
static NS_NAMED_LITERAL_CSTRING(kMozLogExt, MOZ_LOG_FILE_EXTENSION);
772+
if (StringEndsWith(buffer, kMozLogExt)) {
773+
buffer.Truncate(buffer.Length() - kMozLogExt.Length());
774+
}
775+
768776
// Append child-specific postfix to name
769777
buffer.AppendLiteral(".child-");
770778
buffer.AppendInt(gChildCounter);

xpcom/base/Logging.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,27 @@ class LogFile {
113113
LogFile* mNextToRelease;
114114
};
115115

116-
static const char* ExpandPIDMarker(const char* aFilename,
117-
char (&buffer)[2048]) {
116+
static const char* ExpandLogFileName(const char* aFilename,
117+
char (&buffer)[2048]) {
118118
MOZ_ASSERT(aFilename);
119119
static const char kPIDToken[] = "%PID";
120+
static const char kMOZLOGExt[] = MOZ_LOG_FILE_EXTENSION;
121+
122+
bool hasMozLogExtension = StringEndsWith(nsDependentCString(aFilename),
123+
nsLiteralCString(kMOZLOGExt));
124+
120125
const char* pidTokenPtr = strstr(aFilename, kPIDToken);
121126
if (pidTokenPtr &&
122-
SprintfLiteral(
123-
buffer, "%.*s%s%d%s", static_cast<int>(pidTokenPtr - aFilename),
124-
aFilename, XRE_IsParentProcess() ? "-main." : "-child.",
125-
base::GetCurrentProcId(), pidTokenPtr + strlen(kPIDToken)) > 0) {
127+
SprintfLiteral(buffer, "%.*s%s%d%s%s",
128+
static_cast<int>(pidTokenPtr - aFilename), aFilename,
129+
XRE_IsParentProcess() ? "-main." : "-child.",
130+
base::GetCurrentProcId(), pidTokenPtr + strlen(kPIDToken),
131+
hasMozLogExtension ? "" : kMOZLOGExt) > 0) {
132+
return buffer;
133+
}
134+
135+
if (!hasMozLogExtension &&
136+
SprintfLiteral(buffer, "%s%s", aFilename, kMOZLOGExt) > 0) {
126137
return buffer;
127138
}
128139

@@ -258,7 +269,7 @@ class LogModuleManager {
258269

259270
if (logFile && logFile[0]) {
260271
char buf[2048];
261-
logFile = detail::ExpandPIDMarker(logFile, buf);
272+
logFile = detail::ExpandLogFileName(logFile, buf);
262273
mOutFilePath.reset(strdup(logFile));
263274

264275
if (mRotate > 0) {
@@ -288,7 +299,7 @@ class LogModuleManager {
288299

289300
const char* filename = aFilename ? aFilename : "";
290301
char buf[2048];
291-
filename = detail::ExpandPIDMarker(filename, buf);
302+
filename = detail::ExpandLogFileName(filename, buf);
292303

293304
// Can't use rotate at runtime yet.
294305
MOZ_ASSERT(mRotate == 0,

xpcom/base/Logging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
# define MOZ_LOGGING_ENABLED 0
3131
#endif
3232

33+
// The mandatory extension we add to log files. Note that rotate will append
34+
// the file piece number still at the end.
35+
#define MOZ_LOG_FILE_EXTENSION ".moz_log"
36+
3337
namespace mozilla {
3438

3539
// While not a 100% mapping to PR_LOG's numeric values, mozilla::LogLevel does

0 commit comments

Comments
 (0)