在数据库中存储日志数据的更好的策略是什么? [英] Whats a better strategy for storing log data in a database?

查看:375
本文介绍了在数据库中存储日志数据的更好的策略是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个需要广泛记录用户,付款等操作的应用程序。

Im building an application that requires extensive logging of actions of the users, payments, etc.

我最好使用单片日志表,只需记录一切或者更好的是为每种类型的动作记录单独的日志表Im logging(log_payment,log_logins,log_acc_changes)?

Am I better off with a monolithic logs table, and just log EVERYTHING into that.... or is it better to have separate log tables for each type of action Im logging (log_payment, log_logins, log_acc_changes)?

例如,当前的Im记录用户与支付网关的交互。当他们注册一个试用版,当试用成为一个订阅,当它被重新装运,退还,如果有失败,等等。

For example, currently Im logging user's interactions with a payment gateway. When they sign up for a trial, when trial becomes a subscription, when it gets rebilled, refunded, if there was a failure or not, etc.

我想还要开始记录与支付网关不进行交互的操作或事件(更新取消,禁止,数据甚至发送到网关进行验证,登录等之前被拦截的付款失败)。

I'd like to also start logging actions or events that dont interact with the payment gateway (renewal cancellations, bans, payment failures that were intercepted before the data is even sent to the gateway for verification, logins, etc).

编辑:
将定期检查数据以验证其完整性,因为基于此,人们将需要支付,所以准确的数据是非常关键的。读取查询将由我自己和另外2个管理员完成,所以99%的时间,它将被写入/更新。

The data will be regularly examined to verify its integrity, since based on it, people will need to be paid, so accurate data is very critical. Read queries will be done by myself and 2 other admins, so 99% of the time, its going to be write/update.

我只是想有多个表,只是在处理插入和更新付款数据等的关键mysql交易中创建更多的失败点。

I just figured having multiple tables, just creates more points of failure during the critical mysql transactions that deal with inserting and updating the payment data, etc.

推荐答案

这取决于记录的目的。对于调试和一般监控目的,具有动态日志级别的单个日志表将是有帮助的,因此您可以按时间顺序查看系统正在进行的操作。

It depends on the purpose of logging. For debugging and general monitoring purpose, a single log table with dynamic log level would be helpful so you can chronologically look at what the system is going through.

另一方面对于审计跟踪目的,对于每个CRUD操作,所有表都没有重复的表。这样,付款表中的每一个信息或任何会在您的审计表中被捕获的信息。

On the other hand, for audit trail purpose, there's nothing like having duplicate table for all tables with every CRUD action. This way, every information captured in the payment table or whatever would be captured in your audit table.

所以答案是两个。

这篇关于在数据库中存储日志数据的更好的策略是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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