Class: Apitool::Client::Logger

Inherits:
Logger
  • Object
show all
Defined in:
lib/apitool/client/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.archiveObject



40
41
42
# File 'lib/apitool/client/logger.rb', line 40

def self.archive
  %x(gzip -c #{file_path} > #{targz_file_path})
end

.buildObject



28
29
30
# File 'lib/apitool/client/logger.rb', line 28

def self.build
  new(Rails.root.join("log", file_name))
end

.clearObject



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(message)
  build.debug(message)
end

.error(message) ⇒ Object



3
4
5
# File 'lib/apitool/client/logger.rb', line 3

def self.error(message)
  build.error(message)
end

.file_nameObject



32
33
34
# File 'lib/apitool/client/logger.rb', line 32

def self.file_name
  file_name_noext + '.log'
end

.file_name_noextObject



77
78
79
# File 'lib/apitool/client/logger.rb', line 77

def self.file_name_noext
  "apitool_client"
end

.file_pathObject



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(message)
  build.info(message)
end

.read_latestObject



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

.sizeObject



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_pathObject



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 format_message(severity, timestamp, progname, msg)
  "#{severity} : #{timestamp.strftime("%y-%m-%d %H:%M:%S:%L %z")} : #{msg}\n"
end