Commit 4e1f7206726b6da5108fcc564bc1b9e88214172d
1 parent
cc4727d6
Prevent conflicting log files in web vs. cli by embedding the user name
in the log file names. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@5022 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
23 additions
and
1 deletions
lib/Log.inc
| @@ -59,12 +59,30 @@ class KTLegacyLog { | @@ -59,12 +59,30 @@ class KTLegacyLog { | ||
| 59 | $this->sLogFilePrefix = $sLogFilePrefix; | 59 | $this->sLogFilePrefix = $sLogFilePrefix; |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | + function running_user() { | ||
| 63 | + if (substr(PHP_OS, 0, 3) == "WIN") { | ||
| 64 | + return null; | ||
| 65 | + } | ||
| 66 | + if (extension_loaded("posix")) { | ||
| 67 | + $uid = posix_getuid(); | ||
| 68 | + $userdetails = posix_getpwuid($uid); | ||
| 69 | + return $userdetails['name']; | ||
| 70 | + } | ||
| 71 | + if (file_exists('/usr/bin/whoami')) { | ||
| 72 | + return exec('/usr/bin/whoami'); | ||
| 73 | + } | ||
| 74 | + if (file_exists('/usr/bin/id')) { | ||
| 75 | + return exec('/usr/bin/id -nu'); | ||
| 76 | + } | ||
| 77 | + return null; | ||
| 78 | + } | ||
| 62 | 79 | ||
| 63 | /** | 80 | /** |
| 64 | * Creates the log file from the current datetime | 81 | * Creates the log file from the current datetime |
| 65 | */ | 82 | */ |
| 66 | function initialiseLogFile() { | 83 | function initialiseLogFile() { |
| 67 | global $default; | 84 | global $default; |
| 85 | + $user = $this->running_user(); | ||
| 68 | if (!file_exists($this->logDirectory)) { | 86 | if (!file_exists($this->logDirectory)) { |
| 69 | $res = @mkdir($this->logDirectory, 0755); | 87 | $res = @mkdir($this->logDirectory, 0755); |
| 70 | if ($res === false) { | 88 | if ($res === false) { |
| @@ -72,7 +90,11 @@ class KTLegacyLog { | @@ -72,7 +90,11 @@ class KTLegacyLog { | ||
| 72 | } | 90 | } |
| 73 | } | 91 | } |
| 74 | 92 | ||
| 75 | - $this->logFile = $this->logDirectory . "/" . $this->sLogFilePrefix . "-" . date("Y-m-d") . ".txt"; | 93 | + if ($user) { |
| 94 | + $this->logFile = sprintf("%s/%s-%s.%s.txt", $this->logDirectory, $this->sLogFilePrefix, date("Y-m-d"), $user); | ||
| 95 | + } else { | ||
| 96 | + $this->logFile = sprintf("%s/%s-%s.txt", $this->logDirectory, $this->sLogFilePrefix, date("Y-m-d")); | ||
| 97 | + } | ||
| 76 | if (!file_exists($this->logFile)) { | 98 | if (!file_exists($this->logFile)) { |
| 77 | $res = @touch($this->logFile); | 99 | $res = @touch($this->logFile); |
| 78 | if ($res === false) { | 100 | if ($res === false) { |