[Pkg-owncloud-commits] [owncloud-doc] 70/270: add logger docs

David Prévot taffit at moszumanska.debian.org
Thu Jul 31 03:53:02 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud-doc.

commit e00b6f402e10555dbf74a0bfcd3973fe74553951
Author: Bernhard Posselt <dev at bernhard-posselt.com>
Date:   Mon May 12 01:09:31 2014 +0200

    add logger docs
---
 developer_manual/app/logging.rst | 77 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 76 insertions(+), 1 deletion(-)

diff --git a/developer_manual/app/logging.rst b/developer_manual/app/logging.rst
index c8b9274..0d1a782 100644
--- a/developer_manual/app/logging.rst
+++ b/developer_manual/app/logging.rst
@@ -1,4 +1,79 @@
+=======
 Logging
 =======
 
-.. sectionauthor:: Bernhard Posselt <dev at bernhard-posselt.com>
\ No newline at end of file
+.. sectionauthor:: Bernhard Posselt <dev at bernhard-posselt.com>
+
+The logger can be injected from the ServerContainer:
+
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\AppInfo;
+
+    use \OCP\AppFramework\App;
+
+    use \OCA\MyApp\Service\AuthorService;
+
+
+    class Application extends App {
+
+        public function __construct(array $urlParams=array()){
+            parent::__construct('myapp', $urlParams);
+
+            $container = $this->getContainer();
+
+            /**
+             * Controllers
+             */
+            $container->registerService('AuthorService', function($c) {
+                return new AuthorService(
+                    $c->query('Logger'),
+                    $c->query('AppName')
+                );
+            });
+
+            $container->registerService('Logger', function($c) {
+                return $c->query('ServerContainer')->getLogger();
+            });
+        }
+    }
+
+and then be used in the following way:
+
+.. code-block:: php
+
+    <?php
+    namespace OCA\MyApp\Service;
+
+    use \OCP\ILogger;
+
+
+    class AuthorService {
+
+        private $logger;
+        private $appName;
+
+        public function __construct(ILogger $logger, $appName){
+            $this->logger = $logger;
+            $this->appName = $appName;
+        }
+
+        public function log($message) {
+            $this->logger->error('hi', array('app' => $this->appName));
+        }
+
+    }
+
+
+The following methods are available:
+
+* **emergency**
+* **alert**
+* **critical**
+* **error**
+* **warning**
+* **notice**
+* **info**
+* **debug**
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-doc.git



More information about the Pkg-owncloud-commits mailing list