我如何用Rake为日志文件打时间戳?

问题描述 投票:2回答:1

什么是在Rake任务中连续为日志文件加上时间戳的简单,清晰,简洁的方法?

我看到有一个#timestamp方法;但是,在阅读了它的描述之后,我仍然不确定如何使用它:

#timestamp

而且,我是否有效地使用了timestamp() Time stamp for file creation task. This time stamp is earlier than any other time stamp. file方法?有没有更好的方法?

directory

用法:

require 'time'

task :default => [:timestamp]

directory 'some/path/to'
file 'some/path/to/some.log' => ['some/path/to']
task :timestamp => ['some/path/to/some.log'] do
  File.open('some/path/to/some.log', 'a') do |f|
    f.puts Time.now.iso8601
  end
end
ruby datetime rake
1个回答
0
投票

此时间戳不是您所需要的。瑞克不支持您想要的。您可以通过Debian中可用的“ moreutils”软件包将标准输出传递给“ ts”工具,以添加时间戳。

此方法用于处理文件时间戳。

© www.soinside.com 2019 - 2024. All rights reserved.