Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Wurst <christoph@winzerhof-wurst.at>2021-04-16 10:22:05 +0300
committerChristoph Wurst <christoph@winzerhof-wurst.at>2022-05-23 10:53:38 +0300
commit450136b7cffc874db7a4a1f69332cabad8f4dc8c (patch)
treea54d9210f8148ce16d9b0b97cdd498084807ffff /composer.json
parent74d81655e8b0625b436628c34dfc907f6be7f300 (diff)
Add a helper function that makes it easier to log from anywhereenhancement/logger-function
Our DI is able to inject a logger implementation to any server and app class if they want one. However, sometimes DI isn't applicable or hard to add. In those cases we typically fell back to the *service locator* pattern where we acquired a logger from the server via a global variable. There were some issues with that * `\OC` is a private class, apps are not supposed to use it * `\OC::$server` is a global variable, a well known anti-pattern * `\OC::$server->get(...)` uses the service locator anti-pattern * `\OC::$server->get(...)` may throw * `\OC::$server->get(LoggerInterface::class)` is not scoped to an app With this patch I'm proposing a new helper function ``\OCP\Log\logger`` that can be used to acquire a logger more easily. This function is meant to be public API and therefore apps may use it and there is an optional parameter to specifiy the app ID. The function hides all the ugly details about the global variable and the potentially thrown exceptions from the user. Therefore it's guaranteed that you always get a logger instance. In the worst case you get a noop, though those occasions should be rare. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
Diffstat (limited to 'composer.json')
-rw-r--r--composer.json3
1 files changed, 3 insertions, 0 deletions
diff --git a/composer.json b/composer.json
index 69ac5821c92..6a8e9e99569 100644
--- a/composer.json
+++ b/composer.json
@@ -11,6 +11,9 @@
}
},
"autoload": {
+ "files": [
+ "lib/public/Log/functions.php"
+ ],
"psr-4": {
"": "lib/private/legacy",
"OC\\": "lib/private",