Rails 3 中的自定义记录器? [英] Custom logger in Rails 3?

查看:38
本文介绍了Rails 3 中的自定义记录器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用程序创建一个自定义记录器,当然它会记录到不同的文件,有人问了一个问题:在 rails 3 中设置记录器

I want to have a custom logger for my application, which of course logs to a different file, someone asked a question: Setting up the logger in rails 3

但我想要一个记录器,我可以用我自己的类名调用它,例如:

But I want to have a logger which I can call with my own class name like:

StatusLogger.info "something happend!!!"

我该怎么做?

推荐答案

你可以用这段代码做到这一点

You could do that with this code

logfile = File.open('/path/to/log.log', 'a')  
StatusLogger = Logger.new(logfile)
StatusLogger.info 'Hello World!'

而且您很可能会在初始化文件中配置它,或者如果您愿意,也可以在环境文件中进行配置.

And you would most likely configure this in an initializer file, or you could do it in an environment file if you wanted.

这篇关于Rails 3 中的自定义记录器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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