6161use OCP \Files \Storage \ILockingStorage ;
6262use OCP \Files \Storage \IStorage ;
6363use OCP \Files \Storage \IWriteStreamStorage ;
64- use OCP \ILogger ;
6564use OCP \Lock \ILockingProvider ;
6665use OCP \Lock \LockedException ;
66+ use Psr \Log \LoggerInterface ;
6767
6868/**
6969 * Storage backend class for providing common filesystem operation methods
@@ -89,7 +89,9 @@ abstract class Common implements Storage, ILockingStorage, IWriteStreamStorage {
8989 protected $ mountOptions = [];
9090 protected $ owner = null ;
9191
92+ /** @var ?bool */
9293 private $ shouldLogLocks = null ;
94+ /** @var ?LoggerInterface */
9395 private $ logger ;
9496
9597 public function __construct ($ parameters ) {
@@ -237,7 +239,7 @@ public function copy($path1, $path2) {
237239 $ target = $ this ->fopen ($ path2 , 'w ' );
238240 [, $ result ] = \OC_Helper::streamCopy ($ source , $ target );
239241 if (!$ result ) {
240- \OC ::$ server ->getLogger ( )->warning ("Failed to write data while copying $ path1 to $ path2 " );
242+ \OC ::$ server ->get (LoggerInterface::class )->warning ("Failed to write data while copying $ path1 to $ path2 " );
241243 }
242244 $ this ->removeCachedFile ($ path2 );
243245 return $ result ;
@@ -459,11 +461,13 @@ public function test() {
459461 if ($ this ->stat ('' )) {
460462 return true ;
461463 }
462- \OC ::$ server ->getLogger ( )->info ("External storage not available: stat() failed " );
464+ \OC ::$ server ->get (LoggerInterface::class )->info ("External storage not available: stat() failed " );
463465 return false ;
464466 } catch (\Exception $ e ) {
465- \OC ::$ server ->getLogger ()->warning ("External storage not available: " . $ e ->getMessage ());
466- \OC ::$ server ->getLogger ()->logException ($ e , ['level ' => ILogger::WARN ]);
467+ \OC ::$ server ->get (LoggerInterface::class)->warning (
468+ "External storage not available: " . $ e ->getMessage (),
469+ ['exception ' => $ e ]
470+ );
467471 return false ;
468472 }
469473 }
@@ -628,7 +632,7 @@ public function copyFromStorage(IStorage $sourceStorage, $sourceInternalPath, $t
628632 $ this ->writeStream ($ targetInternalPath , $ source );
629633 $ result = true ;
630634 } catch (\Exception $ e ) {
631- \OC ::$ server ->getLogger ( )->logException ( $ e , [ ' level ' => ILogger:: WARN , ' message ' => ' Failed to copy stream to storage ' ]);
635+ \OC ::$ server ->get (LoggerInterface::class )->warning ( ' Failed to copy stream to storage ', [ ' exception ' => $ e ]);
632636 }
633637 }
634638
@@ -758,7 +762,7 @@ public function acquireLock($path, $type, ILockingProvider $provider) {
758762 $ provider ->acquireLock ('files/ ' . md5 ($ this ->getId () . ':: ' . trim ($ path , '/ ' )), $ type , $ this ->getId () . ':: ' . $ path );
759763 } catch (LockedException $ e ) {
760764 if ($ logger ) {
761- $ logger ->logException ($ e , ['level ' => ILogger:: INFO ]);
765+ $ logger ->info ($ e-> getMessage () , ['exception ' => $ e ]);
762766 }
763767 throw $ e ;
764768 }
@@ -790,7 +794,7 @@ public function releaseLock($path, $type, ILockingProvider $provider) {
790794 $ provider ->releaseLock ('files/ ' . md5 ($ this ->getId () . ':: ' . trim ($ path , '/ ' )), $ type );
791795 } catch (LockedException $ e ) {
792796 if ($ logger ) {
793- $ logger ->logException ($ e , ['level ' => ILogger:: INFO ]);
797+ $ logger ->info ($ e-> getMessage () , ['exception ' => $ e ]);
794798 }
795799 throw $ e ;
796800 }
@@ -821,15 +825,17 @@ public function changeLock($path, $type, ILockingProvider $provider) {
821825 try {
822826 $ provider ->changeLock ('files/ ' . md5 ($ this ->getId () . ':: ' . trim ($ path , '/ ' )), $ type );
823827 } catch (LockedException $ e ) {
824- \OC ::$ server ->getLogger ()->logException ($ e , ['level ' => ILogger::INFO ]);
828+ if ($ logger ) {
829+ $ logger ->info ($ e ->getMessage (), ['exception ' => $ e ]);
830+ }
825831 throw $ e ;
826832 }
827833 }
828834
829- private function getLockLogger () {
835+ private function getLockLogger (): ? LoggerInterface {
830836 if (is_null ($ this ->shouldLogLocks )) {
831837 $ this ->shouldLogLocks = \OC ::$ server ->getConfig ()->getSystemValue ('filelocking.debug ' , false );
832- $ this ->logger = $ this ->shouldLogLocks ? \OC ::$ server ->getLogger ( ) : null ;
838+ $ this ->logger = $ this ->shouldLogLocks ? \OC ::$ server ->get (LoggerInterface::class ) : null ;
833839 }
834840 return $ this ->logger ;
835841 }
0 commit comments