Module: Log
- Included in:
- Instabot
- Defined in:
- lib/instabot/logger.rb
Instance Method Summary collapse
- #check_log_files ⇒ Object
- #log(text = '', from = '', logs_status = ) ⇒ Object
- #save_action_log(id = 0, type = :default) ⇒ Object
- #write_file(filename, text = '') ⇒ Object
Instance Method Details
#check_log_files ⇒ Object
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/instabot/logger.rb', line 2 def check_log_files puts 'PROCESSING: '.cyan.bold + 'checking log files' log('checking log files', 'LOGGER') unless File.exists?(@logs_dir) Dir.mkdir(@logs_dir) end if [:pre_load] if Dir.exists?('./logs') files = %w[commented_medias followed_users liked_medias unliked_medias unfollowed_users] files.each do |file| if File.exists?("./logs/#{file}.txt") File.open("./logs/#{file}.txt", 'r+') do |buffer| data = buffer.read.split(',') @local_stroage[file.to_sym] = data end end end end end end |
#log(text = '', from = '', logs_status = ) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/instabot/logger.rb', line 29 def log(text = '', from = '', logs_status=[:log_status]) if logs_status time = Time.new.strftime('%H:%M:%S %y-%m-%d') if File.exists?(@logs_dir) File.open("#{@logs_dir}/logs-#{@started_time}.log", 'a+') do |log_file| log_file.puts "[#{@log_counter}] [#{time}] [#{from}] -- : #{text}" end else Dir.mkdir(@logs_dir) end @log_counter += 1 end end |
#save_action_log(id = 0, type = :default) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/instabot/logger.rb', line 43 def save_action_log(id = 0, type = :default) case type when :follow write_file('followed_users.txt', id) when :unfollow write_file('unfollowed_users.txt', id) when :like write_file('liked_medias.txt', id) when :unlike write_file('unliked_medias.txt', id) when :comment write_file('commented_medias.txt', id) when :default puts 'please choose a type' else puts 'please choose a type' end end |
#write_file(filename, text = '') ⇒ Object
25 26 27 |
# File 'lib/instabot/logger.rb', line 25 def write_file(filename, text = '') File.open("#{@logs_dir}/#{filename}", 'a+') { |f| f.print "#{text.chomp}," } end |