Class: Apitool::Client::Logger
- Inherits:
-
Logger
- Object
- Logger
- Apitool::Client::Logger
- Defined in:
- lib/apitool/client/logger.rb
Class Method Summary collapse
- .archive ⇒ Object
- .build ⇒ Object
- .clear ⇒ Object
- .debug(message) ⇒ Object
- .error(message) ⇒ Object
- .file_name ⇒ Object
- .file_name_noext ⇒ Object
- .file_path ⇒ Object
- .info(message) ⇒ Object
- .read_latest ⇒ Object
- .read_latest_for(filename) ⇒ Object
- .size ⇒ Object
- .targz_file_path ⇒ Object
Instance Method Summary collapse
Class Method Details
.archive ⇒ Object
40 41 42 |
# File 'lib/apitool/client/logger.rb', line 40 def self.archive %x(gzip -c #{file_path} > #{targz_file_path}) end |
.build ⇒ Object
28 29 30 |
# File 'lib/apitool/client/logger.rb', line 28 def self.build new(Rails.root.join("log", file_name)) end |
.clear ⇒ Object
44 45 46 |
# File 'lib/apitool/client/logger.rb', line 44 def self.clear %x(echo > #{file_path}) end |
.debug(message) ⇒ Object
11 12 13 |
# File 'lib/apitool/client/logger.rb', line 11 def self.debug() build.debug() end |
.error(message) ⇒ Object
3 4 5 |
# File 'lib/apitool/client/logger.rb', line 3 def self.error() build.error() end |
.file_name ⇒ Object
32 33 34 |
# File 'lib/apitool/client/logger.rb', line 32 def self.file_name file_name_noext + '.log' end |
.file_name_noext ⇒ Object
77 78 79 |
# File 'lib/apitool/client/logger.rb', line 77 def self.file_name_noext "apitool_client" end |
.file_path ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/apitool/client/logger.rb', line 61 def self.file_path if Rails.root.present? Rails.root.join("log", file_name).to_s else [Dir.pwd, "log", file_name].join("/").to_s end end |
.info(message) ⇒ Object
7 8 9 |
# File 'lib/apitool/client/logger.rb', line 7 def self.info() build.info() end |
.read_latest ⇒ Object
15 16 17 18 19 20 |
# File 'lib/apitool/client/logger.rb', line 15 def self.read_latest path = Rails.root.join("log", file_name) self.build unless File.exist?(path) tail_output, _ = Manager::Popen.popen(%W(tail -n 2000 #{path})) tail_output.split("\n") end |
.read_latest_for(filename) ⇒ Object
22 23 24 25 26 |
# File 'lib/apitool/client/logger.rb', line 22 def self.read_latest_for filename path = Rails.root.join("log", filename) tail_output, _ = Manager::Popen.popen(%W(tail -n 2000 #{path})) tail_output.split("\n") end |
.size ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/apitool/client/logger.rb', line 48 def self.size if File.exist?(file_path) File.new(file_path).size else 0 end end |
.targz_file_path ⇒ Object
56 57 58 59 |
# File 'lib/apitool/client/logger.rb', line 56 def self.targz_file_path targz_file_name = "#{file_name}-" + %x(date "+%Y%m%d_%H%M%S").gsub("\n", '') + ".gz" Rails.root.join("log", targz_file_name).to_s end |
Instance Method Details
#format_message(severity, timestamp, progname, msg) ⇒ Object
36 37 38 |
# File 'lib/apitool/client/logger.rb', line 36 def (severity, , progname, msg) "#{severity} : #{.strftime("%y-%m-%d %H:%M:%S:%L %z")} : #{msg}\n" end |