使用数据库进行日志记录 [英] using a database for logging

查看:332
本文介绍了使用数据库进行日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有原因,大多数日志看起来是纯文本,而不是放在MySQL /其他类型的数据库?



将它们放入数据库将使分析更容易,但更容易......但是会牺牲速度还是别的什么?



(我不关心可移植性,显然你会有数据库连接的文本日志。)

解决方案

我可以想到两个大原因: / p>

首先,当简单地将信息附加到文件时,数据库比文本文件慢。使用数据库,您必须建立连接,通过网络传输数据,将其存储在索引结构中等。使用文件,您只需要将错误写出到本地磁盘。



第二,有时您想要记录的事情与数据库断开有关。如果本地磁盘坏了,你会遇到比生成日志文件更大的问题。但是,即使一切正常,您也可以记录数据库中断。



有很多情况下,我想记录的信息只有在应用程序正常工作,当我已经有一个数据库连接。在这种情况下,我直接登录到MySQL。


Is there a reason that most logs seem to be in plain text, as opposed to being put in a MySQL/other sort of database?

It seems to me that putting them into a database would make analysis much, much easier…but would that come at the sacrifice of speed or something else?

(I'm not that concerned with portability, and obviously you'd have text logs for your database connection.)

解决方案

I can think of two big reasons:

First, databases are slower than text files when it comes to simply appending information to a file. With a database, you have to establish a connection, transmit data over the network, store it in an indexed structure, et cetera. With a file, you need only write out the error to local disk.

Second, sometimes the things you want to log pertain to the database being broken. If the local disk is broken, you've got bigger problems than trying to generate log files. But you can log database outages even when everything else is working.

Having said that, there are plenty of situations where the information I want to log is relevant only while the application is properly functioning, and when I already have a database connection. In those cases, I do log directly to MySQL.

这篇关于使用数据库进行日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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