Ruby - 确保 Syslog 关闭
使用完 Syslog 后关闭 Syslog 是否绝对重要? 不这样做会带来巨大的负面影响吗?
如果事实证明我确实需要这样做,那么有什么好方法呢? 我在类构造函数中打开 Syslog,但没有找到在 Ruby 中执行类析构函数的方法,目前有类似以下内容:
class Foo
def initialize
@@log = Syslog.open("foo")
end
end
我没有立即看到 Syslog.close
应该打电话,但是你推荐什么?
Is it absolutely critical that I always close Syslog when I'm done using it? Is there a huge negative impact from not doing so?
If it turns out that I definitely need to, what's a good way to do it? I'm opening Syslog in my class constructor and I don't see a way to do class destructors in Ruby, and currently have something resembling this:
class Foo
def initialize
@@log = Syslog.open("foo")
end
end
I don't immediately see the place where the Syslog.close
call should be, but what do you recommend?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
open 方法接受一个块。 做这样的事情:
The open method accepts a block. Do something like this:
看起来您将其作为类变量打开...所以正确的方法是...
尽管这不一定是可预测或支持的。 如果您要按照自己的方式保留代码,那么这就是执行此操作的方法。
It looks like you're opening it as a class variable... so the proper way would be to do...
Though this is not necesssarily predictable or supported. It's the way to do it if you're going to keep the code the way you do.