B
B
BogBel2015-11-14 16:51:56
Django
BogBel, 2015-11-14 16:51:56

How to implement log logging in Django?

Actually, here's the thing, I want to make a table that will store the user's IP
, URL, HTTP response code.
Intersuet how to call the creation of a new object, well, the actual model, which is necessary for storage.
Thank you.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sim3x, 2015-11-14
@sim3x

You don't have to do that!
check out https://docs.python.org/2/library/logging.html

A
Alexander Pinkevich, 2015-11-14
@pinkevich

As for me, it’s better to create a decorator in which each request will be written to the database and it can be used only for the necessary views, and if you need to write a log of all requests in the project, then it’s better through middleware

A
Artem Klimenko, 2015-11-15
@aklim007

User IP, URL, HTTP response code.

any normal web server will be able to log all these parameters, and it will be faster than logging the same thing through django.
Now, if you need to log more information, and which is difficult/impossible to collect from the web server, you will need to organize this from the Django side.
In my project, there is a similar thing, and we refused to use the logging module in it, because what for it is not needed for our tasks.
There is a separate app that describes:
  • configuration for the database router (access logs are stored in a separate database)
  • Puzzles for Sentry
    1. One task every minute, takes data from the cache, processes it and puts it all at once in the database.
    2. The other pulls once a day a procedure that checks for the presence of partitions in the database for the next month, and if necessary creates them and updates the trigger functions.

    Didn't find what you were looking for?

    Ask your question

    Ask a Question

    731 491 924 answers to any question