Class: Imagut::UrlLogger
- Inherits:
-
Object
- Object
- Imagut::UrlLogger
- Defined in:
- lib/imagut/urllogger.rb
Defined Under Namespace
Classes: InitializeError
Instance Method Summary collapse
-
#include?(entry) ⇒ Boolean
return true if entry is included in logdir.
-
#initialize(dir) ⇒ UrlLogger
constructor
dir is a directory to storage logs.
- #write(entry, filename = @dir + (DateTime.now.strftime("/%C%g%m%d.log"))) ⇒ Object
Constructor Details
#initialize(dir) ⇒ UrlLogger
dir is a directory to storage logs.
15 16 17 18 |
# File 'lib/imagut/urllogger.rb', line 15 def initialize(dir) raise InitializeError, "#{dir} not exist" unless File.directory?(dir) @dir = dir end |
Instance Method Details
#include?(entry) ⇒ Boolean
return true if entry is included in logdir.
21 22 23 24 25 26 |
# File 'lib/imagut/urllogger.rb', line 21 def include?(entry) Dir.glob(@dir + "/*.log").each do |file| return true if File.open(file, "r").readlines.map{|i|i.chomp}.include?(entry) end return false end |
#write(entry, filename = @dir + (DateTime.now.strftime("/%C%g%m%d.log"))) ⇒ Object
28 29 30 31 |
# File 'lib/imagut/urllogger.rb', line 28 def write(entry, filename = @dir + (DateTime.now.strftime("/%C%g%m%d.log"))) File.open(filename, "a") { |io| io.puts entry } end |