Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] Enable SMB logging for the Community Edition #30244

Merged
merged 1 commit into from
Jan 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -663,46 +663,46 @@ public function test() {
* @param int $level
* @param string $from
*/
private function log($message, $level = Util::DEBUG, $from = 'wnd') {
if (\OC::$server->getConfig()->getSystemValue('wnd.logging.enable', false) === true) {
private function log($message, $level = Util::DEBUG, $from = 'smb') {
if (\OC::$server->getConfig()->getSystemValue('smb.logging.enable', false) === true) {
Util::writeLog($from, $message, $level);
}
}

/**
* if wnd.logging.enable is set to true in the config will log a leave line
* if 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
* @param mixed $result an exception will be logged and then returned
* @return mixed
*/
private function leave($function, $result) {
if (\OC::$server->getConfig()->getSystemValue('wnd.logging.enable', false) === false) {
if (\OC::$server->getConfig()->getSystemValue('smb.logging.enable', false) === false) {
//don't bother building log strings
return $result;
} else if ($result === true) {
Util::writeLog('wnd', "leave: $function, return true", Util::DEBUG);
Util::writeLog('smb', "leave: $function, return true", Util::DEBUG);
} else if ($result === false) {
Util::writeLog('wnd', "leave: $function, return false", Util::DEBUG);
Util::writeLog('smb', "leave: $function, return false", Util::DEBUG);
} else if (is_string($result)) {
Util::writeLog('wnd', "leave: $function, return '$result'", Util::DEBUG);
Util::writeLog('smb', "leave: $function, return '$result'", Util::DEBUG);
} else if (is_resource($result)) {
Util::writeLog('wnd', "leave: $function, return resource", Util::DEBUG);
Util::writeLog('smb', "leave: $function, return resource", Util::DEBUG);
} else if ($result instanceof \Exception) {
Util::writeLog('wnd', "leave: $function, throw ".get_class($result)
Util::writeLog('smb', "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('smb', "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)
if (\OC::$server->getConfig()->getSystemValue('smb.logging.enable', false) === true) {
Util::writeLog('smb', "$function swallowing ".get_class($exception)
.' - code: '.$exception->getCode()
.' message: '.$exception->getMessage()
.' trace: '.$exception->getTraceAsString(), Util::DEBUG);
Expand Down
4 changes: 4 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1438,4 +1438,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,
);