Skip to content

Commit 7fb9550

Browse files
author
Cong Liu
committed
added "NWJS_LOG_FILE" env
1 parent c17db5f commit 7fb9550

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/shell_main_delegate.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "content/nw/src/shell_main_delegate.h"
2222

2323
#include "base/command_line.h"
24+
#include "base/environment.h"
2425
#include "base/files/file_path.h"
2526
#include "base/file_util.h"
2627
#include "base/lazy_instance.h"
@@ -111,10 +112,26 @@ base::LazyInstance<ShellContentUtilityClient>
111112
g_chrome_content_utility_client = LAZY_INSTANCE_INITIALIZER;
112113
#endif
113114

115+
base::FilePath GetLogFileName() {
116+
std::string filename;
117+
scoped_ptr<base::Environment> env(base::Environment::Create());
118+
if (env->GetVar("NWJS_LOG_FILE", &filename) && !filename.empty())
119+
return base::FilePath::FromUTF8Unsafe(filename);
120+
121+
const base::FilePath log_filename(FILE_PATH_LITERAL("debug.log"));
122+
base::FilePath log_path;
123+
124+
if (PathService::Get(base::DIR_EXE, &log_path)) {
125+
log_path = log_path.Append(log_filename);
126+
return log_path;
127+
} else {
128+
// error with path service, just use some default file somewhere
129+
return log_filename;
130+
}
131+
}
132+
114133
void InitLogging() {
115-
base::FilePath log_filename;
116-
PathService::Get(base::DIR_EXE, &log_filename);
117-
log_filename = log_filename.AppendASCII("debug.log");
134+
base::FilePath log_filename = GetLogFileName();
118135
logging::LoggingSettings settings;
119136
if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableLogging)) {
120137
settings.logging_dest = logging::LOG_TO_ALL;

0 commit comments

Comments
 (0)