Class: Anoubis::LogService
- Inherits:
-
Object
- Object
- Anoubis::LogService
- Defined in:
- app/services/anoubis/log_service.rb
Overview
Graylog logging service
Instance Attribute Summary collapse
-
#logger ⇒ Object
GELF::Notifier service.
-
#perm ⇒ Object
Hash of permanent parameters that added before sending data to Graylog server.
Instance Method Summary collapse
-
#facility ⇒ String
Returns Graylog facility identifier in input source.
-
#initialize ⇒ LogService
constructor
Setups basic initialization parameters.
-
#level(type) ⇒ GELF::Levels
Returns GELF::Levels according by type.
-
#log(text, type = 'info', object = nil) ⇒ Object
Send data to Graylog server.
-
#port ⇒ String
Returns Graylog server port.
-
#url ⇒ String
Returns Graylog server URL.
Constructor Details
#initialize ⇒ LogService
Setups basic initialization parameters.
50 51 52 53 54 55 |
# File 'app/services/anoubis/log_service.rb', line 50 def initialize self.logger = GELF::Notifier.new(url, port, 'WAN', { facility: facility }) logger.collect_file_and_line = false logger.rescue_network_errors = true self.perm = {} end |
Instance Attribute Details
#logger ⇒ Object
GELF::Notifier service
5 6 7 |
# File 'app/services/anoubis/log_service.rb', line 5 def logger @logger end |
#perm ⇒ Object
Hash of permanent parameters that added before sending data to Graylog server
7 8 9 |
# File 'app/services/anoubis/log_service.rb', line 7 def perm @perm end |
Instance Method Details
#facility ⇒ String
Returns Graylog facility identifier in input source
38 39 40 41 42 43 44 45 46 |
# File 'app/services/anoubis/log_service.rb', line 38 def facility begin value = Rails.configuration.graylog_facility rescue StandardError value = 'Graylog' end value end |
#level(type) ⇒ GELF::Levels
Returns GELF::Levels according by type
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'app/services/anoubis/log_service.rb', line 83 def level(type) case type when 'debug' return GELF::DEBUG when 'info' return GELF::INFO when 'warn' return GELF::WARN when 'error' return GELF::ERROR end GELF::UNKNOWN end |
#log(text, type = 'info', object = nil) ⇒ Object
Send data to Graylog server
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/services/anoubis/log_service.rb', line 62 def log(text, type = 'info', object = nil) type = 'info' unless %w[info warn error].include? type.downcase loc = caller_locations(1, 1).first data = { short_message: text, level: level(type), line: loc.lineno, file: loc.path } data.merge!(object) if object data.merge!(self.perm) logger.notify data nil end |
#port ⇒ String
Returns Graylog server port
25 26 27 28 29 30 31 32 33 |
# File 'app/services/anoubis/log_service.rb', line 25 def port begin value = Rails.configuration.graylog_port rescue StandardError value = 12201 end value end |
#url ⇒ String
Returns Graylog server URL
12 13 14 15 16 17 18 19 20 |
# File 'app/services/anoubis/log_service.rb', line 12 def url begin value = Rails.configuration.graylog_server rescue StandardError value = '127.0.0.1' end value end |