Class: ServiceInfo::Logger

Inherits:
Base
  • Object
show all
Defined in:
lib/runit-man/service_info/logger.rb

Overview

Represents information about service on logger-enabled host.

Instance Attribute Summary

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

[], #active?, all, #allowed_signals, #down!, #down?, #files_to_view, #files_to_watch, #initialize, itself_or_parent?, #log_pid, #logged?, #pid, real_data_from_file, #restart!, #run?, #send_signal, #started_at, #stat, #switch_down!, #switch_up!, #switchable?, #symlinks_to_file_paths, #to_hash, #to_json, #up!, #uptime, #urls_to_view, #watched_modified_files

Constructor Details

This class inherits a constructor from ServiceInfo::Base

Instance Method Details

#all_log_file_locationsObject

All log file locations



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/runit-man/service_info/logger.rb', line 50

def all_log_file_locations
  dir_name = log_folder
  return []  if log_folder.nil? || ! File.directory?(dir_name)

  r = []
  Dir.foreach(dir_name) do |subdirname|
    next  if ServiceInfo::Base.itself_or_parent?(subdirname)
    subdirpath = File.expand_path(subdirname, dir_name)
    next  unless File.directory?(subdirpath)

    Dir.foreach(subdirpath) do |filename|
      next  if ServiceInfo::Base.itself_or_parent?(filename)
      filepath = File.expand_path(filename, subdirpath)
      next  unless File.file?(filepath) && File.readable?(filepath)

      label = "#{Utils.host_name}-#{subdirname}-#{filename}"

      stats = File.stat(filepath)
      stat_times = [stats.ctime.utc, stats.mtime.utc]
      min_time, max_time = stat_times.min, stat_times.max

      r << {
        :name     => filename,
        :path     => filepath,
        :subdir   => subdirname,
        :label    => label,
        :size     => stats.size,
        :created  => min_time,
        :modified => max_time
      }
    end
  end

  sorted_file_locations(r)
end

#log_base_folderObject



12
13
14
# File 'lib/runit-man/service_info/logger.rb', line 12

def log_base_folder
  (logger_string =~ /^[^\:]+\:([^\:]+)/) ? $1 : nil
end

#log_file_locationsObject

Current log file locations



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/runit-man/service_info/logger.rb', line 31

def log_file_locations
  folder = log_folder
  return []  if folder.nil? || ! File.directory?(log_folder)

  curdir = File.join(log_folder, Time.now.strftime('%Y-%m-%d'))
  return []  unless File.directory?(curdir)
  r = []
  Dir.foreach(curdir) do |filename|
    next  if ServiceInfo::Base.itself_or_parent?(filename)
    filepath = File.expand_path(filename, curdir)
    next  unless File.file?(filepath) && File.readable?(filepath)

    r << filepath
  end

  r
end

#log_folderObject



16
17
18
19
# File 'lib/runit-man/service_info/logger.rb', line 16

def log_folder
  folder = log_folder_base_name
  (log_base_folder.nil? || folder.nil?) ? folder : File.expand_path(File.join(log_base_folder, folder))
end

#log_folder_base_nameObject



21
22
23
24
25
26
27
28
# File 'lib/runit-man/service_info/logger.rb', line 21

def log_folder_base_name
  result = super

  # we should remove : from the end of the line for logger installations.
  result = $1  if result =~ /^(.+)\:$/

  result
end

#logger_nameObject



8
9
10
# File 'lib/runit-man/service_info/logger.rb', line 8

def logger_name
  (logger_string =~ /^([^\:]+)\:/) ? $1 : logger_string
end

#logger_stringObject



4
5
6
# File 'lib/runit-man/service_info/logger.rb', line 4

def logger_string
  RunitMan::App.runit_logger
end