Skip to main content

A simple Django app to register log and save them.

Project description

Log Register Documentation

Leandro Gomez <>
:Version: 0.0.3


pip install django-log-register==0.0.3

Django Log Register is a simple application for Django.
It's a simple way to save this error, warning, success, info, and debug log; everything in database.
You can reference to another model in database, to be able to know who makes you system fails.

``Lot``: It's a lot of logs where you can register error, warning, info, debug or success logs (See details below).
``Log``: This is a error, a warning or another message level (by default the same of django message) with the reason.


Suppose that you want to register each successful creation of a model, or its fail if it's not created

creation_logs = Lot()
for n in range(10):
obj = SomeModel(attr=1, attr=2)
creation_logs.success("A obj has been created!") #Only the reason param is required!
except Exception as e:
creation_logs.error("A obj has not been created!")
creation_logs.close() #Don't forget to close the Lot, this can indicate you if the process finished fine.

Now suppose the same context, but you want the real exception and some context to can find a solution.

creation_logs = Lot()
for n in range(10):
attr1 = some_calculated_value()
attr2 = 20
obj = SomeModel(attr1=attr1, attr2=attr2)
"A obj has been created!",
"with attr1=%(attr1)s and attr2=%(attr2)s" % dict(attr1=attr1, attr2=attr2)
) #You can add some extra_data if you wish or need it

except Exception as e:
context = "attr1=%(attr1)s and attr2=%(attr2)s" % dict(attr1=attr1, attr2=attr2)
creation_logs.error(str(e), context)
#make a str(e) is my favourite way to register a error log, and let the extra_data provide me
# what I need to solve the problem.

Now suppose that you are updating many instances of models, and can register which model update has fail.

creation_logs = Lot()
for id in range(5):
obj = MyModel.objects.get(id=id)
creation_logs.success("A obj has been update!")
except SomeException as e:
context = "model=%(model)s and id=%(id)s" % dict(model=model, id=id)
if 'obj' in locals()::
creation_logs.error(str(e), context, log_object=obj)
creation_logs.error(str(e), context)

But you maybe want to even logs for a object in the same Lot; so... you can make this:

from lot_register.actions import get_lot_for_objects

obj1 = MyModel()
onj2 = MySecondModel()

lot = get_lot_for_objects(obj1)

# make something with obj1 and obj2
lot.log("I make something with my obj1 with another obj2!!", "some extra data",log_object=obj2)
lot.error("Something went wrong", log_object=obj2)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-log-register-0.0.3.tar.gz (7.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page