move log constants to ILogger

Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
Arthur Schiwon 2018-04-25 15:22:28 +02:00 committed by Morris Jobke
parent 12c5db9032
commit 38a90130ce
No known key found for this signature in database
GPG Key ID: FE03C3A163FEDE68
74 changed files with 412 additions and 298 deletions

View File

@ -108,14 +108,14 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin {
*/ */
public function logException(\Exception $ex) { public function logException(\Exception $ex) {
$exceptionClass = get_class($ex); $exceptionClass = get_class($ex);
$level = \OCP\Util::FATAL; $level = ILogger::FATAL;
if (isset($this->nonFatalExceptions[$exceptionClass]) || if (isset($this->nonFatalExceptions[$exceptionClass]) ||
( (
$exceptionClass === ServiceUnavailable::class && $exceptionClass === ServiceUnavailable::class &&
$ex->getMessage() === 'System in maintenance mode.' $ex->getMessage() === 'System in maintenance mode.'
) )
) { ) {
$level = \OCP\Util::DEBUG; $level = ILogger::DEBUG;
} }
$this->logger->logException($ex, [ $this->logger->logException($ex, [

View File

@ -374,7 +374,7 @@ class KeyManager {
} catch (\Exception $e) { } catch (\Exception $e) {
$this->log->logException($e, [ $this->log->logException($e, [
'message' => 'Could not decrypt the private key from user "' . $uid . '"" during login. Assume password change on the user back-end.', 'message' => 'Could not decrypt the private key from user "' . $uid . '"" during login. Assume password change on the user back-end.',
'level' => \OCP\Util::WARN, 'level' => ILogger::WARN,
'app' => 'encryption', 'app' => 'encryption',
]); ]);
return false; return false;

View File

@ -42,6 +42,7 @@ use OCP\Federation\ICloudIdManager;
use OCP\Files\StorageInvalidException; use OCP\Files\StorageInvalidException;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use OCP\ISession; use OCP\ISession;
use OCP\IUserSession; use OCP\IUserSession;
@ -165,7 +166,7 @@ class MountPublicLinkController extends Controller {
$this->federatedShareProvider->create($share); $this->federatedShareProvider->create($share);
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::WARN, 'level' => ILogger::WARN,
'app' => 'federatedfilesharing', 'app' => 'federatedfilesharing',
]); ]);
return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST); return new JSONResponse(['message' => $e->getMessage()], Http::STATUS_BAD_REQUEST);

View File

@ -217,7 +217,7 @@ class RequestHandlerController extends OCSController {
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'Server can not add remote share.', 'message' => 'Server can not add remote share.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_sharing' 'app' => 'files_sharing'
]); ]);
throw new OCSException('internal server error, was not able to add share from ' . $remote, 500); throw new OCSException('internal server error, was not able to add share from ' . $remote, 500);

View File

@ -266,7 +266,7 @@ class FederatedShareProvider implements IShareProvider {
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'Failed to notify remote server of federated share, removing share.', 'message' => 'Failed to notify remote server of federated share, removing share.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'federatedfilesharing', 'app' => 'federatedfilesharing',
]); ]);
$failure = true; $failure = true;

View File

@ -194,14 +194,14 @@ class GetSharedSecret extends Job {
$status = -1; // There is no status code if we could not connect $status = -1; // There is no status code if we could not connect
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'Could not connect to ' . $target, 'message' => 'Could not connect to ' . $target,
'level' => \OCP\Util::INFO, 'level' => ILogger::INFO,
'app' => 'federation', 'app' => 'federation',
]); ]);
} catch (RingException $e) { } catch (RingException $e) {
$status = -1; // There is no status code if we could not connect $status = -1; // There is no status code if we could not connect
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'Could not connect to ' . $target, 'message' => 'Could not connect to ' . $target,
'level' => \OCP\Util::INFO, 'level' => ILogger::INFO,
'app' => 'federation', 'app' => 'federation',
]); ]);
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@ -72,7 +72,7 @@ class AddServerMiddleware extends Middleware {
throw $exception; throw $exception;
} }
$this->logger->logException($exception, [ $this->logger->logException($exception, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => $this->appName, 'app' => $this->appName,
]); ]);
if ($exception instanceof HintException) { if ($exception instanceof HintException) {

View File

@ -50,7 +50,7 @@ class SyncJob extends TimedJob {
if ($ex instanceof \Exception) { if ($ex instanceof \Exception) {
$this->logger->logException($ex, [ $this->logger->logException($ex, [
'message' => "Error while syncing $url.", 'message' => "Error while syncing $url.",
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'fed-sync', 'app' => 'fed-sync',
]); ]);
} }

View File

@ -244,7 +244,7 @@ class TrustedServers {
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'No Nextcloud server.', 'message' => 'No Nextcloud server.',
'level' => \OCP\Util::DEBUG, 'level' => ILogger::DEBUG,
'app' => 'federation', 'app' => 'federation',
]); ]);
return false; return false;

View File

@ -52,6 +52,7 @@ use OCP\Files\Notify\IChange;
use OCP\Files\Notify\IRenameChange; use OCP\Files\Notify\IRenameChange;
use OCP\Files\Storage\INotifyStorage; use OCP\Files\Storage\INotifyStorage;
use OCP\Files\StorageNotAvailableException; use OCP\Files\StorageNotAvailableException;
use OCP\ILogger;
use OCP\Util; use OCP\Util;
class SMB extends Common implements INotifyStorage { class SMB extends Common implements INotifyStorage {
@ -202,7 +203,7 @@ class SMB extends Common implements INotifyStorage {
$this->remove($target); $this->remove($target);
$result = $this->share->rename($absoluteSource, $absoluteTarget); $result = $this->share->rename($absoluteSource, $absoluteTarget);
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, ['level' => Util::WARN]); \OC::$server->getLogger()->logException($e, ['level' => ILogger::WARN]);
return false; return false;
} }
unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]); unset($this->statCache[$absoluteSource], $this->statCache[$absoluteTarget]);

View File

@ -45,6 +45,7 @@ use Icewind\Streams\CallbackWrapper;
use Icewind\Streams\IteratorDirectory; use Icewind\Streams\IteratorDirectory;
use OC\Files\ObjectStore\SwiftFactory; use OC\Files\ObjectStore\SwiftFactory;
use OCP\Files\StorageBadConfigException; use OCP\Files\StorageBadConfigException;
use OCP\ILogger;
use OpenStack\Common\Error\BadResponseError; use OpenStack\Common\Error\BadResponseError;
use OpenStack\ObjectStore\v1\Models\StorageObject; use OpenStack\ObjectStore\v1\Models\StorageObject;
@ -132,7 +133,7 @@ class Swift extends \OC\Files\Storage\Common {
// Expected response is "404 Not Found", so only log if it isn't // Expected response is "404 Not Found", so only log if it isn't
if ($e->getResponse()->getStatusCode() !== 404) { if ($e->getResponse()->getStatusCode() !== 404) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
} }
@ -225,7 +226,7 @@ class Swift extends \OC\Files\Storage\Common {
$this->objectCache->remove($path); $this->objectCache->remove($path);
} catch (BadResponseError $e) { } catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return false; return false;
@ -269,7 +270,7 @@ class Swift extends \OC\Files\Storage\Common {
$this->objectCache->remove($path . '/'); $this->objectCache->remove($path . '/');
} catch (BadResponseError $e) { } catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return false; return false;
@ -307,7 +308,7 @@ class Swift extends \OC\Files\Storage\Common {
return IteratorDirectory::wrap($files); return IteratorDirectory::wrap($files);
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return false; return false;
@ -331,7 +332,7 @@ class Swift extends \OC\Files\Storage\Common {
} }
} catch (BadResponseError $e) { } catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return false; return false;
@ -385,7 +386,7 @@ class Swift extends \OC\Files\Storage\Common {
} catch (BadResponseError $e) { } catch (BadResponseError $e) {
if ($e->getResponse()->getStatusCode() !== 404) { if ($e->getResponse()->getStatusCode() !== 404) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
throw $e; throw $e;
@ -409,7 +410,7 @@ class Swift extends \OC\Files\Storage\Common {
return $this->objectStore->readObject($path); return $this->objectStore->readObject($path);
} catch (BadResponseError $e) { } catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return false; return false;
@ -496,7 +497,7 @@ class Swift extends \OC\Files\Storage\Common {
$this->objectCache->remove($path2 . '/'); $this->objectCache->remove($path2 . '/');
} catch (BadResponseError $e) { } catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return false; return false;
@ -513,7 +514,7 @@ class Swift extends \OC\Files\Storage\Common {
$this->objectCache->remove($path2 . '/'); $this->objectCache->remove($path2 . '/');
} catch (BadResponseError $e) { } catch (BadResponseError $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return false; return false;

View File

@ -25,6 +25,7 @@
namespace OCA\Files_External\Service; namespace OCA\Files_External\Service;
use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Lib\StorageConfig;
use OCP\ILogger;
/** /**
* Read mount config from legacy mount.json * Read mount config from legacy mount.json
@ -190,7 +191,7 @@ abstract class LegacyStoragesService {
// don't die if a storage backend doesn't exist // don't die if a storage backend doesn't exist
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Could not load storage.', 'message' => 'Could not load storage.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
} }

View File

@ -37,6 +37,7 @@ use \OCA\Files_External\Lib\Backend\Backend;
use \OCA\Files_External\Lib\Auth\AuthMechanism; use \OCA\Files_External\Lib\Auth\AuthMechanism;
use OCP\Files\Config\IUserMountCache; use OCP\Files\Config\IUserMountCache;
use \OCP\Files\StorageNotAvailableException; use \OCP\Files\StorageNotAvailableException;
use OCP\ILogger;
/** /**
* Service class to manage external storages * Service class to manage external storages
@ -104,14 +105,14 @@ abstract class StoragesService {
// don't die if a storage backend doesn't exist // don't die if a storage backend doesn't exist
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Could not load storage.', 'message' => 'Could not load storage.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return null; return null;
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Could not load storage.', 'message' => 'Could not load storage.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
return null; return null;
@ -479,7 +480,7 @@ abstract class StoragesService {
// be instantiated or whenever $user vars where used, in which case // be instantiated or whenever $user vars where used, in which case
// the storage id could not be computed // the storage id could not be computed
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'files_external', 'app' => 'files_external',
]); ]);
} }

View File

@ -24,6 +24,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
use OCP\ILogger;
\OC_JSON::checkLoggedIn(); \OC_JSON::checkLoggedIn();
\OC_JSON::callCheck(); \OC_JSON::callCheck();
\OC::$server->getSession()->close(); \OC::$server->getSession()->close();
@ -66,7 +69,7 @@ foreach ($list as $file) {
OCA\Files_Trashbin\Trashbin::delete($filename, \OCP\User::getUser(), $timestamp); OCA\Files_Trashbin\Trashbin::delete($filename, \OCP\User::getUser(), $timestamp);
if (OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) { if (OCA\Files_Trashbin\Trashbin::file_exists($filename, $timestamp)) {
$error[] = $filename; $error[] = $filename;
\OCP\Util::writeLog('trashbin','can\'t delete ' . $filename . ' permanently.', \OCP\Util::ERROR); \OCP\Util::writeLog('trashbin','can\'t delete ' . $filename . ' permanently.', ILogger::ERROR);
} }
// only list deleted files if not deleting everything // only list deleted files if not deleting everything
else if (!$deleteAll) { else if (!$deleteAll) {

View File

@ -26,6 +26,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
use OCP\ILogger;
\OC_JSON::checkLoggedIn(); \OC_JSON::checkLoggedIn();
\OC_JSON::callCheck(); \OC_JSON::callCheck();
\OC::$server->getSession()->close(); \OC::$server->getSession()->close();
@ -72,7 +75,7 @@ foreach ($list as $file) {
if ( !OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp) ) { if ( !OCA\Files_Trashbin\Trashbin::restore($path, $filename, $timestamp) ) {
$error[] = $filename; $error[] = $filename;
\OCP\Util::writeLog('trashbin', 'can\'t restore ' . $filename, \OCP\Util::ERROR); \OCP\Util::writeLog('trashbin', 'can\'t restore ' . $filename, ILogger::ERROR);
} else { } else {
$success[$i]['filename'] = $file; $success[$i]['filename'] = $file;
$success[$i]['timestamp'] = $timestamp; $success[$i]['timestamp'] = $timestamp;

View File

@ -132,7 +132,7 @@ class Storage extends Wrapper {
// do nothing, in this case we just disable the trashbin and continue // do nothing, in this case we just disable the trashbin and continue
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Trashbin storage could not check if a file was moved out of a shared folder.', 'message' => 'Trashbin storage could not check if a file was moved out of a shared folder.',
'level' => \OCP\Util::DEBUG, 'level' => ILogger::DEBUG,
'app' => 'files_trashbin', 'app' => 'files_trashbin',
]); ]);
} }

View File

@ -294,7 +294,7 @@ class UsersController extends AUserData {
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => "Can't send new user mail to $email", 'message' => "Can't send new user mail to $email",
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'ocs_api', 'app' => 'ocs_api',
]); ]);
throw new OCSException('Unable to send the invitation mail', 109); throw new OCSException('Unable to send the invitation mail', 109);
@ -306,14 +306,14 @@ class UsersController extends AUserData {
} catch (HintException $e ) { } catch (HintException $e ) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'Failed addUser attempt with hint exception.', 'message' => 'Failed addUser attempt with hint exception.',
'level' => \OCP\Util::WARN, 'level' => ILogger::WARN,
'app' => 'ocs_api', 'app' => 'ocs_api',
]); ]);
throw new OCSException($e->getHint(), 107); throw new OCSException($e->getHint(), 107);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'Failed addUser attempt with exception.', 'message' => 'Failed addUser attempt with exception.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'ocs_api', 'app' => 'ocs_api',
]); ]);
throw new OCSException('Bad request', 101); throw new OCSException('Bad request', 101);
@ -885,7 +885,7 @@ class UsersController extends AUserData {
} catch(\Exception $e) { } catch(\Exception $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => "Can't send new user mail to $email", 'message' => "Can't send new user mail to $email",
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'settings', 'app' => 'settings',
]); ]);
throw new OCSException('Sending email failed', 102); throw new OCSException('Sending email failed', 102);

View File

@ -442,7 +442,7 @@ class UsersControllerTest extends TestCase {
->method('logException') ->method('logException')
->with($exception, [ ->with($exception, [
'message' => 'Failed addUser attempt with exception.', 'message' => 'Failed addUser attempt with exception.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'ocs_api', 'app' => 'ocs_api',
]); ]);
$loggedInUser = $this->getMockBuilder(IUser::class) $loggedInUser = $this->getMockBuilder(IUser::class)

View File

@ -353,7 +353,7 @@ class ShareByMailProvider implements IShareProvider {
} catch (HintException $hintException) { } catch (HintException $hintException) {
$this->logger->logException($hintException, [ $this->logger->logException($hintException, [
'message' => 'Failed to send share by mail.', 'message' => 'Failed to send share by mail.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'sharebymail', 'app' => 'sharebymail',
]); ]);
$this->removeShareFromTable($shareId); $this->removeShareFromTable($shareId);
@ -361,7 +361,7 @@ class ShareByMailProvider implements IShareProvider {
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'Failed to send share by mail.', 'message' => 'Failed to send share by mail.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'sharebymail', 'app' => 'sharebymail',
]); ]);
$this->removeShareFromTable($shareId); $this->removeShareFromTable($shareId);

View File

@ -52,6 +52,7 @@ use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\Mapping\AbstractMapping; use OCA\User_LDAP\Mapping\AbstractMapping;
use OC\ServerNotAvailableException; use OC\ServerNotAvailableException;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Util; use OCP\Util;
@ -186,13 +187,13 @@ class Access extends LDAPUtility implements IUserTools {
if(!$this->checkConnection()) { if(!$this->checkConnection()) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'No LDAP Connector assigned, access impossible for readAttribute.', 'No LDAP Connector assigned, access impossible for readAttribute.',
\OCP\Util::WARN); ILogger::WARN);
return false; return false;
} }
$cr = $this->connection->getConnectionResource(); $cr = $this->connection->getConnectionResource();
if(!$this->ldap->isResource($cr)) { if(!$this->ldap->isResource($cr)) {
//LDAP not available //LDAP not available
\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
return false; return false;
} }
//Cancel possibly running Paged Results operation, otherwise we run in //Cancel possibly running Paged Results operation, otherwise we run in
@ -247,7 +248,7 @@ class Access extends LDAPUtility implements IUserTools {
} }
} while($isRangeRequest); } while($isRangeRequest);
\OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Requested attribute '.$attr.' not found for '.$dn, ILogger::DEBUG);
return false; return false;
} }
@ -271,13 +272,13 @@ class Access extends LDAPUtility implements IUserTools {
if (!$this->ldap->isResource($rr)) { if (!$this->ldap->isResource($rr)) {
if ($attribute !== '') { if ($attribute !== '') {
//do not throw this message on userExists check, irritates //do not throw this message on userExists check, irritates
\OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'readAttribute failed for DN ' . $dn, ILogger::DEBUG);
} }
//in case an error occurs , e.g. object does not exist //in case an error occurs , e.g. object does not exist
return false; return false;
} }
if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) { if ($attribute === '' && ($filter === 'objectclass=*' || $this->invokeLDAPMethod('countEntries', $cr, $rr) === 1)) {
\OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'readAttribute: ' . $dn . ' found', ILogger::DEBUG);
return true; return true;
} }
$er = $this->invokeLDAPMethod('firstEntry', $cr, $rr); $er = $this->invokeLDAPMethod('firstEntry', $cr, $rr);
@ -363,7 +364,7 @@ class Access extends LDAPUtility implements IUserTools {
$cr = $this->connection->getConnectionResource(); $cr = $this->connection->getConnectionResource();
if(!$this->ldap->isResource($cr)) { if(!$this->ldap->isResource($cr)) {
//LDAP not available //LDAP not available
\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', ILogger::DEBUG);
return false; return false;
} }
try { try {
@ -566,14 +567,14 @@ class Access extends LDAPUtility implements IUserTools {
} }
} else { } else {
//If the UUID can't be detected something is foul. //If the UUID can't be detected something is foul.
\OCP\Util::writeLog('user_ldap', 'Cannot determine UUID for '.$fdn.'. Skipping.', \OCP\Util::INFO); \OCP\Util::writeLog('user_ldap', 'Cannot determine UUID for '.$fdn.'. Skipping.', ILogger::INFO);
return false; return false;
} }
if(is_null($ldapName)) { if(is_null($ldapName)) {
$ldapName = $this->readAttribute($fdn, $nameAttribute, $filter); $ldapName = $this->readAttribute($fdn, $nameAttribute, $filter);
if(!isset($ldapName[0]) && empty($ldapName[0])) { if(!isset($ldapName[0]) && empty($ldapName[0])) {
\OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', \OCP\Util::INFO); \OCP\Util::writeLog('user_ldap', 'No or empty name for '.$fdn.' with filter '.$filter.'.', ILogger::INFO);
return false; return false;
} }
$ldapName = $ldapName[0]; $ldapName = $ldapName[0];
@ -592,7 +593,7 @@ class Access extends LDAPUtility implements IUserTools {
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'app' => 'user_ldap', 'app' => 'user_ldap',
'level' => Util::WARN, 'level' => ILogger::WARN,
]); ]);
// we don't attempt to set a username here. We can go for // we don't attempt to set a username here. We can go for
// for an alternative 4 digit random number as we would append // for an alternative 4 digit random number as we would append
@ -633,7 +634,7 @@ class Access extends LDAPUtility implements IUserTools {
} }
//if everything else did not help.. //if everything else did not help..
\OCP\Util::writeLog('user_ldap', 'Could not create unique name for '.$fdn.'.', \OCP\Util::INFO); \OCP\Util::writeLog('user_ldap', 'Could not create unique name for '.$fdn.'.', ILogger::INFO);
return false; return false;
} }
@ -1031,13 +1032,13 @@ class Access extends LDAPUtility implements IUserTools {
* Maybe implement exponential backoff? * Maybe implement exponential backoff?
* This was enough to get solr indexer working which has large delays between LDAP fetches. * This was enough to get solr indexer working which has large delays between LDAP fetches.
*/ */
\OCP\Util::writeLog('user_ldap', "Connection lost on $command, attempting to reestablish.", \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', "Connection lost on $command, attempting to reestablish.", ILogger::DEBUG);
$this->connection->resetConnectionResource(); $this->connection->resetConnectionResource();
$cr = $this->connection->getConnectionResource(); $cr = $this->connection->getConnectionResource();
if(!$this->ldap->isResource($cr)) { if(!$this->ldap->isResource($cr)) {
// Seems like we didn't find any resource. // Seems like we didn't find any resource.
\OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', "Could not $command, because resource is missing.", ILogger::DEBUG);
throw $e; throw $e;
} }
@ -1069,7 +1070,7 @@ class Access extends LDAPUtility implements IUserTools {
if(!$this->ldap->isResource($cr)) { if(!$this->ldap->isResource($cr)) {
// Seems like we didn't find any resource. // Seems like we didn't find any resource.
// Return an empty array just like before. // Return an empty array just like before.
\OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Could not search, because resource is missing.', ILogger::DEBUG);
return false; return false;
} }
@ -1081,7 +1082,7 @@ class Access extends LDAPUtility implements IUserTools {
// cannot use $cr anymore, might have changed in the previous call! // cannot use $cr anymore, might have changed in the previous call!
$error = $this->ldap->errno($this->connection->getConnectionResource()); $error = $this->ldap->errno($this->connection->getConnectionResource());
if(!is_array($sr) || $error !== 0) { if(!is_array($sr) || $error !== 0) {
\OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), \OCP\Util::ERROR); \OCP\Util::writeLog('user_ldap', 'Attempt for Paging? '.print_r($pagedSearchOK, true), ILogger::ERROR);
return false; return false;
} }
@ -1152,7 +1153,7 @@ class Access extends LDAPUtility implements IUserTools {
* @throws ServerNotAvailableException * @throws ServerNotAvailableException
*/ */
private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) { private function count($filter, $base, $attr = null, $limit = null, $offset = null, $skipHandling = false) {
\OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Count filter: '.print_r($filter, true), ILogger::DEBUG);
$limitPerPage = (int)$this->connection->ldapPagingSize; $limitPerPage = (int)$this->connection->ldapPagingSize;
if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) { if(!is_null($limit) && $limit < $limitPerPage && $limit > 0) {
@ -1468,7 +1469,7 @@ class Access extends LDAPUtility implements IUserTools {
\OCP\Util::writeLog( \OCP\Util::writeLog(
'user_ldap', 'user_ldap',
'Creating advanced filter for search failed, falling back to simple method.', 'Creating advanced filter for search failed, falling back to simple method.',
\OCP\Util::INFO ILogger::INFO
); );
} }
} }
@ -1629,16 +1630,20 @@ class Access extends LDAPUtility implements IUserTools {
$value = $this->readAttribute($dn, $attribute); $value = $this->readAttribute($dn, $attribute);
if(is_array($value) && isset($value[0]) && !empty($value[0])) { if(is_array($value) && isset($value[0]) && !empty($value[0])) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
'Setting '.$attribute.' as '.$uuidAttr, 'user_ldap',
\OCP\Util::DEBUG); 'Setting '.$attribute.' as '.$uuidAttr,
ILogger::DEBUG
);
$this->connection->$uuidAttr = $attribute; $this->connection->$uuidAttr = $attribute;
return true; return true;
} }
} }
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
'Could not autodetect the UUID attribute', 'user_ldap',
\OCP\Util::ERROR); 'Could not autodetect the UUID attribute',
ILogger::ERROR
);
return false; return false;
} }
@ -1941,7 +1946,7 @@ class Access extends LDAPUtility implements IUserTools {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'initializing paged search for Filter '.$filter.' base '.print_r($bases, true) 'initializing paged search for Filter '.$filter.' base '.print_r($bases, true)
.' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset, .' attr '.print_r($attr, true). ' limit ' .$limit.' offset '.$offset,
\OCP\Util::DEBUG); ILogger::DEBUG);
//get the cookie from the search for the previous search, required by LDAP //get the cookie from the search for the previous search, required by LDAP
foreach($bases as $base) { foreach($bases as $base) {
@ -1969,10 +1974,10 @@ class Access extends LDAPUtility implements IUserTools {
if(!$pagedSearchOK) { if(!$pagedSearchOK) {
return false; return false;
} }
\OCP\Util::writeLog('user_ldap', 'Ready for a paged search', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Ready for a paged search', ILogger::DEBUG);
} else { } else {
$e = new \Exception('No paged search possible, Limit '.$limit.' Offset '.$offset); $e = new \Exception('No paged search possible, Limit '.$limit.' Offset '.$offset);
\OC::$server->getLogger()->logException($e, ['level' => Util::DEBUG]); \OC::$server->getLogger()->logException($e, ['level' => ILogger::DEBUG]);
} }
} }

