include/sal/log.hxx | 3 ++- sal/osl/all/log.cxx | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-)
New commits: commit c3a9bbc2f8db978c81c2f7277ab67f56fe189d3f Author: Stephan Bergmann <[email protected]> AuthorDate: Mon Aug 4 10:21:40 2025 +0200 Commit: Stephan Bergmann <[email protected]> CommitDate: Mon Aug 4 15:01:22 2025 +0200 Allow SAL_LOG_FILE to add process ID to file name ...so that different processes (e.g., when soffice.bin gets automatically restarted) less easily overwrite each other's log files. The protocol (to mostly stay backwards compatible and only use a single file name by default) is to append a process ID iff the value of SAL_LOG_FILE ends in a hyphen, in which case the process ID is appended to that value. Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188914 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <[email protected]> (cherry picked from commit 0066897796f05bb460da0e8218b35a6d2f626746) Conflicts: sal/osl/all/log.cxx Change-Id: I516d7a286d029a16afc2f1379d5353f3f0eb5767 diff --git a/include/sal/log.hxx b/include/sal/log.hxx index a60d8dc24829..dc195a4727f0 100644 --- a/include/sal/log.hxx +++ b/include/sal/log.hxx @@ -323,7 +323,8 @@ inline char const * unwrapStream(SAL_UNUSED_PARAMETER StreamIgnore const &) { On some systems, log output can be redirected to other log sinks, notably a file provided as a system path and filename via - environment variable SAL_LOG_FILE; or to a syslog facility if + environment variable SAL_LOG_FILE (appending the process ID if that value ends in a hyphen); + or to a syslog facility if LibreOffice is suitably built, by setting environment variable SAL_LOG_SYSLOG. diff --git a/sal/osl/all/log.cxx b/sal/osl/all/log.cxx index 15cb269a1976..dc00ae454a5e 100644 --- a/sal/osl/all/log.cxx +++ b/sal/osl/all/log.cxx @@ -163,8 +163,13 @@ std::ofstream * getLogFile() { if (logFile) { + std::ostringstream pathname; + pathname << logFile; + if (pathname.str().ends_with('-')) { + pathname << OSL_DETAIL_GETPID; + } // stays until process exits - static std::ofstream file(logFile, std::ios::app | std::ios::out); + static std::ofstream file(pathname.str().c_str(), std::ios::app | std::ios::out); pResult = &file; }
