diff --git a/apps/files_external/lib/Lib/Storage/SMB.php b/apps/files_external/lib/Lib/Storage/SMB.php index bb1c51c42372..9c82b1ba6ff2 100644 --- a/apps/files_external/lib/Lib/Storage/SMB.php +++ b/apps/files_external/lib/Lib/Storage/SMB.php @@ -659,18 +659,36 @@ public function test() { } /** - * @param string $message - * @param int $level + * Return either 'wnd' or 'smb' if the related config values has been enabled + * Return a an existing string if set by the caller * @param string $from + * @return string */ - private function log($message, $level = Util::DEBUG, $from = 'wnd') { + private function getSmbWndLogging($from = '') { + if (!empty($from)) { + return $from; + } if (\OC::$server->getConfig()->getSystemValue('wnd.logging.enable', false) === true) { - Util::writeLog($from, $message, $level); + return 'wnd'; + } + if (\OC::$server->getConfig()->getSystemValue('smb.logging.enable', false) === true) { + return 'smb'; } } + /** - * if wnd.logging.enable is set to true in the config will log a leave line + * @param string $message + * @param int $level + * @param string $from + */ + private function log($message, $level = Util::DEBUG, $from = '') { + $newfrom = $this->getSmbWndLogging($from); + Util::writeLog($newfrom, $message, $level); + } + + /** + * if wnd/smb.logging.enable is set to true in the config will log a leave line * with the given function, the return value or the exception * * @param $function @@ -678,31 +696,33 @@ private function log($message, $level = Util::DEBUG, $from = 'wnd') { * @return mixed */ private function leave($function, $result) { - if (\OC::$server->getConfig()->getSystemValue('wnd.logging.enable', false) === false) { + $from = $this->getSmbWndLogging(); + if (empty($from)) { //don't bother building log strings return $result; } else if ($result === true) { - Util::writeLog('wnd', "leave: $function, return true", Util::DEBUG); + Util::writeLog($from, "leave: $function, return true", Util::DEBUG); } else if ($result === false) { - Util::writeLog('wnd', "leave: $function, return false", Util::DEBUG); + Util::writeLog($from, "leave: $function, return false", Util::DEBUG); } else if (is_string($result)) { - Util::writeLog('wnd', "leave: $function, return '$result'", Util::DEBUG); + Util::writeLog($from, "leave: $function, return '$result'", Util::DEBUG); } else if (is_resource($result)) { - Util::writeLog('wnd', "leave: $function, return resource", Util::DEBUG); + Util::writeLog($from, "leave: $function, return resource", Util::DEBUG); } else if ($result instanceof \Exception) { - Util::writeLog('wnd', "leave: $function, throw ".get_class($result) + Util::writeLog($from, "leave: $function, throw ".get_class($result) .' - code: '.$result->getCode() .' message: '.$result->getMessage() .' trace: '.$result->getTraceAsString(), Util::DEBUG); } else { - Util::writeLog('wnd', "leave: $function, return ".json_encode($result, true), Util::DEBUG); + Util::writeLog($from, "leave: $function, return ".json_encode($result, true), Util::DEBUG); } return $result; } private function swallow($function, \Exception $exception) { - if (\OC::$server->getConfig()->getSystemValue('wnd.logging.enable', false) === true) { - Util::writeLog('wnd', "$function swallowing ".get_class($exception) + $from = $this->getSmbWndLogging(); + if (!empty($from)) { + Util::writeLog($from, "$function swallowing ".get_class($exception) .' - code: '.$exception->getCode() .' message: '.$exception->getMessage() .' trace: '.$exception->getTraceAsString(), Util::DEBUG); diff --git a/config/config.sample.php b/config/config.sample.php index a85856a047ee..a3993bc9d039 100644 --- a/config/config.sample.php +++ b/config/config.sample.php @@ -1416,4 +1416,8 @@ */ 'files_external_allow_create_new_local' => false, +/** + * Set this property to true if you want to enable debug logging for SMB access. + */ +'smb.logging.enable' => false, );