记录用户活动的最佳做法是什么? [英] What is the best practice for logging users activity?

查看:58
本文介绍了记录用户活动的最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的Web应用( php + js + mysql )实现用户的活动日志记录.

I'd like to implement users' activity logging for my web app (php+js+mysql).

以前,我使用过这种方法:

Previously, I've used this appoach:

  • 在用户登录时,在数据库中创建一个临时表来存储用户ID
  • 使用该临时表中的用户ID为在 activity 表中插入行的所有表创建触发器
  • on users login create a temporary table in the database to store users id
  • create triggers for all tables which insert row in activity table using users id from that temporary table

现在我真的不想在数据库中放置太多逻辑,所以我的问题是:最佳实践是什么?我应该继续使用上述方法,还是应该使用其他方法?

Now I don't really want to put so much logic in the database, so my question is: what is the best practice? Should I stay with the described method, or should I use something else?

编辑1

我看过这个问题,但我很想将上述方法与答案中的一种进行比较.

I've seen this question, but I'm intrested in comparing the described method with one in the answers.

编辑2

我为什么需要日志:如果出现问题,我需要知道应归咎于哪个用户=)

Why do I need logs: I need to know which user to blame if something goes wrong =)

日志必须包含已更改的数据和新数据,以查看实际更改的内容.

Logs have to contain changed data and new data to see what has actually changed.

不会有太多用户,因为它是公司应用程序,而我们公司规模不大.

There won't be many users cause it's a corporate app and our company is not so large.

主要问题是我应该在哪里放置日志记录逻辑:数据库或应用程序(php后端)级别?

The main question is where should I put logging logics: database or application (php backend) level?

推荐答案

和往常一样,取决于".

As always, "it depends".

如果核心业务概念随时间的演变很重要,那么它应该是数据库设计以及PHP逻辑中的一流概念.Fowler在"分析模式"中写道.这使您可以捕获谁对您的业务对象进行了哪些更改,并回答诸如谁在z上将项目从类型x更改为y?",用户x多久更改一次产品y"之类的问题.等等,这确实使域模型更加复杂.

If the evolution over time of your core business concepts is important, it should be a first-class concept in your database design, as well as your PHP logic. Fowler writes about this in "Analysis patterns". This allows you to capture who made which changes to your business objects and answer questions like "who changed the project from type x to y on date z?", "how often did user x change product y?" etc. It does make the domain model more complex.

如果您不需要这种集成级别,我的首选是将日志记录功能放在PHP中;触发器具有降低数据库速度,导致意外副作用或被更改架构的开发人员遗忘的可怕方法.因此,在PHP中,我可能会使用面向方面的框架来包含显式的"log this"语句(尽管我从未在PHP中使用过,仅在Java中使用过).

If you don't need this level of integration, my preference is to put the logging functionality in PHP; triggers have a horrible way of slowing down a database, or leading to unexpected side effects, or being forgotten by developers making changes to the schema. So, in PHP, I'd include explicit "log this" statements, possibly using an aspect-oriented framework (though I've never used that in PHP, only in Java).

这篇关于记录用户活动的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