gpt4 book ai didi

ruby-on-rails-3 - Rails3 自定义日志记录选项?

转载 作者:行者123 更新时间:2023-12-04 07:12:53 26 4
gpt4 key购买 nike

Rails3 的“最佳实践”自定义日志记录选项是什么?任何人都可以建议用于日志记录的好 gem 或技术。

一般来说,自定义、非 Controller 、非模型内容的约定是什么?如果我像这样制作自定义记录器:

#custom_logger.rb
class CustomLogger < Logger
def format_message(severity, timestamp, progname, msg)
"#{msg}\n"
end
end

logfile = File.open(RAILS_ROOT + '/log/custom.log', 'a') #create log file
logfile.sync = true #automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile) #constant accessible anywhere

(从 here 中窃取)应该放在“/lib”中的文件中吗?在“application.rb”中?还是在初始化程序中?

我似乎找不到任何描述这些与以前 Rails 版本的细微差别的内容。

谢谢

最佳答案

这个 gem 非常适合自定义日志输出: https://github.com/johmas/itslog

关于ruby-on-rails-3 - Rails3 自定义日志记录选项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4937396/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com