Repository: electron/electron
File: shell/common/logging.cc (C++)

Code before:
    filename = base::Environment::Create()->GetVar(kLogFileName).value_or("");
  if (!filename.empty())
    return base::FilePath::FromUTF8Unsafe(filename);

  auto log_filename = base::FilePath{FILE_PATH_LITERAL("electron_debug.log")};

  if (base::FilePath path; base::PathService::Get(chrome::DIR_LOGS, &path))
    return path.Append(log_filename);

  // error with path service, just use some default file somewhere
  return log_filename;
}

namespace {

bool HasExplicitLogFile(const base::CommandLine& command_line) {
  std::string filename = command_line.GetSwitchValueASCII(switches::kLogFile);
  if (filename.empty())
    filename = base::Environment::Create()->GetVar(kLogFileName).value_or("");
  return !filename.empty();
}

LoggingDestination DetermineLoggingDestination(
    const base::CommandLine& command_line,
    bool is_preinit,
    bool& filename_is_handle) {
  filename_is_handle = false;

  bool enable_logging = false;
  std::string logging_destination;
  if (command_line.HasSwitch(::switches::kEnableLogging)) {
    enable_logging = true;
    logging_destination =
        command_line.GetSwitchValueASCII(switches::kEnableLogging);
  } else {
    auto env = base::Environment::Create();
    if (env->HasVar(kElectronEnableLogging)) {
      enable_logging = true;
      logging_destination = env->GetVar(kElectronEnableLogging).value();
    }
  }
  if (!enable_logging)
    return LOG_NONE;

  bool also_log_to_stderr = false;
#if !defined(NDEBUG)
  if (std::optional<std::string> also_log_to_stderr_str =
          base::Environment::Create()->GetVar("ELECTRON_ALSO_LOG_TO_STDERR"))
    also_log_to_stderr = !also_log_to_stderr_str->empty();
#endif


Review comment (suggestion):
It's kind of weird to return one part via `return` and the other part by taking an outarg.

Better to return a `std::pair<LoggingDestination, bool /*filename_is_handle*/>` and remove the third argument

Code after:
    filename = base::Environment::Create()->GetVar(kLogFileName).value_or("");
  if (!filename.empty())
    return base::FilePath::FromUTF8Unsafe(filename);

  auto log_filename = base::FilePath{FILE_PATH_LITERAL("electron_debug.log")};

  if (base::FilePath path; base::PathService::Get(chrome::DIR_LOGS, &path))
    return path.Append(log_filename);

  // error with path service, just use some default file somewhere
  return log_filename;
}

namespace {

bool HasExplicitLogFile(const base::CommandLine& command_line) {
  std::string filename = command_line.GetSwitchValueASCII(switches::kLogFile);
  if (filename.empty())
    filename = base::Environment::Create()->GetVar(kLogFileName).value_or("");
  return !filename.empty();
}

std::pair<LoggingDestination, bool /* filename_is_handle */>
DetermineLoggingDestination(const base::CommandLine& command_line,
                            bool is_preinit) {
  bool enable_logging = false;
  std::string logging_destination;
  if (command_line.HasSwitch(::switches::kEnableLogging)) {
    enable_logging = true;
    logging_destination =
        command_line.GetSwitchValueASCII(switches::kEnableLogging);
  } else {
    auto env = base::Environment::Create();
    if (env->HasVar(kElectronEnableLogging)) {
      enable_logging = true;
      logging_destination = env->GetVar(kElectronEnableLogging).value();
    }
  }
  if (!enable_logging)
    return {LOG_NONE, false};

  bool also_log_to_stderr = false;
#if !defined(NDEBUG)
  if (std::optional<std::string> also_log_to_stderr_str =
          base::Environment::Create()->GetVar("ELECTRON_ALSO_LOG_TO_STDERR"))
    also_log_to_stderr = !also_log_to_stderr_str->empty();
#endif

#if BUILDFLAG(IS_WIN)
  if (logging_destination == "handle" &&
      command_line.HasSwitch(::switches::kProcessType) &&