View File

@ -37,6 +37,7 @@
namespace OCA\User_LDAP; namespace OCA\User_LDAP;
use OC\ServerNotAvailableException; use OC\ServerNotAvailableException;
use OCP\ILogger;
/** /**
* magic properties (incomplete) * magic properties (incomplete)
@ -192,7 +193,7 @@ class Connection extends LDAPUtility {
$this->establishConnection(); $this->establishConnection();
} }
if(is_null($this->ldapConnectionRes)) { if(is_null($this->ldapConnectionRes)) {
\OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, \OCP\Util::ERROR); \OCP\Util::writeLog('user_ldap', 'No LDAP Connection to server ' . $this->configuration->ldapHost, ILogger::ERROR);
throw new ServerNotAvailableException('Connection to LDAP server could not be established'); throw new ServerNotAvailableException('Connection to LDAP server could not be established');
} }
return $this->ldapConnectionRes; return $this->ldapConnectionRes;
@ -366,7 +367,7 @@ class Connection extends LDAPUtility {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'Illegal value for the '. 'Illegal value for the '.
$effectiveSetting.', '.'reset to '. $effectiveSetting.', '.'reset to '.
'autodetect.', \OCP\Util::INFO); 'autodetect.', ILogger::INFO);
} }
} }
@ -390,10 +391,11 @@ class Connection extends LDAPUtility {
if((stripos($this->configuration->ldapHost, 'ldaps://') === 0) if((stripos($this->configuration->ldapHost, 'ldaps://') === 0)
&& $this->configuration->ldapTLS) { && $this->configuration->ldapTLS) {
$this->configuration->ldapTLS = false; $this->configuration->ldapTLS = false;
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
'LDAPS (already using secure connection) and '. 'user_ldap',
'TLS do not work together. Switched off TLS.', 'LDAPS (already using secure connection) and TLS do not work together. Switched off TLS.',
\OCP\Util::INFO); ILogger::INFO
);
} }
} }
@ -432,9 +434,11 @@ class Connection extends LDAPUtility {
break; break;
} }
$configurationOK = false; $configurationOK = false;
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
$errorStr.'No '.$subj.' given!', 'user_ldap',
\OCP\Util::WARN); $errorStr.'No '.$subj.' given!',
ILogger::WARN
);
} }
} }
@ -445,11 +449,11 @@ class Connection extends LDAPUtility {
($agent === '' && $pwd !== '') ($agent === '' && $pwd !== '')
|| ($agent !== '' && $pwd === '') || ($agent !== '' && $pwd === '')
) { ) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
$errorStr.'either no password is given for the '. 'user_ldap',
'user agent or a password is given, but not an '. $errorStr.'either no password is given for the user ' .
'LDAP agent.', 'agent or a password is given, but not an LDAP agent.',
\OCP\Util::WARN); ILogger::WARN);
$configurationOK = false; $configurationOK = false;
} }
@ -458,18 +462,21 @@ class Connection extends LDAPUtility {
$baseGroups = $this->configuration->ldapBaseGroups; $baseGroups = $this->configuration->ldapBaseGroups;
if(empty($base) && empty($baseUsers) && empty($baseGroups)) { if(empty($base) && empty($baseUsers) && empty($baseGroups)) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
$errorStr.'Not a single Base DN given.', 'user_ldap',
\OCP\Util::WARN); $errorStr.'Not a single Base DN given.',
ILogger::WARN
);
$configurationOK = false; $configurationOK = false;
} }
if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8') if(mb_strpos($this->configuration->ldapLoginFilter, '%uid', 0, 'UTF-8')
=== false) { === false) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
$errorStr.'login filter does not contain %uid '. 'user_ldap',
'place holder.', $errorStr.'login filter does not contain %uid place holder.',
\OCP\Util::WARN); ILogger::WARN
);
$configurationOK = false; $configurationOK = false;
} }
@ -511,18 +518,21 @@ class Connection extends LDAPUtility {
return false; return false;
} }
if(!$this->ignoreValidation && !$this->configured) { if(!$this->ignoreValidation && !$this->configured) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
'Configuration is invalid, cannot connect', 'user_ldap',
\OCP\Util::WARN); 'Configuration is invalid, cannot connect',
ILogger::WARN
);
return false; return false;
} }
if(!$this->ldapConnectionRes) { if(!$this->ldapConnectionRes) {
if(!$this->ldap->areLDAPFunctionsAvailable()) { if(!$this->ldap->areLDAPFunctionsAvailable()) {
$phpLDAPinstalled = false; $phpLDAPinstalled = false;
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
'function ldap_connect is not available. Make '. 'user_ldap',
'sure that the PHP ldap module is installed.', 'function ldap_connect is not available. Make sure that the PHP ldap module is installed.',
\OCP\Util::ERROR); ILogger::ERROR
);
return false; return false;
} }
@ -530,11 +540,13 @@ class Connection extends LDAPUtility {
if(putenv('LDAPTLS_REQCERT=never')) { if(putenv('LDAPTLS_REQCERT=never')) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'Turned off SSL certificate validation successfully.', 'Turned off SSL certificate validation successfully.',
\OCP\Util::DEBUG); ILogger::DEBUG);
} else { } else {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog(
'Could not turn off SSL certificate validation.', 'user_ldap',
\OCP\Util::WARN); 'Could not turn off SSL certificate validation.',
ILogger::WARN
);
} }
} }
@ -651,7 +663,7 @@ class Connection extends LDAPUtility {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr), 'Bind failed: ' . $errno . ': ' . $this->ldap->error($cr),
\OCP\Util::WARN); ILogger::WARN);
// Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS // Set to failure mode, if LDAP error code is not LDAP_SUCCESS or LDAP_INVALID_CREDENTIALS
if($errno !== 0x00 && $errno !== 0x31) { if($errno !== 0x00 && $errno !== 0x31) {

View File

@ -43,6 +43,7 @@ namespace OCA\User_LDAP;
use OC\Cache\CappedMemoryCache; use OC\Cache\CappedMemoryCache;
use OCP\GroupInterface; use OCP\GroupInterface;
use OCP\ILogger;
class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLDAP { class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLDAP {
protected $enabled = false; protected $enabled = false;
@ -197,7 +198,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
} }
} else { } else {
\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
'of group ' . $dnGroup, \OCP\Util::DEBUG); 'of group ' . $dnGroup, ILogger::DEBUG);
} }
} }
return $dynamicMembers; return $dynamicMembers;
@ -656,7 +657,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
} }
} else { } else {
\OCP\Util::writeLog('user_ldap', 'No search filter found on member url '. \OCP\Util::writeLog('user_ldap', 'No search filter found on member url '.
'of group ' . print_r($dynamicGroup, true), \OCP\Util::DEBUG); 'of group ' . print_r($dynamicGroup, true), ILogger::DEBUG);
} }
} }
} }
@ -699,7 +700,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$result = $this->access->readAttribute($userDN, 'uid'); $result = $this->access->readAttribute($userDN, 'uid');
if ($result === false) { if ($result === false) {
\OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '. \OCP\Util::writeLog('user_ldap', 'No uid attribute found for DN ' . $userDN . ' on '.
$this->access->connection->ldapHost, \OCP\Util::DEBUG); $this->access->connection->ldapHost, ILogger::DEBUG);
} }
$uid = $result[0]; $uid = $result[0];
} else { } else {
@ -961,7 +962,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset; $cacheKey = 'getGroups-'.$search.'-'.$limit.'-'.$offset;
//Check cache before driving unnecessary searches //Check cache before driving unnecessary searches
\OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'getGroups '.$cacheKey, ILogger::DEBUG);
$ldap_groups = $this->access->connection->getFromCache($cacheKey); $ldap_groups = $this->access->connection->getFromCache($cacheKey);
if(!is_null($ldap_groups)) { if(!is_null($ldap_groups)) {
return $ldap_groups; return $ldap_groups;
@ -976,7 +977,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$this->access->connection->ldapGroupFilter, $this->access->connection->ldapGroupFilter,
$this->access->getFilterPartForGroupSearch($search) $this->access->getFilterPartForGroupSearch($search)
)); ));
\OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'getGroups Filter '.$filter, ILogger::DEBUG);
$ldap_groups = $this->access->fetchListOfGroups($filter, $ldap_groups = $this->access->fetchListOfGroups($filter,
array($this->access->connection->ldapGroupDisplayName, 'dn'), array($this->access->connection->ldapGroupDisplayName, 'dn'),
$limit, $limit,
@ -1021,7 +1022,7 @@ class Group_LDAP extends BackendUtility implements \OCP\GroupInterface, IGroupLD
$chunkLimit = min($pagingSize, $overallLimit - $chunkOffset); $chunkLimit = min($pagingSize, $overallLimit - $chunkOffset);
$ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset); $ldapGroups = $this->getGroupsChunk($search, $chunkLimit, $chunkOffset);
$nread = count($ldapGroups); $nread = count($ldapGroups);
\OCP\Util::writeLog('user_ldap', 'getGroups('.$search.'): read '.$nread.' at offset '.$chunkOffset.' (limit: '.$chunkLimit.')', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'getGroups('.$search.'): read '.$nread.' at offset '.$chunkOffset.' (limit: '.$chunkLimit.')', ILogger::DEBUG);
if ($nread) { if ($nread) {
$allGroups = array_merge($allGroups, $ldapGroups); $allGroups = array_merge($allGroups, $ldapGroups);
$chunkOffset += $nread; $chunkOffset += $nread;

View File

@ -43,6 +43,7 @@ use OCA\User_LDAP\LogWrapper;
use OCA\User_LDAP\Mapping\GroupMapping; use OCA\User_LDAP\Mapping\GroupMapping;
use OCA\User_LDAP\Mapping\UserMapping; use OCA\User_LDAP\Mapping\UserMapping;
use OCA\User_LDAP\User\Manager; use OCA\User_LDAP\User\Manager;
use OCP\ILogger;
class UpdateGroups extends \OC\BackgroundJob\TimedJob { class UpdateGroups extends \OC\BackgroundJob\TimedJob {
static private $groupsFromDB; static private $groupsFromDB;
@ -61,7 +62,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
} }
static public function updateGroups() { static public function updateGroups() {
\OCP\Util::writeLog('user_ldap', 'Run background job "updateGroups"', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Run background job "updateGroups"', ILogger::DEBUG);
$knownGroups = array_keys(self::getKnownGroups()); $knownGroups = array_keys(self::getKnownGroups());
$actualGroups = self::getGroupBE()->getGroups(); $actualGroups = self::getGroupBE()->getGroups();
@ -69,7 +70,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
if(empty($actualGroups) && empty($knownGroups)) { if(empty($actualGroups) && empty($knownGroups)) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" groups do not seem to be configured properly, aborting.', 'bgJ "updateGroups" groups do not seem to be configured properly, aborting.',
\OCP\Util::INFO); ILogger::INFO);
return; return;
} }
@ -77,7 +78,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
self::handleCreatedGroups(array_diff($actualGroups, $knownGroups)); self::handleCreatedGroups(array_diff($actualGroups, $knownGroups));
self::handleRemovedGroups(array_diff($knownGroups, $actualGroups)); self::handleRemovedGroups(array_diff($knownGroups, $actualGroups));
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" Finished.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" Finished.', ILogger::DEBUG);
} }
/** /**
@ -92,7 +93,7 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
* @param string[] $groups * @param string[] $groups
*/ */
static private function handleKnownGroups($groups) { static private function handleKnownGroups($groups) {
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" Dealing with known Groups.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" Dealing with known Groups.', ILogger::DEBUG);
$query = \OC_DB::prepare(' $query = \OC_DB::prepare('
UPDATE `*PREFIX*ldap_group_members` UPDATE `*PREFIX*ldap_group_members`
SET `owncloudusers` = ? SET `owncloudusers` = ?
@ -107,14 +108,14 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
\OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group)); \OCP\Util::emitHook('OC_User', 'post_removeFromGroup', array('uid' => $removedUser, 'gid' => $group));
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" "'.$removedUser.'" removed from "'.$group.'".', 'bgJ "updateGroups" "'.$removedUser.'" removed from "'.$group.'".',
\OCP\Util::INFO); ILogger::INFO);
$hasChanged = true; $hasChanged = true;
} }
foreach(array_diff($actualUsers, $knownUsers) as $addedUser) { foreach(array_diff($actualUsers, $knownUsers) as $addedUser) {
\OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group)); \OCP\Util::emitHook('OC_User', 'post_addToGroup', array('uid' => $addedUser, 'gid' => $group));
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" "'.$addedUser.'" added to "'.$group.'".', 'bgJ "updateGroups" "'.$addedUser.'" added to "'.$group.'".',
\OCP\Util::INFO); ILogger::INFO);
$hasChanged = true; $hasChanged = true;
} }
if($hasChanged) { if($hasChanged) {
@ -123,14 +124,14 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
} }
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" FINISHED dealing with known Groups.', 'bgJ "updateGroups" FINISHED dealing with known Groups.',
\OCP\Util::DEBUG); ILogger::DEBUG);
} }
/** /**
* @param string[] $createdGroups * @param string[] $createdGroups
*/ */
static private function handleCreatedGroups($createdGroups) { static private function handleCreatedGroups($createdGroups) {
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" dealing with created Groups.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" dealing with created Groups.', ILogger::DEBUG);
$query = \OC_DB::prepare(' $query = \OC_DB::prepare('
INSERT INSERT
INTO `*PREFIX*ldap_group_members` (`owncloudname`, `owncloudusers`) INTO `*PREFIX*ldap_group_members` (`owncloudname`, `owncloudusers`)
@ -139,20 +140,20 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
foreach($createdGroups as $createdGroup) { foreach($createdGroups as $createdGroup) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" new group "'.$createdGroup.'" found.', 'bgJ "updateGroups" new group "'.$createdGroup.'" found.',
\OCP\Util::INFO); ILogger::INFO);
$users = serialize(self::getGroupBE()->usersInGroup($createdGroup)); $users = serialize(self::getGroupBE()->usersInGroup($createdGroup));
$query->execute(array($createdGroup, $users)); $query->execute(array($createdGroup, $users));
} }
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" FINISHED dealing with created Groups.', 'bgJ "updateGroups" FINISHED dealing with created Groups.',
\OCP\Util::DEBUG); ILogger::DEBUG);
} }
/** /**
* @param string[] $removedGroups * @param string[] $removedGroups
*/ */
static private function handleRemovedGroups($removedGroups) { static private function handleRemovedGroups($removedGroups) {
\OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" dealing with removed groups.', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'bgJ "updateGroups" dealing with removed groups.', ILogger::DEBUG);
$query = \OC_DB::prepare(' $query = \OC_DB::prepare('
DELETE DELETE
FROM `*PREFIX*ldap_group_members` FROM `*PREFIX*ldap_group_members`
@ -161,12 +162,12 @@ class UpdateGroups extends \OC\BackgroundJob\TimedJob {
foreach($removedGroups as $removedGroup) { foreach($removedGroups as $removedGroup) {
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" group "'.$removedGroup.'" was removed.', 'bgJ "updateGroups" group "'.$removedGroup.'" was removed.',
\OCP\Util::INFO); ILogger::INFO);
$query->execute(array($removedGroup)); $query->execute(array($removedGroup));
} }
\OCP\Util::writeLog('user_ldap', \OCP\Util::writeLog('user_ldap',
'bgJ "updateGroups" FINISHED dealing with removed groups.', 'bgJ "updateGroups" FINISHED dealing with removed groups.',
\OCP\Util::DEBUG); ILogger::DEBUG);
} }
/** /**

View File

@ -35,6 +35,7 @@ use OCA\User_LDAP\FilesystemHelper;
use OCA\User_LDAP\LogWrapper; use OCA\User_LDAP\LogWrapper;
use OCP\IAvatarManager; use OCP\IAvatarManager;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\Image; use OCP\Image;
use OCP\IUserManager; use OCP\IUserManager;
use OCP\Util; use OCP\Util;
@ -125,10 +126,10 @@ class User {
INotificationManager $notificationManager) { INotificationManager $notificationManager) {
if ($username === null) { if ($username === null) {
$log->log("uid for '$dn' must not be null!", Util::ERROR); $log->log("uid for '$dn' must not be null!", ILogger::ERROR);
throw new \InvalidArgumentException('uid must not be null!'); throw new \InvalidArgumentException('uid must not be null!');
} else if ($username === '') { } else if ($username === '') {
$log->log("uid for '$dn' must not be an empty string", Util::ERROR); $log->log("uid for '$dn' must not be an empty string", ILogger::ERROR);
throw new \InvalidArgumentException('uid must not be an empty string!'); throw new \InvalidArgumentException('uid must not be an empty string!');
} }
@ -507,7 +508,7 @@ class User {
if ($this->verifyQuotaValue($aQuota[0])) { if ($this->verifyQuotaValue($aQuota[0])) {
$quota = $aQuota[0]; $quota = $aQuota[0];
} else { } else {
$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', \OCP\Util::WARN); $this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $aQuota[0] . ']', ILogger::WARN);
} }
} }
} }
@ -515,7 +516,7 @@ class User {
if ($this->verifyQuotaValue($valueFromLDAP)) { if ($this->verifyQuotaValue($valueFromLDAP)) {
$quota = $valueFromLDAP; $quota = $valueFromLDAP;
} else { } else {
$this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', \OCP\Util::WARN); $this->log->log('not suitable LDAP quota found for user ' . $this->uid . ': [' . $valueFromLDAP . ']', ILogger::WARN);
} }
} }
@ -532,10 +533,10 @@ class User {
if($quota !== false) { if($quota !== false) {
$targetUser->setQuota($quota); $targetUser->setQuota($quota);
} else { } else {
$this->log->log('not suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', \OCP\Util::WARN); $this->log->log('not suitable default quota found for user ' . $this->uid . ': [' . $defaultQuota . ']', ILogger::WARN);
} }
} else { } else {
$this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', \OCP\Util::ERROR); $this->log->log('trying to set a quota for user ' . $this->uid . ' but the user is missing', ILogger::ERROR);
} }
} }
@ -577,13 +578,13 @@ class User {
*/ */
private function setOwnCloudAvatar() { private function setOwnCloudAvatar() {
if(!$this->image->valid()) { if(!$this->image->valid()) {
$this->log->log('jpegPhoto data invalid for '.$this->dn, \OCP\Util::ERROR); $this->log->log('jpegPhoto data invalid for '.$this->dn, ILogger::ERROR);
return; return;
} }
//make sure it is a square and not bigger than 128x128 //make sure it is a square and not bigger than 128x128
$size = min(array($this->image->width(), $this->image->height(), 128)); $size = min(array($this->image->width(), $this->image->height(), 128));
if(!$this->image->centerCrop($size)) { if(!$this->image->centerCrop($size)) {
$this->log->log('croping image for avatar failed for '.$this->dn, \OCP\Util::ERROR); $this->log->log('croping image for avatar failed for '.$this->dn, ILogger::ERROR);
return; return;
} }
@ -597,7 +598,7 @@ class User {
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Could not set avatar for ' . $this->dn, 'message' => 'Could not set avatar for ' . $this->dn,
'level' => \OCP\Util::INFO, 'level' => ILogger::INFO,
'app' => 'user_ldap', 'app' => 'user_ldap',
]); ]);
} }

