Class: Logman
- Inherits:
-
Object
- Object
- Logman
- Defined in:
- lib/logman_rails.rb,
lib/logman_rails/log.rb
Defined Under Namespace
Class Method Summary collapse
-
.error(message, data = {}) ⇒ Object
Sends a error message.
-
.info(message, data = {}) ⇒ Object
Sends a success message.
-
.log(log_type, message, data = {}) ⇒ Object
Writes custom message to logman endpoint Logtype is symbol, avalabile symbols are: Prameters: - log_type => type of log, avalabile types are :error :success :warn :info - message => message in string format - optional data.
- .options ⇒ Object
- .options=(val) ⇒ Object
-
.send(log, endpoint, token) ⇒ Object
end of rails class.
-
.success(message, data = {}) ⇒ Object
Sends a success message.
-
.warn(message, data = {}) ⇒ Object
Sends a warn message.
Class Method Details
.error(message, data = {}) ⇒ Object
Sends a error message
109 110 111 |
# File 'lib/logman_rails.rb', line 109 def self.error(, data={}) Logman.log(:error, ,data) end |
.info(message, data = {}) ⇒ Object
Sends a success message
119 120 121 |
# File 'lib/logman_rails.rb', line 119 def self.info(, data={}) Logman.log(:info, ,data) end |
.log(log_type, message, data = {}) ⇒ Object
Writes custom message to logman endpoint Logtype is symbol, avalabile symbols are:
Prameters:
- log_type => type of log, avalabile types are
:error :success :warn :info
- message => message in string format
- optional data
89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/logman_rails.rb', line 89 def self.log(log_type, , data={}) return if .class != String || .empty? map = {:error=>1, :success=>2, :warn=>3, :info=>4} ltype = map[log_type] ltype = 4 if ltype.nil? #info newlog = Log.new newlog. = newlog.log_type = ltype newlog.data = data Logman.send(newlog, Logman.[:endpoint], Logman.[:token]) end |
.options ⇒ Object
12 13 14 |
# File 'lib/logman_rails.rb', line 12 def self. @@options end |
.options=(val) ⇒ Object
16 17 18 |
# File 'lib/logman_rails.rb', line 16 def self.(val) @@options = val end |
.send(log, endpoint, token) ⇒ Object
end of rails class
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/logman_rails.rb', line 65 def self.send(log, endpoint, token) begin uri = URI(endpoint) uri.path = '/api/write' uri.query = "key=#{token}" req = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'}) req.body = log.to_json res = Net::HTTP.start(uri.hostname, uri.port) do |http| http.request(req) end rescue puts 'Can not send message to logman endpoint' end end |