mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-16 16:00:17 +02:00
Add function to services.hooks
to provide a concise way for creating loggers for extensions/plugins. Revise basic documentation to use this function.
This commit is contained in:
parent
38aaf545c6
commit
76ebd21163
@ -9,6 +9,29 @@ from allianceauth.hooks import get_hooks
|
|||||||
from .models import NameFormatConfig
|
from .models import NameFormatConfig
|
||||||
|
|
||||||
|
|
||||||
|
def get_extension_logger(name):
|
||||||
|
"""
|
||||||
|
Takes the name of a plugin/extension and generates a child logger of the extensions logger
|
||||||
|
to be used by the extension to log events to the extensions logger.
|
||||||
|
|
||||||
|
The logging level is decided by whether or not DEBUG is set to true in the project settings. If
|
||||||
|
DEBUG is set to false, then the logging level is set to INFO.
|
||||||
|
|
||||||
|
:param: name: the name of the extension doing the logging
|
||||||
|
:return: an extensions child logger
|
||||||
|
"""
|
||||||
|
import logging
|
||||||
|
from django.conf import settings
|
||||||
|
|
||||||
|
logger = logging.getLogger('extensions.' + name)
|
||||||
|
logger.name = name
|
||||||
|
logger.level = logging.INFO
|
||||||
|
if settings.DEBUG:
|
||||||
|
logger.level = logging.DEBUG
|
||||||
|
|
||||||
|
return logger
|
||||||
|
|
||||||
|
|
||||||
class ServicesHook:
|
class ServicesHook:
|
||||||
"""
|
"""
|
||||||
Abstract base class for creating a compatible services
|
Abstract base class for creating a compatible services
|
||||||
|
@ -2,15 +2,13 @@
|
|||||||
Alliance Auth provides a logger for use with custom apps to make everyone's life a little easier.
|
Alliance Auth provides a logger for use with custom apps to make everyone's life a little easier.
|
||||||
|
|
||||||
## Using the Extensions Logger
|
## Using the Extensions Logger
|
||||||
The extensions logger should not be directly used by custom apps as the error messages logged to it
|
AllianceAuth provides a helper function to get the logger for the current module to reduce the amount of
|
||||||
will not be labeled with the correct name. In order to correctly use the extensions logger please follow
|
code you need to write.
|
||||||
the code below.
|
|
||||||
|
|
||||||
```python
|
```python
|
||||||
import logging
|
from allianceauth.services.hooks import get_extension_logger
|
||||||
|
|
||||||
logger = logging.getLogger('extensions.' + __name__)
|
logger = get_extension_logger(__name__)
|
||||||
logger.name = __name__
|
|
||||||
```
|
```
|
||||||
|
|
||||||
This works by creating a child logger of the extension logger which propagates all log entries
|
This works by creating a child logger of the extension logger which propagates all log entries
|
||||||
|
Loading…
x
Reference in New Issue
Block a user