View File

@ -45,6 +45,7 @@ use OCA\User_LDAP\Exceptions\NotOnLDAP;
use OCA\User_LDAP\User\OfflineUser; use OCA\User_LDAP\User\OfflineUser;
use OCA\User_LDAP\User\User; use OCA\User_LDAP\User\User;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\IUserSession; use OCP\IUserSession;
use OCP\Notification\IManager as INotificationManager; use OCP\Notification\IManager as INotificationManager;
@ -181,7 +182,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
try { try {
$ldapRecord = $this->getLDAPUserByLoginName($uid); $ldapRecord = $this->getLDAPUserByLoginName($uid);
} catch(NotOnLDAP $e) { } catch(NotOnLDAP $e) {
if($this->ocConfig->getSystemValue('loglevel', Util::WARN) === Util::DEBUG) { if($this->ocConfig->getSystemValue('loglevel', ILogger::WARN) === ILogger::DEBUG) {
\OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']); \OC::$server->getLogger()->logException($e, ['app' => 'user_ldap']);
} }
return false; return false;
@ -193,7 +194,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
Util::writeLog('user_ldap', Util::writeLog('user_ldap',
'LDAP Login: Could not get user object for DN ' . $dn . 'LDAP Login: Could not get user object for DN ' . $dn .
'. Maybe the LDAP entry has no set display name attribute?', '. Maybe the LDAP entry has no set display name attribute?',
Util::WARN); ILogger::WARN);
return false; return false;
} }
if($user->getUsername() !== false) { if($user->getUsername() !== false) {
@ -278,14 +279,14 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
Util::writeLog('user_ldap', Util::writeLog('user_ldap',
'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter, 'getUsers: Options: search '.$search.' limit '.$limit.' offset '.$offset.' Filter: '.$filter,
Util::DEBUG); ILogger::DEBUG);
//do the search and translate results to Nextcloud names //do the search and translate results to Nextcloud names
$ldap_users = $this->access->fetchListOfUsers( $ldap_users = $this->access->fetchListOfUsers(
$filter, $filter,
$this->access->userManager->getAttributes(true), $this->access->userManager->getAttributes(true),
$limit, $offset); $limit, $offset);
$ldap_users = $this->access->nextcloudUserNames($ldap_users); $ldap_users = $this->access->nextcloudUserNames($ldap_users);
Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', Util::DEBUG); Util::writeLog('user_ldap', 'getUsers: '.count($ldap_users). ' Users found', ILogger::DEBUG);
$this->access->connection->writeToCache($cachekey, $ldap_users); $this->access->connection->writeToCache($cachekey, $ldap_users);
return $ldap_users; return $ldap_users;
@ -358,7 +359,7 @@ class User_LDAP extends BackendUtility implements \OCP\IUserBackend, \OCP\UserIn
if(is_null($user)) { if(is_null($user)) {
Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '. Util::writeLog('user_ldap', 'No DN found for '.$uid.' on '.
$this->access->connection->ldapHost, Util::DEBUG); $this->access->connection->ldapHost, ILogger::DEBUG);
$this->access->connection->writeToCache('userExists'.$uid, false); $this->access->connection->writeToCache('userExists'.$uid, false);
return false; return false;
} else if($user instanceof OfflineUser) { } else if($user instanceof OfflineUser) {

View File

@ -39,6 +39,7 @@
namespace OCA\User_LDAP; namespace OCA\User_LDAP;
use OC\ServerNotAvailableException; use OC\ServerNotAvailableException;
use OCP\ILogger;
class Wizard extends LDAPUtility { class Wizard extends LDAPUtility {
/** @var \OCP\IL10N */ /** @var \OCP\IL10N */
@ -301,7 +302,7 @@ class Wizard extends LDAPUtility {
if($writeLog) { if($writeLog) {
\OCP\Util::writeLog('user_ldap', 'The mail attribute has ' . \OCP\Util::writeLog('user_ldap', 'The mail attribute has ' .
'automatically been reset, because the original value ' . 'automatically been reset, because the original value ' .
'did not return any results.', \OCP\Util::INFO); 'did not return any results.', ILogger::INFO);
} }
} }
@ -679,7 +680,7 @@ class Wizard extends LDAPUtility {
foreach($portSettings as $setting) { foreach($portSettings as $setting) {
$p = $setting['port']; $p = $setting['port'];
$t = $setting['tls']; $t = $setting['tls'];
\OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: trying port '. $p . ', TLS '. $t, ILogger::DEBUG);
//connectAndBind may throw Exception, it needs to be catched by the //connectAndBind may throw Exception, it needs to be catched by the
//callee of this method //callee of this method
@ -702,7 +703,7 @@ class Wizard extends LDAPUtility {
'ldapTLS' => (int)$t 'ldapTLS' => (int)$t
); );
$this->configuration->setConfiguration($config); $this->configuration->setConfiguration($config);
\OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: detected Port ' . $p, ILogger::DEBUG);
$this->result->addChange('ldap_port', $p); $this->result->addChange('ldap_port', $p);
return $this->result; return $this->result;
} }
@ -848,7 +849,7 @@ class Wizard extends LDAPUtility {
$errorNo = $this->ldap->errno($cr); $errorNo = $this->ldap->errno($cr);
$errorMsg = $this->ldap->error($cr); $errorMsg = $this->ldap->error($cr);
\OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base. \OCP\Util::writeLog('user_ldap', 'Wiz: Could not search base '.$base.
' Error '.$errorNo.': '.$errorMsg, \OCP\Util::INFO); ' Error '.$errorNo.': '.$errorMsg, ILogger::INFO);
return false; return false;
} }
$entries = $this->ldap->countEntries($cr, $rr); $entries = $this->ldap->countEntries($cr, $rr);
@ -1024,7 +1025,7 @@ class Wizard extends LDAPUtility {
break; break;
} }
\OCP\Util::writeLog('user_ldap', 'Wiz: Final filter '.$filter, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: Final filter '.$filter, ILogger::DEBUG);
return $filter; return $filter;
} }
@ -1044,7 +1045,7 @@ class Wizard extends LDAPUtility {
if(!$hostInfo) { if(!$hostInfo) {
throw new \Exception(self::$l->t('Invalid Host')); throw new \Exception(self::$l->t('Invalid Host'));
} }
\OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: Attempting to connect ', ILogger::DEBUG);
$cr = $this->ldap->connect($host, $port); $cr = $this->ldap->connect($host, $port);
if(!is_resource($cr)) { if(!is_resource($cr)) {
throw new \Exception(self::$l->t('Invalid Host')); throw new \Exception(self::$l->t('Invalid Host'));
@ -1063,7 +1064,7 @@ class Wizard extends LDAPUtility {
} }
} }
\OCP\Util::writeLog('user_ldap', 'Wiz: Attemping to Bind ', \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: Attemping to Bind ', ILogger::DEBUG);
//interesting part: do the bind! //interesting part: do the bind!
$login = $this->ldap->bind($cr, $login = $this->ldap->bind($cr,
$this->configuration->ldapAgentName, $this->configuration->ldapAgentName,
@ -1078,7 +1079,7 @@ class Wizard extends LDAPUtility {
if($login === true) { if($login === true) {
$this->ldap->unbind($cr); $this->ldap->unbind($cr);
\OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, \OCP\Util::DEBUG); \OCP\Util::writeLog('user_ldap', 'Wiz: Bind successful to Port '. $port . ' TLS ' . (int)$tls, ILogger::DEBUG);
return true; return true;
} }

View File

@ -30,6 +30,7 @@
namespace OC\Core\Controller; namespace OC\Core\Controller;
use OC\Setup; use OC\Setup;
use OCP\ILogger;
class SetupController { class SetupController {
/** @var Setup */ /** @var Setup */
@ -107,7 +108,7 @@ class SetupController {
public function loadAutoConfig($post) { public function loadAutoConfig($post) {
if( file_exists($this->autoConfigFile)) { if( file_exists($this->autoConfigFile)) {
\OCP\Util::writeLog('core', 'Autoconfig file found, setting up ownCloud…', \OCP\Util::INFO); \OCP\Util::writeLog('core', 'Autoconfig file found, setting up ownCloud…', ILogger::INFO);
$AUTOCONFIG = array(); $AUTOCONFIG = array();
include $this->autoConfigFile; include $this->autoConfigFile;
$post = array_merge ($post, $AUTOCONFIG); $post = array_merge ($post, $AUTOCONFIG);

View File

@ -28,6 +28,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
use OCP\ILogger;
use Symfony\Component\EventDispatcher\GenericEvent; use Symfony\Component\EventDispatcher\GenericEvent;
if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) {
@ -208,7 +210,7 @@ if (\OCP\Util::needUpgrade()) {
$updater->upgrade(); $updater->upgrade();
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'update', 'app' => 'update',
]); ]);
$eventSource->send('failure', get_class($e) . ': ' . $e->getMessage()); $eventSource->send('failure', get_class($e) . ': ' . $e->getMessage());

View File

@ -34,6 +34,7 @@ declare(strict_types=1);
namespace OC; namespace OC;
use \OCP\AutoloadNotAllowedException; use \OCP\AutoloadNotAllowedException;
use OCP\ILogger;
class Autoloader { class Autoloader {
/** @var bool */ /** @var bool */
@ -100,7 +101,7 @@ class Autoloader {
* Remove "apps/" from inclusion path for smooth migration to multi app dir * Remove "apps/" from inclusion path for smooth migration to multi app dir
*/ */
if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) {
\OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', ILogger::DEBUG);
$paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]);
} }
} elseif (strpos($class, 'OC_') === 0) { } elseif (strpos($class, 'OC_') === 0) {

View File

@ -54,6 +54,7 @@
* *
*/ */
use OCP\ILogger;
use OCP\Share; use OCP\Share;
use OC\Encryption\HookManager; use OC\Encryption\HookManager;
use OC\Files\Filesystem; use OC\Files\Filesystem;
@ -828,7 +829,7 @@ class OC {
// so log the exception // so log the exception
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Exception when running cache gc.', 'message' => 'Exception when running cache gc.',
'level' => \OCP\Util::WARN, 'level' => ILogger::WARN,
'app' => 'core', 'app' => 'core',
]); ]);
} }

View File

@ -101,7 +101,7 @@ class AppFetcher extends Fetcher {
$releases[] = $release; $releases[] = $release;
} }
} catch (\InvalidArgumentException $e) { } catch (\InvalidArgumentException $e) {
$this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => Util::WARN]); $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::WARN]);
} }
} }
} }

