server/lib
Christoph Wurst 450136b7cf
Add a helper function that makes it easier to log from anywhere
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>
2022-05-23 09:53:38 +02:00
..
composer Add a helper function that makes it easier to log from anywhere 2022-05-23 09:53:38 +02:00
l10n [tx-robot] updated from transifex 2022-05-23 02:31:03 +00:00
private Merge pull request #32486 from nextcloud/debt/noid/psalm-username 2022-05-20 18:19:53 +02:00
public Add a helper function that makes it easier to log from anywhere 2022-05-23 09:53:38 +02:00
autoloader.php Add a built-in profiler inside Nextcloud 2022-04-04 10:28:26 +02:00
base.php Merge pull request #32427 from nextcloud/boot-event-ordering 2022-05-17 11:55:00 +00:00
versioncheck.php Drop PHP7.3 2022-01-25 17:25:08 +01:00