Module: LogInFile
- Defined in:
- lib/log_in_file.rb,
lib/log_in_file/main.rb,
lib/log_in_file/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- LOG_TIME_FORMAT =
'%Y %m %d %H:%M:%S'
- VERSION =
"1.0.0"
Class Method Summary collapse
- .close ⇒ Object
- .find_temporary_folder ⇒ Object
- .formated_message(message, **options) ⇒ Object
- .logfile_folder ⇒ Object
-
.logfile_path ⇒ Object
Log file path.
- .open_log ⇒ Object
- .remove_log ⇒ Object
- .rf ⇒ Object
-
.tmp_folder ⇒ Object
Maybe a temp folder.
- .write(message, **options) ⇒ Object
Class Method Details
.close ⇒ Object
51 52 53 54 55 |
# File 'lib/log_in_file/main.rb', line 51 def close @rf ||= nil rf.close unless @rf.nil? @rf = nil end |
.find_temporary_folder ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'lib/log_in_file/main.rb', line 83 def find_temporary_folder curdir = File.('.') ['tmp','temp','temporary','.tmp'].each do |cname| pth = File.join(curdir, cname) return pth if File.exist?(pth) end return nil end |
.formated_message(message, **options) ⇒ Object
33 34 35 36 37 38 |
# File 'lib/log_in_file/main.rb', line 33 def (, **) s = .dup s = s % [:data] if .key?(:data) s = "--- #{Time.now.strftime(LOG_TIME_FORMAT)} #{s}" return s end |
.logfile_folder ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/log_in_file/main.rb', line 68 def logfile_folder @logfile_folder ||= begin if tmp_folder.nil? File.('.') else tmp_folder end end end |
.logfile_path ⇒ Object
Log file path
64 65 66 |
# File 'lib/log_in_file/main.rb', line 64 def logfile_path @logfile_path ||= File.join(logfile_folder, 'loginfile.log') end |
.open_log ⇒ Object
40 41 42 43 |
# File 'lib/log_in_file/main.rb', line 40 def open_log close `open "#{LogInFile.logfile_path}"` end |
.remove_log ⇒ Object
57 58 59 60 |
# File 'lib/log_in_file/main.rb', line 57 def remove_log close File.delete(logfile_path) if File.exist?(logfile_path) end |
.rf ⇒ Object
45 46 47 48 49 |
# File 'lib/log_in_file/main.rb', line 45 def rf @rf ||= begin File.open(logfile_path, File::APPEND|File::WRONLY|File::CREAT) end end |
.tmp_folder ⇒ Object
Maybe a temp folder
79 80 81 |
# File 'lib/log_in_file/main.rb', line 79 def tmp_folder @tmp_folder ||= find_temporary_folder end |
.write(message, **options) ⇒ Object
28 29 30 31 |
# File 'lib/log_in_file/main.rb', line 28 def write(, **) rf.puts((, **)) return true end |