mirror of
https://gitlab.com/allianceauth/allianceauth.git
synced 2025-07-09 20:40:17 +02:00
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
from __future__ import unicode_literals
|
|
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class NotificationHandler(logging.Handler):
|
|
def emit(self, record):
|
|
from django.contrib.auth.models import User, Permission
|
|
from django.db.models import Q
|
|
from notifications import notify
|
|
from notifications.models import Notification
|
|
|
|
try:
|
|
perm = Permission.objects.get(codename="logging_notifications")
|
|
|
|
message = record.getMessage()
|
|
if record.exc_text:
|
|
message += "\n\n"
|
|
message = message + record.exc_text
|
|
|
|
users = User.objects.filter(
|
|
Q(groups__permissions=perm) | Q(user_permissions=perm) | Q(is_superuser=True)).distinct()
|
|
|
|
for user in users:
|
|
notify(
|
|
user,
|
|
"%s [%s:%s]" % (record.levelname, record.funcName, record.lineno),
|
|
level=str([item[0] for item in Notification.LEVEL_CHOICES if item[1] == record.levelname][0]),
|
|
message=message
|
|
)
|
|
except Permission.DoesNotExist:
|
|
pass
|