Class: Termite::HasturLogger
- Inherits:
-
Object
- Object
- Termite::HasturLogger
- Defined in:
- lib/termite/hastur_logger.rb
Instance Method Summary collapse
-
#initialize(socket, addr, port, labels) ⇒ HasturLogger
constructor
A new instance of HasturLogger.
- #send_message(severity, raw_message, app_data, time = Time.now, data = '{}') ⇒ Object
- #to_usec(time) ⇒ Object
Constructor Details
#initialize(socket, addr, port, labels) ⇒ HasturLogger
Returns a new instance of HasturLogger.
3 4 5 6 |
# File 'lib/termite/hastur_logger.rb', line 3 def initialize(socket, addr, port, labels) @socket, @addr, @port = socket, addr, port @labels = labels || {} end |
Instance Method Details
#send_message(severity, raw_message, app_data, time = Time.now, data = '{}') ⇒ Object
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 |
# File 'lib/termite/hastur_logger.rb', line 12 def (severity, , app_data, time=Time.now, data='{}') severity = Logger::LOGGER_LEVEL_MAP.invert[severity].to_s tid = Ecology.thread_id(::Thread.current) hostname = Socket.gethostname pid = Process.pid application, component = app_data[:app], app_data[:component] = { :_route => :log, :timestamp => to_usec(time), :message => } labels = { :severity => severity, :pid => pid, :tid => tid, :app => application, :component => component, :hostname => hostname } labels.merge!(MultiJson.decode(data)) if data && data != '{}' labels.merge!(@labels) if @labels && !@labels.empty? [:labels] = labels @socket.send MultiJson.encode(), 0, @addr, @port end |
#to_usec(time) ⇒ Object
8 9 10 |
# File 'lib/termite/hastur_logger.rb', line 8 def to_usec(time) (time.to_f * 1_000_000).round end |