Class: Jfrog::Saas::Log::LogConfig

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/jfrog/saas/log/confighandler.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeLogConfig

Returns a new instance of LogConfig.



67
# File 'lib/jfrog/saas/log/confighandler.rb', line 67

def initialize; end

Instance Attribute Details

#audit_repo_urlObject

Returns the value of attribute audit_repo_url.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def audit_repo_url
  @audit_repo_url
end

#console_loggerObject

Returns the value of attribute console_logger.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def console_logger
  @console_logger
end

#debug_modeObject

Returns the value of attribute debug_mode.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def debug_mode
  @debug_mode
end

#log_file_retention_daysObject

Returns the value of attribute log_file_retention_days.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def log_file_retention_days
  @log_file_retention_days
end

#log_repo_urlObject

Returns the value of attribute log_repo_url.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def log_repo_url
  @log_repo_url
end

#log_ship_configObject

Returns the value of attribute log_ship_config.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def log_ship_config
  @log_ship_config
end

#log_types_enabledObject

Returns the value of attribute log_types_enabled.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def log_types_enabled
  @log_types_enabled
end

#loggerObject

Returns the value of attribute logger.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def logger
  @logger
end

Returns the value of attribute print_with_utc.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def print_with_utc
  @print_with_utc
end

#solutions_enabledObject

Returns the value of attribute solutions_enabled.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def solutions_enabled
  @solutions_enabled
end

#target_log_pathObject

Returns the value of attribute target_log_path.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def target_log_path
  @target_log_path
end

#uri_date_patternObject

Returns the value of attribute uri_date_pattern.



65
66
67
# File 'lib/jfrog/saas/log/confighandler.rb', line 65

def uri_date_pattern
  @uri_date_pattern
end

Class Method Details

.audit_repo_urlObject



41
42
43
# File 'lib/jfrog/saas/log/confighandler.rb', line 41

def self.audit_repo_url
  audit_repo_url
end

.console_loggerObject



21
22
23
# File 'lib/jfrog/saas/log/confighandler.rb', line 21

def self.console_logger
  console_logger
end

.debug_modeObject



49
50
51
# File 'lib/jfrog/saas/log/confighandler.rb', line 49

def self.debug_mode
  debug_mode
end

.log_file_retention_daysObject



61
62
63
# File 'lib/jfrog/saas/log/confighandler.rb', line 61

def self.log_file_retention_days
  log_file_retention_days
end

.log_repo_urlObject



45
46
47
# File 'lib/jfrog/saas/log/confighandler.rb', line 45

def self.log_repo_url
  log_repo_url
end

.log_ship_configObject



25
26
27
# File 'lib/jfrog/saas/log/confighandler.rb', line 25

def self.log_ship_config
  log_ship_config
end

.log_types_enabledObject



33
34
35
# File 'lib/jfrog/saas/log/confighandler.rb', line 33

def self.log_types_enabled
  log_types_enabled
end

.loggerObject



17
18
19
# File 'lib/jfrog/saas/log/confighandler.rb', line 17

def self.logger
  logger
end


57
58
59
# File 'lib/jfrog/saas/log/confighandler.rb', line 57

def self.print_with_utc
  print_with_utc
end

.solutions_enabledObject



29
30
31
# File 'lib/jfrog/saas/log/confighandler.rb', line 29

def self.solutions_enabled
  solutions_enabled
end

.target_log_pathObject



53
54
55
# File 'lib/jfrog/saas/log/confighandler.rb', line 53

def self.target_log_path
  target_log_path
end

.uri_date_patternObject



37
38
39
# File 'lib/jfrog/saas/log/confighandler.rb', line 37

def self.uri_date_pattern
  uri_date_pattern
end

Instance Method Details

#configure(config_file) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/jfrog/saas/log/confighandler.rb', line 69

def configure(config_file)
  config = YAML.load_file(config_file)
  self.target_log_path = (config['log']['target_log_path']).to_s.strip
  log_file = "#{target_log_path}/jfrog-saas-collector.log"
  FileUtils.mkdir_p(target_log_path) unless File.directory? target_log_path
  FileUtils.touch(log_file) unless File.exist? log_file
  self.logger = Logger.new(log_file, 'weekly')
  self.console_logger = Logger.new($stdout)

  console_logger.formatter = logger.formatter = proc do |severity, datetime, progname, msg|
    formatted_date = datetime.strftime('%Y-%m-%d %H:%M:%S')
    "[ #{formatted_date}, p_id=##{Process.pid}, t_id=##{Thread.current.object_id}, #{severity.ljust(5)}] -- #{msg} \n"
  end

  self.log_ship_config = (config['log']['log_ship_config'])
  self.solutions_enabled = config['log']['solutions_enabled'].map(&:strip)
  self.log_types_enabled = config['log']['log_types_enabled'].map(&:strip)
  self.uri_date_pattern = (config['log']['uri_date_pattern']).to_s
  self.audit_repo_url = (config['log']['audit_repo']).to_s.strip
  self.log_repo_url = (config['log']['log_repo']).to_s.strip
  self.debug_mode = (config['log']['debug_mode'])
  self.print_with_utc = (config['log']['print_with_utc'])
  self.log_file_retention_days = if (config['log']['log_file_retention_days']).to_i.positive?
                                   (config['log']['log_file_retention_days']).to_i
                                 else
                                   7
                                 end
end

#to_sObject



98
99
100
# File 'lib/jfrog/saas/log/confighandler.rb', line 98

def to_s
  "Object_id :#{object_id}, solutions_enabled :#{solutions_enabled}, log_types_enabled:#{log_types_enabled}, uri_date_pattern: #{uri_date_pattern}"
end