Python django sentry的轻量级日志记录替代品有哪些?

Python django sentry的轻量级日志记录替代品有哪些?,python,django,sentry,Python,Django,Sentry,对于django环境中的错误日志记录,是否有比django sentry更轻量级的替代方案 我以前使用了django数据库日志,现在称为django哨兵。我发现的其他一些人几乎已经死了,因为他们在过去两年里几乎没有犯过罪 谢谢。哨兵过度杀戮,Djangodblog被弃用,我自己翻滚,从两者中吃掉了必要的部分 它的工作原理是捕捉错误信号。然后,它使用Django的内置异常报告器生成Django在启用调试时显示的奇特500错误页面。我们将其存储在数据库中,并在管理控制台中呈现 以下是我的实现: 型号

对于django环境中的错误日志记录,是否有比django sentry更轻量级的替代方案

我以前使用了
django数据库日志
,现在称为
django哨兵
。我发现的其他一些人几乎已经死了,因为他们在过去两年里几乎没有犯过罪


谢谢。

哨兵过度杀戮,Djangodblog被弃用,我自己翻滚,从两者中吃掉了必要的部分

它的工作原理是捕捉错误信号。然后,它使用Django的内置异常报告器生成Django在启用调试时显示的奇特500错误页面。我们将其存储在数据库中,并在管理控制台中呈现

以下是我的实现:

型号:

class Error(Model):
    """
    Model for storing the individual errors.
    """
    kind = CharField( _('type'),
        null=True, blank=True, max_length=128, db_index=True
    )
    info = TextField(
        null=False,
    )
    data = TextField(
        blank=True, null=True
    )
    path = URLField(
        null=True, blank=True, verify_exists=False,
    )
    when = DateTimeField(
        null=False, auto_now_add=True, db_index=True,
    )
    html = TextField(
        null=True, blank=True,
    )

    class Meta:
        """
        Meta information for the model.
        """
        verbose_name = _('Error')
        verbose_name_plural = _('Errors')

    def __unicode__(self):
        """
        String representation of the object.
        """
        return "%s: %s" % (self.kind, self.info)
管理员:

class ErrorAdmin(admin.ModelAdmin):
    list_display    = ('path', 'kind', 'info', 'when')
    list_display_links = ('path',)
    ordering        = ('-id',)
    search_fields   = ('path', 'kind', 'info', 'data')
    readonly_fields = ('path', 'kind', 'info', 'data', 'when', 'html',)
    fieldsets       = (
        (None, {
            'fields': ('kind', 'data', 'info')
        }),
    )

    def has_delete_permission(self, request, obj=None):
        """
        Disabling the delete permissions
        """
        return False

    def has_add_permission(self, request):
        """
        Disabling the create permissions
        """
        return False

    def change_view(self, request, object_id, extra_context={}):
        """
        The detail view of the error record.
        """
        obj = self.get_object(request, unquote(object_id))

        extra_context.update({
            'instance': obj,
            'error_body': mark_safe(obj.html),
        })

        return super(ErrorAdmin, self).change_view(request, object_id, extra_context)

admin.site.register(Error, ErrorAdmin)
助手:

class LoggingExceptionHandler(object):
    """
    The logging exception handler
    """
    @staticmethod
    def create_from_exception(sender, request=None, *args, **kwargs):
        """
        Handles the exception upon receiving the signal.
        """
        kind, info, data = sys.exc_info()

        if not issubclass(kind, Http404):

            error = Error.objects.create(
                kind = kind.__name__,
                html = ExceptionReporter(request, kind, info, data).get_traceback_html(),
                path = request.build_absolute_uri(),
                info = info,
                data = '\n'.join(traceback.format_exception(kind, info, data)),
            )
            error.save()
初始化:


还有:如果您想要更轻量级的产品,但仍然可以投入生产。

是否有不想使用内置记录器的原因?您需要什么功能?最初我使用的是
django db log
,这很好,因为每次我在站点上出现错误时,我都可以在管理面板中看到错误。我可以按类型、频率等过滤错误。它记录的错误页面是Django在遇到所有堆栈跟踪、内存中的变量、请求参数等异常时显示的默认500错误页面。如果我可以在不编写太多代码和使用Django内部机制的情况下执行同样的操作,那就太好了。希望这是有益的解释。谢谢。你好,Agf和Spacedman,如果您有兴趣,我已经在下面的回答中添加了我的实现。现在,这是PyPi提供的一个包。这个问题和答案激励我也推出我自己的。我已经在生产中使用了一段时间,并最终在pypi上发布了它:对于Django>=1.4,在ModelAdmin的change\u view()方法中添加了一个“form\u url”参数。这意味着上述代码需要稍加修改才能继续工作。在上面的ErrorAdmin类中,在被重写的change_view()方法中,在方法末尾调用super()时,现在应该指定额外的上下文作为关键字参数,如下所示:return super(ErrorAdmin,self).change_view(request,object_id,extra_context=extra_context)
from django.core.signals import got_request_exception

from modules.error.signals import LoggingExceptionHandler

got_request_exception.connect(LoggingExceptionHandler.create_from_exception)