Class: ErpTechSvcs::Util::CompassLogger

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/erp_tech_svcs/utils/compass_logger.rb

Constant Summary collapse

@@writers =
{}

Class Method Summary collapse

Class Method Details

.app_loggerObject



69
70
71
72
73
74
75
76
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 69

def CompassLogger.app_logger()
  path = File.join(ErpTechSvcs::Config.compass_logger_path, "#{Rails.env rescue 'rake'}.log")
  unless @@writers.has_key?("app_logger")
    logger = Logger.new(path)
    logger.level = CompassLogger.log_level()
    @@writers["app_logger"] = logger
  end
end

.debug(msg) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 9

def CompassLogger.debug(msg)
  if defined?(logger)
    logger.debug(msg)
  else
    CompassLogger.app_logger()
    @@writers["app_logger"].debug(msg)
  end
end

.error(msg) ⇒ Object



36
37
38
39
40
41
42
43
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 36

def CompassLogger.error(msg)
  if defined?(logger)
    logger.error(msg)
  else
    CompassLogger.app_logger()
    @@writers["app_logger"].error(msg)
  end
end

.fatal(msg) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 45

def CompassLogger.fatal(msg)
  if defined?(logger)
    logger.fatal(msg)
  else
    CompassLogger.app_logger()
    @@writers["app_logger"].fatal(msg)
  end
end

.info(msg) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 18

def CompassLogger.info(msg)
  if defined?(logger)
    logger.info(msg)
  else
    CompassLogger.app_logger()
    @@writers["app_logger"].info(msg)
  end
end

.log_levelObject



78
79
80
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 78

def CompassLogger.log_level()
  ActiveRecord::Base.logger.level rescue Logger::DEBUG
end

.log_path(method) ⇒ Object



82
83
84
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 82

def CompassLogger.log_path(method)
  File.join(ErpTechSvcs::Config.compass_logger_path, "#{Rails.env rescue ''}_#{method}.log")
end

.method_missing(method, *args, &block) ⇒ Object



60
61
62
63
64
65
66
67
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 60

def CompassLogger.method_missing(method, *args, &block)
  unless @@writers.has_key?(method)
    logger = Logger.new(CompassLogger.log_path(method))
    logger.level = CompassLogger.log_level()
    @@writers[method] = logger
  end
  @@writers[method]
end

.stdout(msg) ⇒ Object



54
55
56
57
58
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 54

def CompassLogger.stdout(msg)
  if CompassLogger.log_level() == 0
    puts msg
  end
end

.warn(msg) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/erp_tech_svcs/utils/compass_logger.rb', line 27

def CompassLogger.warn(msg)
  if defined?(logger)
    logger.warn(msg)
  else
    CompassLogger.app_logger()
    @@writers["app_logger"].warn(msg)
  end
end