View File

@ -171,10 +171,10 @@ abstract class Fetcher {
$file->putContent(json_encode($responseJson)); $file->putContent(json_encode($responseJson));
return json_decode($file->getContent(), true)['data']; return json_decode($file->getContent(), true)['data'];
} catch (ConnectException $e) { } catch (ConnectException $e) {
$this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => Util::INFO, 'message' => 'Could not connect to appstore']); $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO, 'message' => 'Could not connect to appstore']);
return []; return [];
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => Util::INFO]); $this->logger->logException($e, ['app' => 'appstoreFetcher', 'level' => ILogger::INFO]);
return []; return [];
} }
} }

View File

@ -57,6 +57,7 @@ use OCP\Files\Folder;
use OCP\Files\IAppData; use OCP\Files\IAppData;
use OCP\GlobalScale\IConfig; use OCP\GlobalScale\IConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\ILogger;
use OCP\IRequest; use OCP\IRequest;
use OCP\IServerContainer; use OCP\IServerContainer;
use OCP\IUserSession; use OCP\IUserSession;
@ -375,19 +376,19 @@ class DIContainer extends SimpleContainer implements IAppContainer {
public function log($message, $level) { public function log($message, $level) {
switch($level){ switch($level){
case 'debug': case 'debug':
$level = \OCP\Util::DEBUG; $level = ILogger::DEBUG;
break; break;
case 'info': case 'info':
$level = \OCP\Util::INFO; $level = ILogger::INFO;
break; break;
case 'warn': case 'warn':
$level = \OCP\Util::WARN; $level = ILogger::WARN;
break; break;
case 'fatal': case 'fatal':
$level = \OCP\Util::FATAL; $level = ILogger::FATAL;
break; break;
default: default:
$level = \OCP\Util::ERROR; $level = ILogger::ERROR;
break; break;
} }
\OCP\Util::writeLog($this->getAppName(), $message, $level); \OCP\Util::writeLog($this->getAppName(), $message, $level);

View File

@ -255,7 +255,7 @@ class SecurityMiddleware extends Middleware {
} }
$this->logger->logException($exception, [ $this->logger->logException($exception, [
'level' => \OCP\Util::DEBUG, 'level' => ILogger::DEBUG,
'app' => 'core', 'app' => 'core',
]); ]);
return $response; return $response;

View File

@ -31,6 +31,7 @@
namespace OC\Archive; namespace OC\Archive;
use Icewind\Streams\CallbackWrapper; use Icewind\Streams\CallbackWrapper;
use OCP\ILogger;
class ZIP extends Archive{ class ZIP extends Archive{
/** /**
@ -47,7 +48,7 @@ class ZIP extends Archive{
$this->zip=new \ZipArchive(); $this->zip=new \ZipArchive();
if($this->zip->open($source, \ZipArchive::CREATE)) { if($this->zip->open($source, \ZipArchive::CREATE)) {
}else{ }else{
\OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, \OCP\Util::WARN); \OCP\Util::writeLog('files_archive', 'Error while opening archive '.$source, ILogger::WARN);
} }
} }
/** /**

View File

@ -30,6 +30,7 @@ namespace OC\Cache;
use OC\Files\Filesystem; use OC\Files\Filesystem;
use OC\Files\View; use OC\Files\View;
use OCP\ICache; use OCP\ICache;
use OCP\ILogger;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
class File implements ICache { class File implements ICache {
@ -58,7 +59,7 @@ class File implements ICache {
$this->storage = new View('/' . $user->getUID() . '/cache'); $this->storage = new View('/' . $user->getUID() . '/cache');
return $this->storage; return $this->storage;
} else { } else {
\OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'Can\'t get cache storage, user not logged in', ILogger::ERROR);
throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in'); throw new \OC\ForbiddenException('Can\t get cache storage, user not logged in');
} }
} }

View File

@ -57,7 +57,7 @@ class CapabilitiesManager {
} catch (QueryException $e) { } catch (QueryException $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'CapabilitiesManager', 'message' => 'CapabilitiesManager',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
continue; continue;

View File

@ -26,6 +26,7 @@ namespace OC;
use OCP\IConfig; use OCP\IConfig;
use OCP\IDateTimeZone; use OCP\IDateTimeZone;
use OCP\ILogger;
use OCP\ISession; use OCP\ISession;
class DateTimeZone implements IDateTimeZone { class DateTimeZone implements IDateTimeZone {
@ -64,7 +65,7 @@ class DateTimeZone implements IDateTimeZone {
try { try {
return new \DateTimeZone($timeZone); return new \DateTimeZone($timeZone);
} catch (\Exception $e) { } catch (\Exception $e) {
\OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", \OCP\Util::DEBUG); \OCP\Util::writeLog('datetimezone', 'Failed to created DateTimeZone "' . $timeZone . "'", ILogger::DEBUG);
return new \DateTimeZone($this->getDefaultTimeZone()); return new \DateTimeZone($this->getDefaultTimeZone());
} }
} }
@ -109,7 +110,7 @@ class DateTimeZone implements IDateTimeZone {
} }
// No timezone found, fallback to UTC // No timezone found, fallback to UTC
\OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", \OCP\Util::DEBUG); \OCP\Util::writeLog('datetimezone', 'Failed to find DateTimeZone for offset "' . $offset . "'", ILogger::DEBUG);
return new \DateTimeZone($this->getDefaultTimeZone()); return new \DateTimeZone($this->getDefaultTimeZone());
} }
} }

View File

@ -38,6 +38,7 @@ use OC\Files\Filesystem;
use OC\Hooks\BasicEmitter; use OC\Hooks\BasicEmitter;
use OCP\Files\Cache\IScanner; use OCP\Files\Cache\IScanner;
use OCP\Files\ForbiddenException; use OCP\Files\ForbiddenException;
use OCP\ILogger;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
/** /**
@ -110,7 +111,7 @@ class Scanner extends BasicEmitter implements IScanner {
protected function getData($path) { protected function getData($path) {
$data = $this->storage->getMetaData($path); $data = $this->storage->getMetaData($path);
if (is_null($data)) { if (is_null($data)) {
\OCP\Util::writeLog(Scanner::class, "!!! Path '$path' is not accessible or present !!!", \OCP\Util::DEBUG); \OCP\Util::writeLog(Scanner::class, "!!! Path '$path' is not accessible or present !!!", ILogger::DEBUG);
} }
return $data; return $data;
} }
@ -454,7 +455,7 @@ class Scanner extends BasicEmitter implements IScanner {
} }
\OC::$server->getLogger()->logException($ex, [ \OC::$server->getLogger()->logException($ex, [
'message' => 'Exception while scanning file "' . $child . '"', 'message' => 'Exception while scanning file "' . $child . '"',
'level' => \OCP\Util::DEBUG, 'level' => ILogger::DEBUG,
'app' => 'core', 'app' => 'core',
]); ]);
$exceptionOccurred = true; $exceptionOccurred = true;

View File

@ -65,6 +65,7 @@ use OC\Files\Storage\StorageFactory;
use OC\Lockdown\Filesystem\NullStorage; use OC\Lockdown\Filesystem\NullStorage;
use OCP\Files\Config\IMountProvider; use OCP\Files\Config\IMountProvider;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\ILogger;
use OCP\IUserManager; use OCP\IUserManager;
class Filesystem { class Filesystem {
@ -408,7 +409,7 @@ class Filesystem {
$userObject = $userManager->get($user); $userObject = $userManager->get($user);
if (is_null($userObject)) { if (is_null($userObject)) {
\OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, \OCP\Util::ERROR); \OCP\Util::writeLog('files', ' Backends provided no user object for ' . $user, ILogger::ERROR);
// reset flag, this will make it possible to rethrow the exception if called again // reset flag, this will make it possible to rethrow the exception if called again
unset(self::$usersSetup[$user]); unset(self::$usersSetup[$user]);
throw new \OC\User\NoUserException('Backends provided no user object for ' . $user); throw new \OC\User\NoUserException('Backends provided no user object for ' . $user);
@ -418,7 +419,7 @@ class Filesystem {
// workaround in case of different casings // workaround in case of different casings
if ($user !== $realUid) { if ($user !== $realUid) {
$stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50)); $stack = json_encode(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 50));
\OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $realUid . '" got "' . $user . '". Stack: ' . $stack, \OCP\Util::WARN); \OCP\Util::writeLog('files', 'initMountPoints() called with wrong user casing. This could be a bug. Expected: "' . $realUid . '" got "' . $user . '". Stack: ' . $stack, ILogger::WARN);
$user = $realUid; $user = $realUid;
// again with the correct casing // again with the correct casing

View File

@ -33,6 +33,7 @@ use \OC\Files\Filesystem;
use OC\Files\Storage\StorageFactory; use OC\Files\Storage\StorageFactory;
use OC\Files\Storage\Storage; use OC\Files\Storage\Storage;
use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IMountPoint;
use OCP\ILogger;
class MountPoint implements IMountPoint { class MountPoint implements IMountPoint {
/** /**
@ -152,12 +153,12 @@ class MountPoint implements IMountPoint {
// the root storage could not be initialized, show the user! // the root storage could not be initialized, show the user!
throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception); throw new \Exception('The root storage could not be initialized. Please contact your local administrator.', $exception->getCode(), $exception);
} else { } else {
\OC::$server->getLogger()->logException($exception, ['level' => \OCP\Util::ERROR]); \OC::$server->getLogger()->logException($exception, ['level' => ILogger::ERROR]);
} }
return; return;
} }
} else { } else {
\OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'storage backend ' . $this->class . ' not found', ILogger::ERROR);
$this->invalidStorage = true; $this->invalidStorage = true;
return; return;
} }

View File

@ -26,6 +26,7 @@ namespace OC\Files\Mount;
use OCP\Files\Config\IHomeMountProvider; use OCP\Files\Config\IHomeMountProvider;
use OCP\Files\Storage\IStorageFactory; use OCP\Files\Storage\IStorageFactory;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
/** /**
@ -79,7 +80,7 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
// sanity checks // sanity checks
if (empty($config['class'])) { if (empty($config['class'])) {
\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
} }
if (!isset($config['arguments'])) { if (!isset($config['arguments'])) {
$config['arguments'] = []; $config['arguments'] = [];
@ -104,7 +105,7 @@ class ObjectHomeMountProvider implements IHomeMountProvider {
// sanity checks // sanity checks
if (empty($config['class'])) { if (empty($config['class'])) {
\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
} }
if (!isset($config['arguments'])) { if (!isset($config['arguments'])) {
$config['arguments'] = []; $config['arguments'] = [];

View File

@ -27,6 +27,7 @@ namespace OC\Files\ObjectStore;
use Aws\ClientResolver; use Aws\ClientResolver;
use Aws\S3\Exception\S3Exception; use Aws\S3\Exception\S3Exception;
use Aws\S3\S3Client; use Aws\S3\S3Client;
use OCP\ILogger;
trait S3ConnectionTrait { trait S3ConnectionTrait {
/** @var array */ /** @var array */
@ -113,7 +114,7 @@ trait S3ConnectionTrait {
} catch (S3Exception $e) { } catch (S3Exception $e) {
$logger->logException($e, [ $logger->logException($e, [
'message' => 'Invalid remote storage.', 'message' => 'Invalid remote storage.',
'level' => \OCP\Util::DEBUG, 'level' => ILogger::DEBUG,
'app' => 'objectstore', 'app' => 'objectstore',
]); ]);
throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage()); throw new \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());

View File

@ -54,6 +54,7 @@ use OCP\Files\InvalidPathException;
use OCP\Files\ReservedWordException; use OCP\Files\ReservedWordException;
use OCP\Files\Storage\ILockingStorage; use OCP\Files\Storage\ILockingStorage;
use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorage;
use OCP\ILogger;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException; use OCP\Lock\LockedException;
@ -453,7 +454,7 @@ abstract class Common implements Storage, ILockingStorage {
return false; return false;
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->info("External storage not available: " . $e->getMessage()); \OC::$server->getLogger()->info("External storage not available: " . $e->getMessage());
\OC::$server->getLogger()->logException($e, ['level' => \OCP\Util::DEBUG]); \OC::$server->getLogger()->logException($e, ['level' => ILogger::DEBUG]);
return false; return false;
} }
} }

