Skip to content

Commit

Permalink
Merge pull request #15376 from NickLaMuro/vmdb_logging_without_autolo…
Browse files Browse the repository at this point in the history
…ading

Allow `lib/vmdb/logging.rb` to be required without needing Rails autoloading
  • Loading branch information
gtanzillo authored Jun 19, 2017
2 parents 2323c7f + 5d9c4ec commit ed707ba
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
9 changes: 5 additions & 4 deletions lib/vmdb/loggers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'manageiq'
require 'util/vmdb-logger'

Dir.glob(File.join(File.dirname(__FILE__), "loggers", "*")).each { |f| require f }

module Vmdb
def self.logger
$log
Expand Down Expand Up @@ -38,10 +37,10 @@ def self.apply_config(config)
private

def self.create_loggers
path_dir = Rails.root.join("log")
path_dir = ManageIQ.root.join("log")

$log = VMDBLogger.new(path_dir.join("evm.log"))
$rails_log = VMDBLogger.new(path_dir.join("#{Rails.env}.log"))
$rails_log = VMDBLogger.new(path_dir.join("#{ManageIQ.env}.log"))
$audit_log = AuditLogger.new(path_dir.join("audit.log"))
$fog_log = FogLogger.new(path_dir.join("fog.log"))
$policy_log = VMDBLogger.new(path_dir.join("policy.log"))
Expand Down Expand Up @@ -80,3 +79,5 @@ def self.apply_config_value(config, logger, key)
end
end
end

Dir.glob(File.join(File.dirname(__FILE__), "loggers", "*")).each { |f| require f }
11 changes: 9 additions & 2 deletions lib/vmdb/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ module Vmdb
class LogProxy < Struct.new(:klass, :separator)
LEVELS = [:debug, :info, :warn, :error]

delegate *LEVELS.map { |level| :"#{level}?" },
:log_backtrace, :level, :to => :logger
# def debug?
# def info?
# def warn?
# def error?
# def log_backtrace
# def level
(LEVELS.map { |l| :"#{l}?" } + [:log_backtrace, :level]).each do |method|
define_method(method) { |*args| logger.send(method, *args) }
end

LEVELS.each do |level|
define_method(level) do |msg = nil, &blk|
Expand Down

0 comments on commit ed707ba

Please sign in to comment.