Skip to content
Permalink
Browse files

initial working code

  • Loading branch information...
dcramer committed May 12, 2008
0 parents commit 3c2e87573d3bd16f61cf08fece0638cc47a4fc22
Showing with 71 additions and 0 deletions.
  1. +35 −0 djangodblog/__init__.py
  2. +36 −0 djangodblog/models.py
@@ -0,0 +1,35 @@
from models import Error, ErrorBatch

import traceback
import socket
import warnings
import md5

class DBLogMiddleware(object):
def process_exception(self, request, exception):
server_name = socket.gethostname()
tb_text = traceback.format_exc()
class_name = exception.__class__.__name__
checksum = md5.new(tb_text).hexdigest()

defaults = dict(
class_name = class_name,
message = exception.message,
url = request.build_absolute_uri(),
server_name = server_name,
traceback = tb_text,
)

try:
Error.objects.create(**defaults)
batch, created = ErrorBatch.objects.get_or_create(
class_name = class_name,
server_name = server_name,
checksum = checksum,
defaults = defaults
)
if not created:
batch.times_seen += 1
batch.save()
except Exception, exc:
warnings.warn(unicode(exc))
@@ -0,0 +1,36 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _

import datetime

class ErrorBatch(models.Model):
class_name = models.CharField(_('Type'), max_length=128)
message = models.TextField()
traceback = models.TextField()
times_seen = models.PositiveIntegerField(default=1)
last_seen = models.DateTimeField(default=datetime.datetime.now)
first_seen = models.DateTimeField(default=datetime.datetime.now)
url = models.URLField(verify_exists=False, null=True, blank=True)
server_name = models.CharField(max_length=128, db_index=True)
checksum = models.CharField(max_length=32, db_index=True)

class Admin:
list_display = ('class_name', 'message', 'last_seen', 'times_seen', 'url', 'server_name')
list_filter = ('class_name', 'times_seen', 'server_name')
ordering = ('-last_seen',)

class Meta:
unique_together = (('class_name', 'server_name', 'checksum'),)

class Error(models.Model):
class_name = models.CharField(_('type'), max_length=128)
message = models.TextField()
traceback = models.TextField()

This comment has been minimized.

Copy link
@JTCunning

JTCunning Nov 7, 2019

Member

TOAST is really going to love dealing with this.

datetime = models.DateTimeField(default=datetime.datetime.now)
url = models.URLField(verify_exists=False, null=True, blank=True)
server_name = models.CharField(max_length=128, db_index=True)

class Admin:
list_display = ('class_name', 'message', 'datetime', 'url', 'server_name')
list_filter = ('class_name', 'datetime', 'server_name')
ordering = ('-datetime',)

10 comments on commit 3c2e875

@dcramer

This comment has been minimized.

Copy link
Member Author

dcramer replied May 14, 2015

From less than 100 lines of code to more than 70,000. Crazy.

@wong2

This comment has been minimized.

Copy link

wong2 replied Jun 24, 2016

absolutely

@jezdez

This comment has been minimized.

Copy link

jezdez replied May 16, 2017

@dcramer Nice!

@mattrobenolt

This comment has been minimized.

Copy link
Member

mattrobenolt replied Nov 1, 2019

👋

@joshuarli

This comment has been minimized.

Copy link
Member

joshuarli replied Nov 6, 2019

From less than 100 lines of code to more than 70,000. Crazy.

@sergiotapia-papa

This comment has been minimized.

Copy link

sergiotapia-papa replied Nov 6, 2019

From less than 100 lines of code to more than 70,000. Crazy.

@petercunha

This comment has been minimized.

Copy link

petercunha replied Nov 6, 2019

From less than 100 lines of code to more than 70,000. Crazy.

@dcramer

This comment has been minimized.

Copy link
Member Author

dcramer replied Nov 6, 2019

$ cloc src
    3761 text files.
    3626 unique files.
Complex regular subexpression recursion limit (32766) exceeded at /usr/local/Cellar/cloc/1.80/libexec/bin/cloc line 9051.
Complex regular subexpression recursion limit (32766) exceeded at /usr/local/Cellar/cloc/1.80/libexec/bin/cloc line 9051.
Complex regular subexpression recursion limit (32766) exceeded at /usr/local/Cellar/cloc/1.80/libexec/bin/cloc line 9051.
     577 files ignored.

github.com/AlDanial/cloc v 1.80  T=11.37 s (280.5 files/s, 67972.1 lines/s)
-------------------------------------------------------------------------------
Language                     files          blank        comment           code
-------------------------------------------------------------------------------
PO File                         67          88514         118280         215919
Python                        1484          30868          21031         117224
JSX                            814          10696           4121          75093
TypeScript                     355           6189           3372          37120
JSON                            82              0              0          18504
LESS                            40           2117            572          12361
HTML                           121            741              2           5423
Lua                              5            260            226           1533
JavaScript                     212             99            542           1117
CSS                              4             67             55            549
Markdown                         2             50              0            151
Bourne Shell                     1              6              0             57
XML                              2              0              0             16
-------------------------------------------------------------------------------
SUM:                          3189         139607         148201         485067
-------------------------------------------------------------------------------
@joshuarli

This comment has been minimized.

Copy link
Member

joshuarli replied Nov 7, 2019

@dcramer 🤔

Oh, it's the translation files.

$ loc src
--------------------------------------------------------------------------------
 Language             Files        Lines        Blank      Comment         Code
--------------------------------------------------------------------------------
 Python                1593       169803        31017         7435       131351
 Jsx                    815        89938        10700         4264        74974
 Typescript JSX         353        46257         6155         3144        36958
 JSON                    86        18528            0            0        18528
 Less                    40        15050         2117          572        12361
 Plain Text              75        10728          149            0        10579
 HTML                   121         6166          741            2         5423
 Lua                      5         2019          260          214         1545
 JavaScript              19         1070           86           91          893
 CSS                      2          661           66           51          544
 reStructuredText         9          351           89            0          262
 TypeScript               2          424           34          227          163
 Markdown                 2          201           50            0          151
 Bourne Shell             1           63            6            0           57
 XML                      2           16            0            0           16
--------------------------------------------------------------------------------
 Total                 3125       361275        51470        16000       293805
--------------------------------------------------------------------------------
@mattrobenolt

This comment has been minimized.

Copy link
Member

mattrobenolt replied Nov 7, 2019

From less than 100 lines of code to more than 70,000. Crazy.

Please sign in to comment.
You can’t perform that action at this time.