Class: FetchUtil::RequestLog
- Inherits:
-
Object
- Object
- FetchUtil::RequestLog
- Defined in:
- lib/fetch_util/request_log.rb
Constant Summary collapse
- DEFAULT_PATH =
File.("~/.local/state/fetch_util/requests.log")
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #append(entry, duration: nil) ⇒ Object
-
#initialize(path: ENV.fetch("FETCH_UTIL_REQUEST_LOG", DEFAULT_PATH)) ⇒ RequestLog
constructor
A new instance of RequestLog.
Constructor Details
#initialize(path: ENV.fetch("FETCH_UTIL_REQUEST_LOG", DEFAULT_PATH)) ⇒ RequestLog
Returns a new instance of RequestLog.
10 11 12 |
# File 'lib/fetch_util/request_log.rb', line 10 def initialize(path: ENV.fetch("FETCH_UTIL_REQUEST_LOG", DEFAULT_PATH)) @path = path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
14 15 16 |
# File 'lib/fetch_util/request_log.rb', line 14 def path @path end |
Instance Method Details
#append(entry, duration: nil) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/fetch_util/request_log.rb', line 16 def append(entry, duration: nil) FileUtils.mkdir_p(File.dirname(path)) line = "#{Time.now.utc.iso8601}\t#{entry}" line = "#{line}\t#{format("%.2f", duration)}s" if duration File.open(path, "a") { |file| file.puts(line) } path end |