mirror of
https://github.com/nextcloud/server.git
synced 2024-08-25 06:08:18 +02:00
![Christoph Wurst](/assets/img/avatar_default.png)
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>
52 lines
1.2 KiB
JSON
52 lines
1.2 KiB
JSON
{
|
|
"config": {
|
|
"vendor-dir": "lib/composer",
|
|
"optimize-autoloader": true,
|
|
"sort-packages": true,
|
|
"platform": {
|
|
"php": "7.4"
|
|
},
|
|
"allow-plugins": {
|
|
"bamarni/composer-bin-plugin": true
|
|
}
|
|
},
|
|
"autoload": {
|
|
"files": [
|
|
"lib/public/Log/functions.php"
|
|
],
|
|
"psr-4": {
|
|
"": "lib/private/legacy",
|
|
"OC\\": "lib/private",
|
|
"OC\\Core\\": "core/",
|
|
"OCP\\": "lib/public"
|
|
}
|
|
},
|
|
"require": {
|
|
"ext-json": "*",
|
|
"ext-libxml": "*",
|
|
"ext-mbstring": "*",
|
|
"ext-pdo": "*",
|
|
"ext-simplexml": "*",
|
|
"ext-xmlreader": "*",
|
|
"ext-zip": "*"
|
|
},
|
|
"require-dev": {
|
|
"bamarni/composer-bin-plugin": "^1.4"
|
|
},
|
|
"scripts": {
|
|
"post-install-cmd": [
|
|
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all install",
|
|
"composer dump-autoload"
|
|
],
|
|
"post-update-cmd": [
|
|
"[ $COMPOSER_DEV_MODE -eq 0 ] || composer bin all update --ansi",
|
|
"composer dump-autoload"
|
|
],
|
|
"cs:fix": "php-cs-fixer fix",
|
|
"cs:check": "php-cs-fixer fix --dry-run --diff",
|
|
"lint": "find . -name \\*.php -not -path './lib/composer/*' -not -path './build/stubs/*' -print0 | xargs -0 -n1 php -l",
|
|
"psalm": "psalm --threads=1",
|
|
"psalm:update-baseline": "psalm --threads=1 --update-baseline"
|
|
}
|
|
}
|