View File

@ -35,6 +35,7 @@ namespace OC\Files\Storage;
use Exception; use Exception;
use GuzzleHttp\Exception\RequestException; use GuzzleHttp\Exception\RequestException;
use OCP\ILogger;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Icewind\Streams\CallbackWrapper; use Icewind\Streams\CallbackWrapper;
use OC\Files\Filesystem; use OC\Files\Filesystem;
@ -357,7 +358,7 @@ class DAV extends Common {
if ($response->getStatusCode() === Http::STATUS_LOCKED) { if ($response->getStatusCode() === Http::STATUS_LOCKED) {
throw new \OCP\Lock\LockedException($path); throw new \OCP\Lock\LockedException($path);
} else { } else {
Util::writeLog("webdav client", 'Guzzle get returned status code ' . $response->getStatusCode(), Util::ERROR); Util::writeLog("webdav client", 'Guzzle get returned status code ' . $response->getStatusCode(), ILogger::ERROR);
} }
} }

View File

@ -42,6 +42,7 @@ namespace OC\Files\Storage;
use OC\Files\Storage\Wrapper\Jail; use OC\Files\Storage\Wrapper\Jail;
use OCP\Files\ForbiddenException; use OCP\Files\ForbiddenException;
use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorage;
use OCP\ILogger;
/** /**
* for local filestore, we only have to map the paths * for local filestore, we only have to map the paths
@ -235,17 +236,17 @@ class Local extends \OC\Files\Storage\Common {
$dstParent = dirname($path2); $dstParent = dirname($path2);
if (!$this->isUpdatable($srcParent)) { if (!$this->isUpdatable($srcParent)) {
\OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'unable to rename, source directory is not writable : ' . $srcParent, ILogger::ERROR);
return false; return false;
} }
if (!$this->isUpdatable($dstParent)) { if (!$this->isUpdatable($dstParent)) {
\OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'unable to rename, destination directory is not writable : ' . $dstParent, ILogger::ERROR);
return false; return false;
} }
if (!$this->file_exists($path1)) { if (!$this->file_exists($path1)) {
\OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'unable to rename, file does not exists : ' . $path1, ILogger::ERROR);
return false; return false;
} }
@ -382,7 +383,7 @@ class Local extends \OC\Files\Storage\Common {
return $fullPath; return $fullPath;
} }
\OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", \OCP\Util::ERROR); \OCP\Util::writeLog('core', "Following symlinks is not allowed ('$fullPath' -> '$realPath' not inside '{$this->realDataDir}')", ILogger::ERROR);
throw new ForbiddenException('Following symlinks is not allowed', false); throw new ForbiddenException('Following symlinks is not allowed', false);
} }

View File

@ -441,7 +441,7 @@ class Encryption extends Wrapper {
} catch (ModuleDoesNotExistsException $e) { } catch (ModuleDoesNotExistsException $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'message' => 'Encryption module "' . $encryptionModuleId . '" not found, file will be stored unencrypted', 'message' => 'Encryption module "' . $encryptionModuleId . '" not found, file will be stored unencrypted',
'level' => \OCP\Util::WARN, 'level' => ILogger::WARN,
'app' => 'core', 'app' => 'core',
]); ]);
} }

View File

@ -59,6 +59,7 @@ use OCP\Files\InvalidPathException;
use OCP\Files\Mount\IMountPoint; use OCP\Files\Mount\IMountPoint;
use OCP\Files\NotFoundException; use OCP\Files\NotFoundException;
use OCP\Files\ReservedWordException; use OCP\Files\ReservedWordException;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
use OCP\Lock\LockedException; use OCP\Lock\LockedException;
@ -975,7 +976,7 @@ class View {
$hooks[] = 'write'; $hooks[] = 'write';
break; break;
default: default:
\OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'invalid mode (' . $mode . ') for ' . $path, ILogger::ERROR);
} }
if ($mode !== 'r' && $mode !== 'w') { if ($mode !== 'r' && $mode !== 'w') {
@ -1463,7 +1464,7 @@ class View {
// sometimes when the storage is not available it can be any exception // sometimes when the storage is not available it can be any exception
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Exception while scanning storage "' . $subStorage->getId() . '"', 'message' => 'Exception while scanning storage "' . $subStorage->getId() . '"',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'lib', 'app' => 'lib',
]); ]);
continue; continue;
@ -1752,7 +1753,7 @@ class View {
if (!$targetStorage->instanceOfStorage('\OCP\Files\IHomeStorage')) { if (!$targetStorage->instanceOfStorage('\OCP\Files\IHomeStorage')) {
\OCP\Util::writeLog('files', \OCP\Util::writeLog('files',
'It is not allowed to move one mount point into another one', 'It is not allowed to move one mount point into another one',
\OCP\Util::DEBUG); ILogger::DEBUG);
return false; return false;
} }
@ -1775,7 +1776,7 @@ class View {
if (count($shares) > 0) { if (count($shares) > 0) {
\OCP\Util::writeLog('files', \OCP\Util::writeLog('files',
'It is not allowed to move one mount point into a shared folder', 'It is not allowed to move one mount point into a shared folder',
\OCP\Util::DEBUG); ILogger::DEBUG);
return false; return false;
} }

View File

@ -175,7 +175,7 @@ class Installer {
$this->downloadApp($appId); $this->downloadApp($appId);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->logger->logException($e, [ $this->logger->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;
@ -460,7 +460,7 @@ class Installer {
OC_Helper::rmdirr($appDir); OC_Helper::rmdirr($appDir);
return true; return true;
}else{ }else{
\OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', ILogger::ERROR);
return false; return false;
} }

View File

@ -107,7 +107,7 @@ class Log implements ILogger {
* @return void * @return void
*/ */
public function emergency(string $message, array $context = []) { public function emergency(string $message, array $context = []) {
$this->log(Util::FATAL, $message, $context); $this->log(ILogger::FATAL, $message, $context);
} }
/** /**
@ -121,7 +121,7 @@ class Log implements ILogger {
* @return void * @return void
*/ */
public function alert(string $message, array $context = []) { public function alert(string $message, array $context = []) {
$this->log(Util::ERROR, $message, $context); $this->log(ILogger::ERROR, $message, $context);
} }
/** /**
@ -134,7 +134,7 @@ class Log implements ILogger {
* @return void * @return void
*/ */
public function critical(string $message, array $context = []) { public function critical(string $message, array $context = []) {
$this->log(Util::ERROR, $message, $context); $this->log(ILogger::ERROR, $message, $context);
} }
/** /**
@ -146,7 +146,7 @@ class Log implements ILogger {
* @return void * @return void
*/ */
public function error(string $message, array $context = []) { public function error(string $message, array $context = []) {
$this->log(Util::ERROR, $message, $context); $this->log(ILogger::ERROR, $message, $context);
} }
/** /**
@ -160,7 +160,7 @@ class Log implements ILogger {
* @return void * @return void
*/ */
public function warning(string $message, array $context = []) { public function warning(string $message, array $context = []) {
$this->log(Util::WARN, $message, $context); $this->log(ILogger::WARN, $message, $context);
} }
/** /**
@ -171,7 +171,7 @@ class Log implements ILogger {
* @return void * @return void
*/ */
public function notice(string $message, array $context = []) { public function notice(string $message, array $context = []) {
$this->log(Util::INFO, $message, $context); $this->log(ILogger::INFO, $message, $context);
} }
/** /**
@ -184,7 +184,7 @@ class Log implements ILogger {
* @return void * @return void
*/ */
public function info(string $message, array $context = []) { public function info(string $message, array $context = []) {
$this->log(Util::INFO, $message, $context); $this->log(ILogger::INFO, $message, $context);
} }
/** /**
@ -195,7 +195,7 @@ class Log implements ILogger {
* @return void * @return void
*/ */
public function debug(string $message, array $context = []) { public function debug(string $message, array $context = []) {
$this->log(Util::DEBUG, $message, $context); $this->log(ILogger::DEBUG, $message, $context);
} }
@ -260,7 +260,7 @@ class Log implements ILogger {
// if log condition is satisfied change the required log level to DEBUG // if log condition is satisfied change the required log level to DEBUG
if ($this->logConditionSatisfied) { if ($this->logConditionSatisfied) {
return Util::DEBUG; return ILogger::DEBUG;
} }
if (isset($context['app'])) { if (isset($context['app'])) {
@ -274,11 +274,11 @@ class Log implements ILogger {
if (!empty($logCondition) if (!empty($logCondition)
&& isset($logCondition['apps']) && isset($logCondition['apps'])
&& in_array($app, $logCondition['apps'], true)) { && in_array($app, $logCondition['apps'], true)) {
return Util::DEBUG; return ILogger::DEBUG;
} }
} }
return min($this->config->getValue('loglevel', Util::WARN), Util::FATAL); return min($this->config->getValue('loglevel', ILogger::WARN), ILogger::FATAL);
} }
/** /**
@ -291,7 +291,7 @@ class Log implements ILogger {
*/ */
public function logException(\Throwable $exception, array $context = []) { public function logException(\Throwable $exception, array $context = []) {
$app = $context['app'] ?? 'no app in context'; $app = $context['app'] ?? 'no app in context';
$level = $context['level'] ?? Util::ERROR; $level = $context['level'] ?? ILogger::ERROR;
$serializer = new ExceptionSerializer(); $serializer = new ExceptionSerializer();
$data = $serializer->serializeException($exception); $data = $serializer->serializeException($exception);

View File

@ -37,6 +37,8 @@
namespace OC\Log; namespace OC\Log;
use OCP\ILogger;
/** /**
* logging utilities * logging utilities
* *
@ -159,7 +161,7 @@ class File {
*/ */
public static function getEntries($limit=50, $offset=0) { public static function getEntries($limit=50, $offset=0) {
self::init(); self::init();
$minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", \OCP\Util::WARN); $minLevel = \OC::$server->getSystemConfig()->getValue("loglevel", ILogger::WARN);
$entries = array(); $entries = array();
$handle = @fopen(self::$logFile, 'rb'); $handle = @fopen(self::$logFile, 'rb');
if ($handle) { if ($handle) {

View File

@ -24,6 +24,7 @@
*/ */
namespace OC\Log; namespace OC\Log;
use OCP\ILogger;
/** /**
* This rotates the current logfile to a new name, this way the total log usage * This rotates the current logfile to a new name, this way the total log usage
@ -49,6 +50,6 @@ class Rotate extends \OC\BackgroundJob\Job {
$rotatedLogfile = $logfile.'.1'; $rotatedLogfile = $logfile.'.1';
rename($logfile, $rotatedLogfile); rename($logfile, $rotatedLogfile);
$msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"'; $msg = 'Log file "'.$logfile.'" was over '.$this->max_log_size.' bytes, moved to "'.$rotatedLogfile.'"';
\OCP\Util::writeLog(Rotate::class, $msg, \OCP\Util::WARN); \OCP\Util::writeLog(Rotate::class, $msg, ILogger::WARN);
} }
} }

View File

@ -25,13 +25,15 @@
namespace OC\Log; namespace OC\Log;
use OCP\ILogger;
class Syslog { class Syslog {
static protected $levels = array( static protected $levels = array(
\OCP\Util::DEBUG => LOG_DEBUG, ILogger::DEBUG => LOG_DEBUG,
\OCP\Util::INFO => LOG_INFO, ILogger::INFO => LOG_INFO,
\OCP\Util::WARN => LOG_WARNING, ILogger::WARN => LOG_WARNING,
\OCP\Util::ERROR => LOG_ERR, ILogger::ERROR => LOG_ERR,
\OCP\Util::FATAL => LOG_CRIT, ILogger::FATAL => LOG_CRIT,
); );
/** /**

View File

@ -27,6 +27,8 @@
namespace OC; namespace OC;
use OCP\ILogger;
class NaturalSort { class NaturalSort {
private static $instance; private static $instance;
private $collator; private $collator;
@ -41,7 +43,7 @@ class NaturalSort {
// or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator // or inject an instance of \OC\NaturalSort_DefaultCollator to force using Owncloud's default collator
if (isset($injectedCollator)) { if (isset($injectedCollator)) {
$this->collator = $injectedCollator; $this->collator = $injectedCollator;
\OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), \OCP\Util::DEBUG); \OCP\Util::writeLog('core', 'forced use of '.get_class($injectedCollator), ILogger::DEBUG);
} }
} }

View File

@ -26,6 +26,7 @@
namespace OC\Preview; namespace OC\Preview;
use Imagick; use Imagick;
use OCP\ILogger;
/** /**
* Creates a PNG preview using ImageMagick via the PECL extension * Creates a PNG preview using ImageMagick via the PECL extension
@ -50,7 +51,7 @@ abstract class Bitmap extends Provider {
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => 'Imagick says:', 'message' => 'Imagick says:',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;

View File

@ -25,6 +25,8 @@
*/ */
namespace OC\Preview; namespace OC\Preview;
use OCP\ILogger;
abstract class Office extends Provider { abstract class Office extends Provider {
private $cmd; private $cmd;
@ -60,7 +62,7 @@ abstract class Office extends Provider {
unlink($absPath); unlink($absPath);
unlink($pdfPreview); unlink($pdfPreview);
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;

View File

@ -24,6 +24,8 @@
*/ */
namespace OC\Preview; namespace OC\Preview;
use OCP\ILogger;
class SVG extends Provider { class SVG extends Provider {
/** /**
* {@inheritDoc} * {@inheritDoc}
@ -54,7 +56,7 @@ class SVG extends Provider {
$svg->setImageFormat('png32'); $svg->setImageFormat('png32');
} catch (\Exception $e) { } catch (\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;

View File

@ -150,12 +150,12 @@ class Manager implements IManager {
/** @var ISection $section */ /** @var ISection $section */
$section = \OC::$server->query($class); $section = \OC::$server->query($class);
} catch (QueryException $e) { } catch (QueryException $e) {
$this->log->logException($e, ['level' => Util::INFO]); $this->log->logException($e, ['level' => ILogger::INFO]);
continue; continue;
} }
if (!$section instanceof ISection) { if (!$section instanceof ISection) {
$this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => Util::INFO]); $this->log->logException(new \InvalidArgumentException('Invalid settings section registered'), ['level' => ILogger::INFO]);
continue; continue;
} }
@ -200,12 +200,12 @@ class Manager implements IManager {
/** @var ISettings $setting */ /** @var ISettings $setting */
$setting = \OC::$server->query($class); $setting = \OC::$server->query($class);
} catch (QueryException $e) { } catch (QueryException $e) {
$this->log->logException($e, ['level' => Util::INFO]); $this->log->logException($e, ['level' => ILogger::INFO]);
continue; continue;
} }
if (!$setting instanceof ISettings) { if (!$setting instanceof ISettings) {
$this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => Util::INFO]); $this->log->logException(new \InvalidArgumentException('Invalid settings setting registered'), ['level' => ILogger::INFO]);
continue; continue;
} }

View File

@ -31,6 +31,7 @@ namespace OC\Setup;
use OC\DB\MySqlTools; use OC\DB\MySqlTools;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\ILogger;
class MySQL extends AbstractDatabase { class MySQL extends AbstractDatabase {
public $dbprettyname = 'MySQL/MariaDB'; public $dbprettyname = 'MySQL/MariaDB';
@ -70,7 +71,7 @@ class MySQL extends AbstractDatabase {
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex, [ $this->logger->logException($ex, [
'message' => 'Database creation failed.', 'message' => 'Database creation failed.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'mysql.setup', 'app' => 'mysql.setup',
]); ]);
return; return;
@ -83,7 +84,7 @@ class MySQL extends AbstractDatabase {
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex, [ $this->logger->logException($ex, [
'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.', 'message' => 'Could not automatically grant privileges, this can be ignored if database user already had privileges.',
'level' => \OCP\Util::DEBUG, 'level' => ILogger::DEBUG,
'app' => 'mysql.setup', 'app' => 'mysql.setup',
]); ]);
} }
@ -107,7 +108,7 @@ class MySQL extends AbstractDatabase {
catch (\Exception $ex){ catch (\Exception $ex){
$this->logger->logException($ex, [ $this->logger->logException($ex, [
'message' => 'Database user creation failed.', 'message' => 'Database user creation failed.',
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'mysql.setup', 'app' => 'mysql.setup',
]); ]);
} }
@ -162,7 +163,7 @@ class MySQL extends AbstractDatabase {
} catch (\Exception $ex) { } catch (\Exception $ex) {
$this->logger->logException($ex, [ $this->logger->logException($ex, [
'message' => 'Can not create a new MySQL user, will continue with the provided user.', 'message' => 'Can not create a new MySQL user, will continue with the provided user.',
'level' => \OCP\Util::INFO, 'level' => ILogger::INFO,
'app' => 'mysql.setup', 'app' => 'mysql.setup',
]); ]);
} }

View File

@ -41,6 +41,7 @@ namespace OC\Share;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IConfig; use OCP\IConfig;
use OCP\ILogger;
use OCP\Util; use OCP\Util;
/** /**
@ -92,7 +93,7 @@ class Share extends Constants {
\OCP\Util::writeLog('OCP\Share', \OCP\Util::writeLog('OCP\Share',
'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class'] 'Sharing backend '.$class.' not registered, '.self::$backendTypes[$itemType]['class']
.' is already registered for '.$itemType, .' is already registered for '.$itemType,
\OCP\Util::WARN); ILogger::WARN);
} }
return false; return false;
} }
@ -264,7 +265,7 @@ class Share extends Constants {
$query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1); $query = \OC_DB::prepare('SELECT * FROM `*PREFIX*share` WHERE `token` = ?', 1);
$result = $query->execute(array($token)); $result = $query->execute(array($token));
if ($result === false) { if ($result === false) {
\OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage() . ', token=' . $token, \OCP\Util::ERROR); \OCP\Util::writeLog('OCP\Share', \OC_DB::getErrorMessage() . ', token=' . $token, ILogger::ERROR);
} }
$row = $result->fetchRow(); $row = $result->fetchRow();
if ($row === false) { if ($row === false) {
@ -335,7 +336,7 @@ class Share extends Constants {
if ($backend->isShareTypeAllowed($shareType) === false) { if ($backend->isShareTypeAllowed($shareType) === false) {
$message = 'Sharing %s failed, because the backend does not allow shares from type %i'; $message = 'Sharing %s failed, because the backend does not allow shares from type %i';
$message_t = $l->t('Sharing %s failed, because the backend does not allow shares from type %i', array($itemSourceName, $shareType)); $message_t = $l->t('Sharing %s failed, because the backend does not allow shares from type %i', array($itemSourceName, $shareType));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareType), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareType), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
@ -356,14 +357,14 @@ class Share extends Constants {
if (!$path) { if (!$path) {
$message = 'Sharing %s failed, because the file does not exist'; $message = 'Sharing %s failed, because the file does not exist';
$message_t = $l->t('Sharing %s failed, because the file does not exist', array($itemSourceName)); $message_t = $l->t('Sharing %s failed, because the file does not exist', array($itemSourceName));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
// verify that the user has share permission // verify that the user has share permission
if (!\OC\Files\Filesystem::isSharable($path) || \OCP\Util::isSharingDisabledForUser()) { if (!\OC\Files\Filesystem::isSharable($path) || \OCP\Util::isSharingDisabledForUser()) {
$message = 'You are not allowed to share %s'; $message = 'You are not allowed to share %s';
$message_t = $l->t('You are not allowed to share %s', [$path]); $message_t = $l->t('You are not allowed to share %s', [$path]);
\OCP\Util::writeLog('OCP\Share', sprintf($message, $path), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $path), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} }
@ -376,7 +377,7 @@ class Share extends Constants {
foreach ($mounts as $mount) { foreach ($mounts as $mount) {
if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) { if ($mount->getStorage()->instanceOfStorage('\OCA\Files_Sharing\ISharedStorage')) {
$message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!'; $message = 'Sharing "' . $itemSourceName . '" failed, because it contains files shared with you!';
\OCP\Util::writeLog('OCP\Share', $message, \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', $message, ILogger::DEBUG);
throw new \Exception($message); throw new \Exception($message);
} }
@ -408,13 +409,13 @@ class Share extends Constants {
if ($shareWith == $uidOwner) { if ($shareWith == $uidOwner) {
$message = 'Sharing %s failed, because you can not share with yourself'; $message = 'Sharing %s failed, because you can not share with yourself';
$message_t = $l->t('Sharing %s failed, because you can not share with yourself', [$itemName]); $message_t = $l->t('Sharing %s failed, because you can not share with yourself', [$itemName]);
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
if (!\OC::$server->getUserManager()->userExists($shareWith)) { if (!\OC::$server->getUserManager()->userExists($shareWith)) {
$message = 'Sharing %s failed, because the user %s does not exist'; $message = 'Sharing %s failed, because the user %s does not exist';
$message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith)); $message_t = $l->t('Sharing %s failed, because the user %s does not exist', array($itemSourceName, $shareWith));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
if ($shareWithinGroupOnly) { if ($shareWithinGroupOnly) {
@ -435,7 +436,7 @@ class Share extends Constants {
$message = 'Sharing %s failed, because the user ' $message = 'Sharing %s failed, because the user '
.'%s is not a member of any groups that %s is a member of'; .'%s is not a member of any groups that %s is a member of';
$message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemName, $shareWith, $uidOwner)); $message_t = $l->t('Sharing %s failed, because the user %s is not a member of any groups that %s is a member of', array($itemName, $shareWith, $uidOwner));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemName, $shareWith, $uidOwner), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemName, $shareWith, $uidOwner), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} }
@ -448,7 +449,7 @@ class Share extends Constants {
if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
$message = 'Sharing %s failed, because this item is already shared with %s'; $message = 'Sharing %s failed, because this item is already shared with %s';
$message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} }
@ -460,7 +461,7 @@ class Share extends Constants {
if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) { if ($checkExists['uid_owner'] != $uidOwner || $checkExists['share_type'] == $shareType) {
$message = 'Sharing %s failed, because this item is already shared with user %s'; $message = 'Sharing %s failed, because this item is already shared with user %s';
$message_t = $l->t('Sharing %s failed, because this item is already shared with user %s', array($itemSourceName, $shareWith)); $message_t = $l->t('Sharing %s failed, because this item is already shared with user %s', array($itemSourceName, $shareWith));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::ERROR); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), ILogger::ERROR);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} }
@ -468,7 +469,7 @@ class Share extends Constants {
if (!\OC::$server->getGroupManager()->groupExists($shareWith)) { if (!\OC::$server->getGroupManager()->groupExists($shareWith)) {
$message = 'Sharing %s failed, because the group %s does not exist'; $message = 'Sharing %s failed, because the group %s does not exist';
$message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith)); $message_t = $l->t('Sharing %s failed, because the group %s does not exist', array($itemSourceName, $shareWith));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
if ($shareWithinGroupOnly) { if ($shareWithinGroupOnly) {
@ -478,7 +479,7 @@ class Share extends Constants {
$message = 'Sharing %s failed, because ' $message = 'Sharing %s failed, because '
. '%s is not a member of the group %s'; . '%s is not a member of the group %s';
$message_t = $l->t('Sharing %s failed, because %s is not a member of the group %s', array($itemSourceName, $uidOwner, $shareWith)); $message_t = $l->t('Sharing %s failed, because %s is not a member of the group %s', array($itemSourceName, $uidOwner, $shareWith));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $uidOwner, $shareWith), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $uidOwner, $shareWith), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} }
@ -490,7 +491,7 @@ class Share extends Constants {
if ($checkExists['share_with'] === $shareWith && $checkExists['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) { if ($checkExists['share_with'] === $shareWith && $checkExists['share_type'] === \OCP\Share::SHARE_TYPE_GROUP) {
$message = 'Sharing %s failed, because this item is already shared with %s'; $message = 'Sharing %s failed, because this item is already shared with %s';
$message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} }
@ -557,7 +558,7 @@ class Share extends Constants {
if (\OCP\Util::isPublicLinkPasswordRequired() && empty($shareWith)) { if (\OCP\Util::isPublicLinkPasswordRequired() && empty($shareWith)) {
$message = 'You need to provide a password to create a public link, only protected links are allowed'; $message = 'You need to provide a password to create a public link, only protected links are allowed';
$message_t = $l->t('You need to provide a password to create a public link, only protected links are allowed'); $message_t = $l->t('You need to provide a password to create a public link, only protected links are allowed');
\OCP\Util::writeLog('OCP\Share', $message, \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', $message, ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
@ -585,7 +586,7 @@ class Share extends Constants {
} }
$message = 'Sharing %s failed, because sharing with links is not allowed'; $message = 'Sharing %s failed, because sharing with links is not allowed';
$message_t = $l->t('Sharing %s failed, because sharing with links is not allowed', array($itemSourceName)); $message_t = $l->t('Sharing %s failed, because sharing with links is not allowed', array($itemSourceName));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} else if ($shareType === self::SHARE_TYPE_REMOTE) { } else if ($shareType === self::SHARE_TYPE_REMOTE) {
@ -596,7 +597,7 @@ class Share extends Constants {
$shareWith, $uidOwner, self::FORMAT_NONE, null, 1, true, true)) { $shareWith, $uidOwner, self::FORMAT_NONE, null, 1, true, true)) {
$message = 'Sharing %s failed, because this item is already shared with %s'; $message = 'Sharing %s failed, because this item is already shared with %s';
$message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith)); $message_t = $l->t('Sharing %s failed, because this item is already shared with %s', array($itemSourceName, $shareWith));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
@ -607,7 +608,7 @@ class Share extends Constants {
if (Helper::isSameUserOnSameServer($user, $remote, $currentUser, $currentServer)) { if (Helper::isSameUserOnSameServer($user, $remote, $currentUser, $currentServer)) {
$message = 'Not allowed to create a federated share with the same user.'; $message = 'Not allowed to create a federated share with the same user.';
$message_t = $l->t('Not allowed to create a federated share with the same user'); $message_t = $l->t('Not allowed to create a federated share with the same user');
\OCP\Util::writeLog('OCP\Share', $message, \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', $message, ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
@ -634,7 +635,7 @@ class Share extends Constants {
// Future share types need to include their own conditions // Future share types need to include their own conditions
$message = 'Share type %s is not valid for %s'; $message = 'Share type %s is not valid for %s';
$message_t = $l->t('Share type %s is not valid for %s', array($shareType, $itemSource)); $message_t = $l->t('Share type %s is not valid for %s', array($shareType, $itemSource));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $shareType, $itemSource), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $shareType, $itemSource), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
@ -703,7 +704,7 @@ class Share extends Constants {
$result = $query->execute(array($status, $itemType, $itemSource, $shareType, $recipient)); $result = $query->execute(array($status, $itemType, $itemSource, $shareType, $recipient));
if($result === false) { if($result === false) {
\OCP\Util::writeLog('OCP\Share', 'Couldn\'t set send mail status', \OCP\Util::ERROR); \OCP\Util::writeLog('OCP\Share', 'Couldn\'t set send mail status', ILogger::ERROR);
} }
} }
@ -740,7 +741,7 @@ class Share extends Constants {
if ($date > $maxDate) { if ($date > $maxDate) {
$warning = 'Cannot set expiration date. Shares cannot expire later than ' . $maxDays . ' after they have been shared'; $warning = 'Cannot set expiration date. Shares cannot expire later than ' . $maxDays . ' after they have been shared';
$warning_t = $l->t('Cannot set expiration date. Shares cannot expire later than %s after they have been shared', array($maxDays)); $warning_t = $l->t('Cannot set expiration date. Shares cannot expire later than %s after they have been shared', array($maxDays));
\OCP\Util::writeLog('OCP\Share', $warning, \OCP\Util::WARN); \OCP\Util::writeLog('OCP\Share', $warning, ILogger::WARN);
throw new \Exception($warning_t); throw new \Exception($warning_t);
} }
} }
@ -748,7 +749,7 @@ class Share extends Constants {
if ($date < $today) { if ($date < $today) {
$message = 'Cannot set expiration date. Expiration date is in the past'; $message = 'Cannot set expiration date. Expiration date is in the past';
$message_t = $l->t('Cannot set expiration date. Expiration date is in the past'); $message_t = $l->t('Cannot set expiration date. Expiration date is in the past');
\OCP\Util::writeLog('OCP\Share', $message, \OCP\Util::WARN); \OCP\Util::writeLog('OCP\Share', $message, ILogger::WARN);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
@ -849,20 +850,20 @@ class Share extends Constants {
if (!(self::$backends[$itemType] instanceof \OCP\Share_Backend)) { if (!(self::$backends[$itemType] instanceof \OCP\Share_Backend)) {
$message = 'Sharing backend %s must implement the interface OCP\Share_Backend'; $message = 'Sharing backend %s must implement the interface OCP\Share_Backend';
$message_t = $l->t('Sharing backend %s must implement the interface OCP\Share_Backend', array($class)); $message_t = $l->t('Sharing backend %s must implement the interface OCP\Share_Backend', array($class));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $class), \OCP\Util::ERROR); \OCP\Util::writeLog('OCP\Share', sprintf($message, $class), ILogger::ERROR);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
return self::$backends[$itemType]; return self::$backends[$itemType];
} else { } else {
$message = 'Sharing backend %s not found'; $message = 'Sharing backend %s not found';
$message_t = $l->t('Sharing backend %s not found', array($class)); $message_t = $l->t('Sharing backend %s not found', array($class));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $class), \OCP\Util::ERROR); \OCP\Util::writeLog('OCP\Share', sprintf($message, $class), ILogger::ERROR);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} }
$message = 'Sharing backend for %s not found'; $message = 'Sharing backend for %s not found';
$message_t = $l->t('Sharing backend for %s not found', array($itemType)); $message_t = $l->t('Sharing backend for %s not found', array($itemType));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemType), \OCP\Util::ERROR); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemType), ILogger::ERROR);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
@ -1133,7 +1134,7 @@ class Share extends Constants {
if ($result === false) { if ($result === false) {
\OCP\Util::writeLog('OCP\Share', \OCP\Util::writeLog('OCP\Share',
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=', \OC_DB::getErrorMessage() . ', select=' . $select . ' where=',
\OCP\Util::ERROR); ILogger::ERROR);
} }
$items = array(); $items = array();
$targets = array(); $targets = array();
@ -1197,7 +1198,7 @@ class Share extends Constants {
if ($result === false) { if ($result === false) {
\OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' . \OCP\Util::writeLog('OCP\Share', 'Can\'t select parent: ' .
\OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where, \OC_DB::getErrorMessage() . ', select=' . $select . ' where=' . $where,
\OCP\Util::ERROR); ILogger::ERROR);
} else { } else {
$parentRow = $parentResult->fetchRow(); $parentRow = $parentResult->fetchRow();
$tmpPath = $parentRow['file_target']; $tmpPath = $parentRow['file_target'];
@ -1668,7 +1669,7 @@ class Share extends Constants {
$message = 'Sharing %s failed, because the user %s is the original sharer'; $message = 'Sharing %s failed, because the user %s is the original sharer';
$message_t = $l->t('Sharing failed, because the user %s is the original sharer', [$shareWith]); $message_t = $l->t('Sharing failed, because the user %s is the original sharer', [$shareWith]);
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $shareWith), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} }
@ -1680,7 +1681,7 @@ class Share extends Constants {
$message = 'Sharing %s failed, because the permissions exceed permissions granted to %s'; $message = 'Sharing %s failed, because the permissions exceed permissions granted to %s';
$message_t = $l->t('Sharing %s failed, because the permissions exceed permissions granted to %s', array($itemSourceName, $uidOwner)); $message_t = $l->t('Sharing %s failed, because the permissions exceed permissions granted to %s', array($itemSourceName, $uidOwner));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $uidOwner), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName, $uidOwner), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} else { } else {
// TODO Don't check if inside folder // TODO Don't check if inside folder
@ -1712,7 +1713,7 @@ class Share extends Constants {
$message = 'Sharing %s failed, because resharing is not allowed'; $message = 'Sharing %s failed, because resharing is not allowed';
$message_t = $l->t('Sharing %s failed, because resharing is not allowed', array($itemSourceName)); $message_t = $l->t('Sharing %s failed, because resharing is not allowed', array($itemSourceName));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSourceName), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} else { } else {
@ -1725,7 +1726,7 @@ class Share extends Constants {
$message = 'Sharing %s failed, because the sharing backend for ' $message = 'Sharing %s failed, because the sharing backend for '
.'%s could not find its source'; .'%s could not find its source';
$message_t = $l->t('Sharing %s failed, because the sharing backend for %s could not find its source', array($itemSource, $itemType)); $message_t = $l->t('Sharing %s failed, because the sharing backend for %s could not find its source', array($itemSource, $itemType));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSource, $itemType), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSource, $itemType), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
if ($backend instanceof \OCP\Share_Backend_File_Dependent) { if ($backend instanceof \OCP\Share_Backend_File_Dependent) {
@ -1740,7 +1741,7 @@ class Share extends Constants {
$message = 'Sharing %s failed, because the file could not be found in the file cache'; $message = 'Sharing %s failed, because the file could not be found in the file cache';
$message_t = $l->t('Sharing %s failed, because the file could not be found in the file cache', array($itemSource)); $message_t = $l->t('Sharing %s failed, because the file could not be found in the file cache', array($itemSource));
\OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSource), \OCP\Util::DEBUG); \OCP\Util::writeLog('OCP\Share', sprintf($message, $itemSource), ILogger::DEBUG);
throw new \Exception($message_t); throw new \Exception($message_t);
} }
} else { } else {

View File

@ -47,6 +47,7 @@ namespace OC;
use OC\Tagging\Tag; use OC\Tagging\Tag;
use OC\Tagging\TagMapper; use OC\Tagging\TagMapper;
use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\ILogger;
class Tags implements \OCP\ITags { class Tags implements \OCP\ITags {
@ -237,14 +238,14 @@ class Tags implements \OCP\ITags {
$entries[$objId][] = $row['category']; $entries[$objId][] = $row['category'];
} }
if ($result === null) { if ($result === null) {
\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), \OCP\Util::ERROR); \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR);
return false; return false;
} }
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;
@ -270,7 +271,7 @@ class Tags implements \OCP\ITags {
} elseif(is_string($tag)) { } elseif(is_string($tag)) {
$tag = trim($tag); $tag = trim($tag);
if($tag === '') { if($tag === '') {
\OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', ILogger::DEBUG);
return false; return false;
} }
$tagId = $this->getTagId($tag); $tagId = $this->getTagId($tag);
@ -291,13 +292,13 @@ class Tags implements \OCP\ITags {
$stmt = \OC_DB::prepare($sql); $stmt = \OC_DB::prepare($sql);
$result = $stmt->execute(array($tagId)); $result = $stmt->execute(array($tagId));
if ($result === null) { if ($result === null) {
\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), \OCP\Util::ERROR); \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR);
return false; return false;
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;
@ -360,11 +361,11 @@ class Tags implements \OCP\ITags {
$name = trim($name); $name = trim($name);
if($name === '') { if($name === '') {
\OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', ILogger::DEBUG);
return false; return false;
} }
if($this->userHasTag($name, $this->user)) { if($this->userHasTag($name, $this->user)) {
\OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', name: ' . $name. ' exists already', ILogger::DEBUG);
return false; return false;
} }
try { try {
@ -374,12 +375,12 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;
} }
\OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', id: ' . $tag->getId(), ILogger::DEBUG);
return $tag->getId(); return $tag->getId();
} }
@ -395,7 +396,7 @@ class Tags implements \OCP\ITags {
$to = trim($to); $to = trim($to);
if($to === '' || $from === '') { if($to === '' || $from === '') {
\OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', Cannot use empty tag names', ILogger::DEBUG);
return false; return false;
} }
@ -405,13 +406,13 @@ class Tags implements \OCP\ITags {
$key = $this->getTagByName($from); $key = $this->getTagByName($from);
} }
if($key === false) { if($key === false) {
\OCP\Util::writeLog('core', __METHOD__.', tag: ' . $from. ' does not exist', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', tag: ' . $from. ' does not exist', ILogger::DEBUG);
return false; return false;
} }
$tag = $this->tags[$key]; $tag = $this->tags[$key];
if($this->userHasTag($to, $tag->getOwner())) { if($this->userHasTag($to, $tag->getOwner())) {
\OCP\Util::writeLog('core', __METHOD__.', A tag named ' . $to. ' already exists for user ' . $tag->getOwner() . '.', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', A tag named ' . $to. ' already exists for user ' . $tag->getOwner() . '.', ILogger::DEBUG);
return false; return false;
} }
@ -421,7 +422,7 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;
@ -476,7 +477,7 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
} }
@ -485,7 +486,7 @@ class Tags implements \OCP\ITags {
// reload tags to get the proper ids. // reload tags to get the proper ids.
$this->tags = $this->mapper->loadTags($this->owners, $this->type); $this->tags = $this->mapper->loadTags($this->owners, $this->type);
\OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true), \OCP\Util::writeLog('core', __METHOD__.', tags: ' . print_r($this->tags, true),
\OCP\Util::DEBUG); ILogger::DEBUG);
// Loop through temporarily cached objectid/tagname pairs // Loop through temporarily cached objectid/tagname pairs
// and save relations. // and save relations.
$tags = $this->tags; $tags = $this->tags;
@ -494,7 +495,7 @@ class Tags implements \OCP\ITags {
$dbConnection = \OC::$server->getDatabaseConnection(); $dbConnection = \OC::$server->getDatabaseConnection();
foreach(self::$relations as $relation) { foreach(self::$relations as $relation) {
$tagId = $this->getTagId($relation['tag']); $tagId = $this->getTagId($relation['tag']);
\OCP\Util::writeLog('core', __METHOD__ . 'catid, ' . $relation['tag'] . ' ' . $tagId, \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__ . 'catid, ' . $relation['tag'] . ' ' . $tagId, ILogger::DEBUG);
if($tagId) { if($tagId) {
try { try {
$dbConnection->insertIfNotExist(self::RELATION_TABLE, $dbConnection->insertIfNotExist(self::RELATION_TABLE,
@ -506,7 +507,7 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
} }
@ -515,7 +516,7 @@ class Tags implements \OCP\ITags {
self::$relations = array(); // reset self::$relations = array(); // reset
} else { } else {
\OCP\Util::writeLog('core', __METHOD__.', $this->tags is not an array! ' \OCP\Util::writeLog('core', __METHOD__.', $this->tags is not an array! '
. print_r($this->tags, true), \OCP\Util::ERROR); . print_r($this->tags, true), ILogger::ERROR);
} }
} }
@ -534,12 +535,12 @@ class Tags implements \OCP\ITags {
. 'WHERE `uid` = ?'); . 'WHERE `uid` = ?');
$result = $stmt->execute(array($arguments['uid'])); $result = $stmt->execute(array($arguments['uid']));
if ($result === null) { if ($result === null) {
\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), \OCP\Util::ERROR); \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR);
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
} }
@ -554,7 +555,7 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
} }
@ -562,7 +563,7 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
} }
@ -572,12 +573,12 @@ class Tags implements \OCP\ITags {
. 'WHERE `uid` = ?'); . 'WHERE `uid` = ?');
$result = $stmt->execute(array($arguments['uid'])); $result = $stmt->execute(array($arguments['uid']));
if ($result === null) { if ($result === null) {
\OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OC::$server->getDatabaseConnection()->getError(), \OCP\Util::ERROR); \OCP\Util::writeLog('core', __METHOD__. ', DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR);
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
} }
@ -603,13 +604,13 @@ class Tags implements \OCP\ITags {
$stmt = \OC_DB::prepare($query); $stmt = \OC_DB::prepare($query);
$result = $stmt->execute($updates); $result = $stmt->execute($updates);
if ($result === null) { if ($result === null) {
\OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), \OCP\Util::ERROR); \OCP\Util::writeLog('core', __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), ILogger::ERROR);
return false; return false;
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;
@ -628,7 +629,7 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return array(); return array();
@ -669,7 +670,7 @@ class Tags implements \OCP\ITags {
if(is_string($tag) && !is_numeric($tag)) { if(is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag); $tag = trim($tag);
if($tag === '') { if($tag === '') {
\OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', Cannot add an empty tag', ILogger::DEBUG);
return false; return false;
} }
if(!$this->hasTag($tag)) { if(!$this->hasTag($tag)) {
@ -689,7 +690,7 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;
@ -708,7 +709,7 @@ class Tags implements \OCP\ITags {
if(is_string($tag) && !is_numeric($tag)) { if(is_string($tag) && !is_numeric($tag)) {
$tag = trim($tag); $tag = trim($tag);
if($tag === '') { if($tag === '') {
\OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', __METHOD__.', Tag name is empty', ILogger::DEBUG);
return false; return false;
} }
$tagId = $this->getTagId($tag); $tagId = $this->getTagId($tag);
@ -724,7 +725,7 @@ class Tags implements \OCP\ITags {
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;
@ -747,7 +748,7 @@ class Tags implements \OCP\ITags {
array_filter($names); array_filter($names);
\OCP\Util::writeLog('core', __METHOD__ . ', before: ' \OCP\Util::writeLog('core', __METHOD__ . ', before: '
. print_r($this->tags, true), \OCP\Util::DEBUG); . print_r($this->tags, true), ILogger::DEBUG);
foreach($names as $name) { foreach($names as $name) {
$id = null; $id = null;
@ -763,7 +764,7 @@ class Tags implements \OCP\ITags {
$this->mapper->delete($tag); $this->mapper->delete($tag);
} else { } else {
\OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name \OCP\Util::writeLog('core', __METHOD__ . 'Cannot delete tag ' . $name
. ': not found.', \OCP\Util::ERROR); . ': not found.', ILogger::ERROR);
} }
if(!is_null($id) && $id !== false) { if(!is_null($id) && $id !== false) {
try { try {
@ -774,13 +775,13 @@ class Tags implements \OCP\ITags {
if ($result === null) { if ($result === null) {
\OCP\Util::writeLog('core', \OCP\Util::writeLog('core',
__METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(), __METHOD__. 'DB error: ' . \OC::$server->getDatabaseConnection()->getError(),
\OCP\Util::ERROR); ILogger::ERROR);
return false; return false;
} }
} catch(\Exception $e) { } catch(\Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'message' => __METHOD__, 'message' => __METHOD__,
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'core', 'app' => 'core',
]); ]);
return false; return false;

View File

@ -100,9 +100,9 @@ class Updater extends BasicEmitter {
$this->emitRepairEvents(); $this->emitRepairEvents();
$this->logAllEvents(); $this->logAllEvents();
$logLevel = $this->config->getSystemValue('loglevel', Util::WARN); $logLevel = $this->config->getSystemValue('loglevel', ILogger::WARN);
$this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]); $this->emit('\OC\Updater', 'setDebugLogLevel', [ $logLevel, $this->logLevelNames[$logLevel] ]);
$this->config->setSystemValue('loglevel', Util::DEBUG); $this->config->setSystemValue('loglevel', ILogger::DEBUG);
$wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false); $wasMaintenanceModeEnabled = $this->config->getSystemValue('maintenance', false);

View File

@ -59,6 +59,7 @@ namespace OC\User;
use OC\Cache\CappedMemoryCache; use OC\Cache\CappedMemoryCache;
use OCP\IDBConnection; use OCP\IDBConnection;
use OCP\ILogger;
use OCP\User\Backend\ABackend; use OCP\User\Backend\ABackend;
use OCP\User\Backend\ICheckPasswordBackend; use OCP\User\Backend\ICheckPasswordBackend;
use OCP\User\Backend\ICountUsersBackend; use OCP\User\Backend\ICountUsersBackend;
@ -408,7 +409,7 @@ class Database extends ABackend
$query = \OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`'); $query = \OC_DB::prepare('SELECT COUNT(*) FROM `*PREFIX*users`');
$result = $query->execute(); $result = $query->execute();
if ($result === false) { if ($result === false) {
Util::writeLog('core', \OC_DB::getErrorMessage(), Util::ERROR); Util::writeLog('core', \OC_DB::getErrorMessage(), ILogger::ERROR);
return false; return false;
} }
return $result->fetchOne(); return $result->fetchOne();

View File

@ -56,6 +56,7 @@ use OC\DB\MigrationService;
use OC\Installer; use OC\Installer;
use OC\Repair; use OC\Repair;
use OCP\App\ManagerEvent; use OCP\App\ManagerEvent;
use OCP\ILogger;
/** /**
* This class manages the apps. It allows them to register and integrate in the * This class manages the apps. It allows them to register and integrate in the
@ -425,7 +426,7 @@ class OC_App {
} }
} }
\OCP\Util::writeLog('core', 'No application directories are marked as writable.', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'No application directories are marked as writable.', ILogger::ERROR);
return null; return null;
} }
@ -666,7 +667,7 @@ class OC_App {
foreach (OC::$APPSROOTS as $apps_dir) { foreach (OC::$APPSROOTS as $apps_dir) {
if (!is_readable($apps_dir['path'])) { if (!is_readable($apps_dir['path'])) {
\OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], \OCP\Util::WARN); \OCP\Util::writeLog('core', 'unable to read app folder : ' . $apps_dir['path'], ILogger::WARN);
continue; continue;
} }
$dh = opendir($apps_dir['path']); $dh = opendir($apps_dir['path']);
@ -707,12 +708,12 @@ class OC_App {
$info = OC_App::getAppInfo($app, false, $langCode); $info = OC_App::getAppInfo($app, false, $langCode);
if (!is_array($info)) { if (!is_array($info)) {
\OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'Could not read app info file for app "' . $app . '"', ILogger::ERROR);
continue; continue;
} }
if (!isset($info['name'])) { if (!isset($info['name'])) {
\OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'App id "' . $app . '" has no name in appinfo', ILogger::ERROR);
continue; continue;
} }
@ -994,11 +995,11 @@ class OC_App {
} }
return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId); return new \OC\Files\View('/' . OC_User::getUser() . '/' . $appId);
} else { } else {
\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ', user not logged in', ILogger::ERROR);
return false; return false;
} }
} else { } else {
\OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'Can\'t get app storage, app ' . $appId . ' not enabled', ILogger::ERROR);
return false; return false;
} }
} }

View File

@ -28,6 +28,8 @@
* *
*/ */
use OCP\ILogger;
/** /**
* This class manages the access to the database. It basically is a wrapper for * This class manages the access to the database. It basically is a wrapper for
* Doctrine with some adaptions. * Doctrine with some adaptions.
@ -185,7 +187,7 @@ class OC_DB {
try { try {
$result = $schemaManager->updateDbFromStructure($file); $result = $schemaManager->updateDbFromStructure($file);
} catch (Exception $e) { } catch (Exception $e) {
\OCP\Util::writeLog('core', 'Failed to update database structure ('.$e.')', \OCP\Util::FATAL); \OCP\Util::writeLog('core', 'Failed to update database structure ('.$e.')', ILogger::FATAL);
throw $e; throw $e;
} }
return $result; return $result;

View File

@ -41,6 +41,7 @@
use OC\Files\View; use OC\Files\View;
use OC\Streamer; use OC\Streamer;
use OCP\ILogger;
use OCP\Lock\ILockingProvider; use OCP\Lock\ILockingProvider;
/** /**
@ -422,7 +423,7 @@ class OC_Files {
if (!$handle) { if (!$handle) {
\OCP\Util::writeLog('files', \OCP\Util::writeLog('files',
'Can\'t write upload limit to ' . $filename . '. Please check the file permissions', 'Can\'t write upload limit to ' . $filename . '. Please check the file permissions',
\OCP\Util::WARN); ILogger::WARN);
$success = false; $success = false;
continue; // try to update as many files as possible continue; // try to update as many files as possible
} }

View File

@ -38,6 +38,8 @@
* *
*/ */
use OCP\ILogger;
/** /**
* This class provides wrapper methods for user management. Multiple backends are * This class provides wrapper methods for user management. Multiple backends are
* supported. User management operations are delegated to the configured backend for * supported. User management operations are delegated to the configured backend for
@ -89,7 +91,7 @@ class OC_User {
case 'database': case 'database':
case 'mysql': case 'mysql':
case 'sqlite': case 'sqlite':
\OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', 'Adding user backend ' . $backend . '.', ILogger::DEBUG);
self::$_usedBackends[$backend] = new \OC\User\Database(); self::$_usedBackends[$backend] = new \OC\User\Database();
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
break; break;
@ -98,7 +100,7 @@ class OC_User {
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
break; break;
default: default:
\OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', 'Adding default user backend ' . $backend . '.', ILogger::DEBUG);
$className = 'OC_USER_' . strtoupper($backend); $className = 'OC_USER_' . strtoupper($backend);
self::$_usedBackends[$backend] = new $className(); self::$_usedBackends[$backend] = new $className();
\OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]); \OC::$server->getUserManager()->registerBackend(self::$_usedBackends[$backend]);
@ -143,10 +145,10 @@ class OC_User {
self::useBackend($backend); self::useBackend($backend);
self::$_setupedBackends[] = $i; self::$_setupedBackends[] = $i;
} else { } else {
\OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', \OCP\Util::DEBUG); \OCP\Util::writeLog('core', 'User backend ' . $class . ' already initialized.', ILogger::DEBUG);
} }
} else { } else {
\OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', \OCP\Util::ERROR); \OCP\Util::writeLog('core', 'User backend ' . $class . ' not found.', ILogger::ERROR);
} }
} }
} }

View File

@ -62,6 +62,7 @@
use OCP\IConfig; use OCP\IConfig;
use OCP\IGroupManager; use OCP\IGroupManager;
use OCP\ILogger;
use OCP\IUser; use OCP\IUser;
class OC_Util { class OC_Util {
@ -100,7 +101,7 @@ class OC_Util {
private static function initObjectStoreRootFS($config) { private static function initObjectStoreRootFS($config) {
// check misconfiguration // check misconfiguration
if (empty($config['class'])) { if (empty($config['class'])) {
\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
} }
if (!isset($config['arguments'])) { if (!isset($config['arguments'])) {
$config['arguments'] = array(); $config['arguments'] = array();
@ -134,7 +135,7 @@ class OC_Util {
private static function initObjectStoreMultibucketRootFS($config) { private static function initObjectStoreMultibucketRootFS($config) {
// check misconfiguration // check misconfiguration
if (empty($config['class'])) { if (empty($config['class'])) {
\OCP\Util::writeLog('files', 'No class given for objectstore', \OCP\Util::ERROR); \OCP\Util::writeLog('files', 'No class given for objectstore', ILogger::ERROR);
} }
if (!isset($config['arguments'])) { if (!isset($config['arguments'])) {
$config['arguments'] = array(); $config['arguments'] = array();
@ -409,7 +410,7 @@ class OC_Util {
\OCP\Util::writeLog( \OCP\Util::writeLog(
'files_skeleton', 'files_skeleton',
'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'), 'copying skeleton for '.$userId.' from '.$skeletonDirectory.' to '.$userDirectory->getFullPath('/'),
\OCP\Util::DEBUG ILogger::DEBUG
); );
self::copyr($skeletonDirectory, $userDirectory); self::copyr($skeletonDirectory, $userDirectory);
// update the file cache // update the file cache
@ -1378,7 +1379,7 @@ class OC_Util {
// XCache // XCache
if (function_exists('xcache_clear_cache')) { if (function_exists('xcache_clear_cache')) {
if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) { if (\OC::$server->getIniWrapper()->getBool('xcache.admin.enable_auth')) {
\OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', \OCP\Util::WARN); \OCP\Util::writeLog('core', 'XCache opcode cache will not be cleared because "xcache.admin.enable_auth" is enabled.', ILogger::WARN);
} else { } else {
@xcache_clear_cache(XC_TYPE_PHP, 0); @xcache_clear_cache(XC_TYPE_PHP, 0);
} }

View File

@ -36,6 +36,27 @@ namespace OCP;
* https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#3-psrlogloggerinterface * https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-3-logger-interface.md#3-psrlogloggerinterface
*/ */
interface ILogger { interface ILogger {
/**
* @since 14.0.0
*/
const DEBUG=0;
/**
* @since 14.0.0
*/
const INFO=1;
/**
* @since 14.0.0
*/
const WARN=2;
/**
* @since 14.0.0
*/
const ERROR=3;
/**
* @since 14.0.0
*/
const FATAL=4;
/** /**
* System is unusable. * System is unusable.
* *

View File

@ -57,11 +57,25 @@ namespace OCP;
* @since 4.0.0 * @since 4.0.0
*/ */
class Util { class Util {
// consts for Logging /**
* @deprecated 14.0.0 use \OCP\ILogger::DEBUG
*/
const DEBUG=0; const DEBUG=0;
/**
* @deprecated 14.0.0 use \OCP\ILogger::INFO
*/
const INFO=1; const INFO=1;
/**
* @deprecated 14.0.0 use \OCP\ILogger::WARN
*/
const WARN=2; const WARN=2;
/**
* @deprecated 14.0.0 use \OCP\ILogger::ERROR
*/
const ERROR=3; const ERROR=3;
/**
* @deprecated 14.0.0 use \OCP\ILogger::FATAL
*/
const FATAL=4; const FATAL=4;
/** \OCP\Share\IManager */ /** \OCP\Share\IManager */
@ -115,7 +129,7 @@ class Util {
* @since ....0.0 - parameter $level was added in 7.0.0 * @since ....0.0 - parameter $level was added in 7.0.0
* @deprecated 8.2.0 use logException of \OCP\ILogger * @deprecated 8.2.0 use logException of \OCP\ILogger
*/ */
public static function logException( $app, \Exception $ex, $level = \OCP\Util::FATAL ) { public static function logException( $app, \Exception $ex, $level = ILogger::FATAL) {
\OC::$server->getLogger()->logException($ex, ['app' => $app]); \OC::$server->getLogger()->logException($ex, ['app' => $app]);
} }

View File

@ -455,7 +455,7 @@ class UsersController extends Controller {
} catch (\Exception $e) { } catch (\Exception $e) {
$this->log->logException($e, [ $this->log->logException($e, [
'message' => "Can't send new user mail to $email", 'message' => "Can't send new user mail to $email",
'level' => \OCP\Util::ERROR, 'level' => ILogger::ERROR,
'app' => 'settings', 'app' => 'settings',
]); ]);
} }

View File

@ -24,6 +24,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/> * along with this program. If not, see <http://www.gnu.org/licenses/>
* *
*/ */
use OCP\ILogger;
OC_JSON::checkAdminUser(); OC_JSON::checkAdminUser();
\OC_JSON::callCheck(); \OC_JSON::callCheck();
@ -51,7 +54,7 @@ try {
OC_JSON::success(['data' => ['update_required' => $updateRequired]]); OC_JSON::success(['data' => ['update_required' => $updateRequired]]);
} catch (Exception $e) { } catch (Exception $e) {
\OC::$server->getLogger()->logException($e, [ \OC::$server->getLogger()->logException($e, [
'level' => \OCP\Util::DEBUG, 'level' => ILogger::DEBUG,
'app' => 'core', 'app' => 'core',
]); ]);
OC_JSON::error(array("data" => array("message" => $e->getMessage()) )); OC_JSON::error(array("data" => array("message" => $e->getMessage()) ));

View File

@ -18,6 +18,7 @@
namespace Test\Log; namespace Test\Log;
use OC\Log\File; use OC\Log\File;
use OCP\ILogger;
use Test\TestCase; use Test\TestCase;
/** /**
@ -62,8 +63,8 @@ class FileTest extends TestCase
# set format & write log line # set format & write log line
$config->setSystemValue('logdateformat', 'u'); $config->setSystemValue('logdateformat', 'u');
File::write('test', 'message', \OCP\Util::ERROR); File::write('test', 'message', ILogger::ERROR);
# read log line # read log line
$handle = @fopen($config->getSystemValue('logfile'), 'r'); $handle = @fopen($config->getSystemValue('logfile'), 'r');
$line = fread($handle, 1000); $line = fread($handle, 1000);

View File

@ -9,6 +9,7 @@
namespace Test; namespace Test;
use OC\Log; use OC\Log;
use OCP\ILogger;
class LoggerTest extends TestCase { class LoggerTest extends TestCase {
@ -45,7 +46,7 @@ class LoggerTest extends TestCase {
$this->config->expects($this->any()) $this->config->expects($this->any())
->method('getValue') ->method('getValue')
->will(($this->returnValueMap([ ->will(($this->returnValueMap([
['loglevel', \OCP\Util::WARN, \OCP\Util::WARN], ['loglevel', ILogger::WARN, ILogger::WARN],
['log.condition', [], ['apps' => ['files']]] ['log.condition', [], ['apps' => ['files']]]
]))); ])));
$logger = $this->logger; $logger = $this->logger;