Class: UnifiedLogger
- Inherits:
-
ActiveSupport::BufferedLogger
- Object
- ActiveSupport::BufferedLogger
- UnifiedLogger
- Defined in:
- lib/unified-logger.rb
Instance Attribute Summary collapse
-
#log_server ⇒ Object
Returns the value of attribute log_server.
-
#log_server_port ⇒ Object
Returns the value of attribute log_server_port.
-
#log_server_relative_path ⇒ Object
Returns the value of attribute log_server_relative_path.
Instance Method Summary collapse
-
#initialize(client_id, log = "log/#{Rails.env}.log", level = DEBUG) ⇒ UnifiedLogger
constructor
A new instance of UnifiedLogger.
- #send_msg(severity, message = nil, progname = nil, &block) ⇒ Object
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_server ⇒ Object
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_port ⇒ Object
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_path ⇒ Object
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, = nil, progname = nil, &block) return if .nil? return if @level > severity = ( || (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 .chomp! .lstrip! .rstrip! log_hash = { :client_id => @client_id, :log_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 |