Class: UnifiedLogger

Inherits:
ActiveSupport::BufferedLogger
  • Object
show all
Defined in:
lib/unified-logger.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client_id, log = "log/#{Rails.env}.log", level = DEBUG) ⇒ UnifiedLogger

Returns a new instance of UnifiedLogger.



9
10
11
12
# File 'lib/unified-logger.rb', line 9

def initialize(client_id, log = "log/#{Rails.env}.log", level = DEBUG)
  super(log, level)
  @client_id = client_id
end

Instance Attribute Details

#log_serverObject

Returns the value of attribute log_server.



5
6
7
# File 'lib/unified-logger.rb', line 5

def log_server
  @log_server
end

#log_server_portObject

Returns the value of attribute log_server_port.



6
7
8
# File 'lib/unified-logger.rb', line 6

def log_server_port
  @log_server_port
end

#log_server_relative_pathObject

Returns the value of attribute log_server_relative_path.



7
8
9
# File 'lib/unified-logger.rb', line 7

def log_server_relative_path
  @log_server_relative_path
end

Instance Method Details

#send_msg(severity, message = nil, progname = nil, &block) ⇒ Object



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
# File 'lib/unified-logger.rb', line 14

def send_msg(severity, message = nil, progname = nil, &block)

  return if message.nil?
  return if @level > severity

  message = (message || (block && block.call) || progname).to_s

  case severity
  when 0
    severity_str = "debug"
  when 1
   severity_str = "info"
  when 2
   severity_str = "warn"
  when 3
   severity_str = "error"
  when 4
   severity_str = "fatal"
  else
   severity_str = "unknown"
  end

  message.chomp!
  message.lstrip!
  message.rstrip!

  log_hash = { :client_id => @client_id, :log_message => message, :log_level => severity_str, :log_time => Time.now }
  loger_hash = { :loger => log_hash }

  RestClient.post("http://#{log_server}:#{log_server_port}/#{log_server_relative_path}", loger_hash.to_json, :content_type => :json)
end