Logging user activity

Peter J. Holzer hjp-python at hjp.at
Mon Feb 7 17:09:56 EST 2022


On 2022-02-06 23:30:41 -0800, blessy carol wrote:
> I have this task where I have to create log files to record user
> activity whenever they make an entry or view something. Also, I have
> to create Database log file whenever someone accessed or manipulated
> the data in the database. The code is written python and used django
> framework. I've connected django with oracle cloud database. So now I
> want to if the basic logging details can be used to store the record
> of these activities in the log file in the server.

There are three places where you can do that in a centralized manner:

1. In the database itself. AFAIK Oracle has an audit system, but I've
   never used it.
2. At the Django ORM layer. Django has the ability to log all database
   queries it makes
3. At the web request level. Your web server (probably) already logs
   every request but not necessarily the information you are interested
   in. But you could write a piece of middleware for your Django which
   extracts log-worthy information and logs that.

The first two options are probably too low-level, and especially the
second is really hard to interpret in an automated manner (which is what
you probably want to do - otherwise why log in the first place?)

So I'd try the third option. But it really depends a lot on the
structure of your application on whether it's feasible to extract all
the data you need at that point. It's possible that you will have to go
through all the views in your app, see what data they are requesting and
altering and craft appropriate log messages for each.

        hp

-- 
   _  | Peter J. Holzer    | Story must make more sense than reality.
|_|_) |                    |
| |   | hjp at hjp.at         |    -- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |       challenge!"
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://mail.python.org/pipermail/python-list/attachments/20220207/c29eabec/attachment.sig>


More information about the Python-list mailing list