-
Notifications
You must be signed in to change notification settings - Fork 898
/
loggers.rb
103 lines (91 loc) · 4.6 KB
/
loggers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
require 'manageiq'
require 'util/vmdb-logger'
module Vmdb
def self.logger
$log
end
def self.rails_logger
$rails_log
end
module Loggers
def self.init
return if @initialized
create_loggers
@initialized = true
end
def self.apply_config(config)
apply_config_value(config, $log, :level)
apply_config_value(config, $rails_log, :level_rails)
apply_config_value(config, $ansible_tower_log, :level_ansible_tower)
apply_config_value(config, $api_log, :level_api)
apply_config_value(config, $miq_ae_logger, :level_automation)
apply_config_value(config, $aws_log, :level_aws)
apply_config_value(config, $azure_log, :level_azure)
apply_config_value(config, $cn_monitoring_log, :level_cn_monitoring)
apply_config_value(config, $datawarehouse_log, :level_datawarehouse)
apply_config_value(config, $fog_log, :level_fog)
apply_config_value(config, $kube_log, :level_kube)
apply_config_value(config, $lenovo_log, :level_lenovo)
apply_config_value(config, $nuage_log, :level_nuage)
apply_config_value(config, $policy_log, :level_policy)
apply_config_value(config, $redfish_log, :level_redfish)
apply_config_value(config, $rhevm_log, :level_rhevm)
apply_config_value(config, $scvmm_log, :level_scvmm)
apply_config_value(config, $vcloud_log, :level_vcloud)
apply_config_value(config, $vim_log, :level_vim)
apply_config_value(config, $websocket_log, :level_websocket)
end
def self.create_loggers
path_dir = ManageIQ.root.join("log")
$audit_log = AuditLogger.new(path_dir.join("audit.log"))
$container_log = ContainerLogger.new
$log = create_multicast_logger(path_dir.join("evm.log"))
$rails_log = create_multicast_logger(path_dir.join("#{Rails.env}.log"))
$api_log = create_multicast_logger(path_dir.join("api.log"))
$ansible_tower_log = create_multicast_logger(path_dir.join("ansible_tower.log"))
$miq_ae_logger = create_multicast_logger(path_dir.join("automation.log"))
$aws_log = create_multicast_logger(path_dir.join("aws.log"))
$azure_log = create_multicast_logger(path_dir.join("azure.log"), AzureLogger)
$cn_monitoring_log = create_multicast_logger(path_dir.join("container_monitoring.log"))
$datawarehouse_log = create_multicast_logger(path_dir.join("datawarehouse.log"))
$fog_log = create_multicast_logger(path_dir.join("fog.log"), FogLogger)
$kube_log = create_multicast_logger(path_dir.join("kubernetes.log"))
$lenovo_log = create_multicast_logger(path_dir.join("lenovo.log"))
$nuage_log = create_multicast_logger(path_dir.join("nuage.log"))
$policy_log = create_multicast_logger(path_dir.join("policy.log"))
$redfish_log = create_multicast_logger(path_dir.join("redfish.log"))
$rhevm_log = create_multicast_logger(path_dir.join("rhevm.log"))
$scvmm_log = create_multicast_logger(path_dir.join("scvmm.log"))
$vcloud_log = create_multicast_logger(path_dir.join("vcloud.log"))
$vim_log = create_multicast_logger(path_dir.join("vim.log"))
$websocket_log = create_multicast_logger(path_dir.join("websocket.log"))
configure_external_loggers
end
private_class_method :create_loggers
def self.create_multicast_logger(log_file_path, logger_class = VMDBLogger)
logger_class.new(log_file_path).tap do |logger|
logger.extend(ActiveSupport::Logger.broadcast($container_log)) if ENV["CONTAINER"]
end
end
private_class_method :create_multicast_logger
def self.configure_external_loggers
require 'awesome_spawn'
AwesomeSpawn.logger = $log
require 'log_decorator'
LogDecorator.logger = $log
end
private_class_method :configure_external_loggers
def self.apply_config_value(config, logger, key)
old_level = logger.level
new_level_name = (config[key] || "INFO").to_s.upcase
new_level = VMDBLogger.const_get(new_level_name)
if old_level != new_level
$log.info("MIQ(#{name}.apply_config) Log level for #{File.basename(logger.filename)} has been changed to [#{new_level_name}]")
logger.level = new_level
end
end
private_class_method :apply_config_value
end
end
require_relative "loggers/instrument"
Dir.glob(File.join(File.dirname(__FILE__), "loggers", "*")).each { |f| require f }