python 日志文件的合适大小(以字节为单位)是多少?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1521082/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is a good size (in bytes) for a log file?
提问by Isaiah
I am using the python loggingmodules RotatingFileHandler, and you can set the maximum size of each log file. What is a good maximum size for a log file? Please give your answer in bytes.
我正在使用 python日志模块RotatingFileHandler,您可以设置每个日志文件的最大大小。日志文件的最佳最大大小是多少?请以字节为单位给出答案。
采纳答案by codeape
My default logging setup:
我的默认日志设置:
RotatingFileHandler(filename, maxBytes=10*1024*1024, backupCount=5)
回答by Colin Pickard
As the other answers have said, there is a no hard and fast answer. It depends so much on your app and your environment. Here's some guidelines I use.
正如其他答案所说,没有一成不变的答案。这在很大程度上取决于您的应用程序和环境。这是我使用的一些准则。
For a multi-user app on a typical server: Configure your logging to generate no more than 1 or 2 entries per user action for production, and then rotate it daily. Keep as many days as you have disk space for, or your data retention/privacy policies allow for. If you want auditing, you probably want a separate solution.
对于典型服务器上的多用户应用程序:将日志配置为针对生产的每个用户操作生成不超过 1 或 2 个条目,然后每天轮换它。保留尽可能多的磁盘空间,或您的数据保留/隐私政策允许。如果您想要审计,您可能需要一个单独的解决方案。
For a single-user app: Try and keep enough information to diagnose anything weird that might happen. No more than 2 or 3 entries per user action though, unless you are doing batch operations. Don't put more than 2MB in a file, so the user can email it you. Don't keep more than 50MB of logs, because it's probably not your space you are wasting here.
对于单用户应用程序:尝试保留足够的信息来诊断可能发生的任何奇怪的事情。除非您进行批处理操作,否则每个用户操作不超过 2 或 3 个条目。不要在文件中放入超过 2MB 的文件,以便用户可以通过电子邮件将其发送给您。不要保留超过 50MB 的日志,因为这可能不是您在这里浪费的空间。
回答by Chris Ballance
Size isn't as important to me as dividing at sensible chronological points. I prefer one log file per day, however, if the file won't open with any notepad program you have at your disposal, it is too big and you might want to go with hourly logs.
大小对我来说并不像在合理的时间点上划分那么重要。我更喜欢每天一个日志文件,但是,如果该文件无法使用您可以使用的任何记事本程序打开,则它太大了,您可能需要使用每小时日志。
回答by Mark Rushakoff
It completely depends on the external variables of the system. For instance:
它完全取决于系统的外部变量。例如:
- Are you running on an embedded device whose only external storage is a 1MB SD card, or do you have full access to a 1TB hard drive?
- Are you logging each time you enter/exit a function, or are you only logging one or two caught exceptions throughout the whole system?
- Is the purpose of these logs to be sent back to the developer for support? A 1kb log file isn't going to help you much, but you probably don't need 200MB of logs for a single support issue.
- 您是否在仅外部存储为 1MB SD 卡的嵌入式设备上运行,或者您是否可以完全访问 1TB 硬盘?
- 您是在每次进入/退出函数时都进行记录,还是在整个系统中只记录一两个捕获的异常?
- 这些日志的目的是发回给开发人员以获得支持吗?1kb 的日志文件不会对您有多大帮助,但您可能不需要 200MB 的日志来解决单个支持问题。
Without these kinds of details, there is no good answer to your question (and there might not be a good answer even withthese details).
没有这些细节,你的问题就没有好的答案(即使有这些细节也可能没有好的答案)。