Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. require 'fileutils'
  2.  
  3. module Device
  4. class File
  5.  
  6. def write(message)
  7. open
  8. @io.write(message) #JSON.pretty_generate(message)
  9. @io.write("\n"*2)
  10. close
  11. end
  12.  
  13. def close
  14. @io.close if @io.present?
  15. end
  16.  
  17. def open
  18. unless ::File.exist?(::File.dirname(path))
  19. ::FileUtils.mkdir_p(::File.dirname(path))
  20. end
  21. @io = ::File.open(path, ::File::WRONLY | ::File::APPEND | ::File::CREAT)
  22. @io.binmode
  23. end
  24.  
  25. def path
  26. @path ||= Settings.custom_logger.file_path.presence || Rails.root.join("log/#{Rails.env}.log")
  27. end
  28. end
  29. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement