Class: Loggly
- Inherits:
-
Object
- Object
- Loggly
- Defined in:
- lib/loggly.rb
Overview
THIS CLASS AS AN ABSTRACT BASE CLASS TO SEND EVENTS TO LOGGLY.COM events on this content are anything that happends in the app. Not an event were people to to have fun
Constant Summary collapse
- @@endpoint =
THIS IS THE ENDPOINT URL FOR LOGGLY
'http://logs.loggly.com/inputs/'
Class Method Summary collapse
-
.async_record(message, time = nil) ⇒ Object
Public.
-
.record(message, time = nil) ⇒ Object
Public This method sends a message to the Loggly API.
-
.send_to_loggly(message, time = nil) ⇒ Object
Private We use this method internally to send messages to loggly.
- .token ⇒ Object
-
.url ⇒ Object
Contructing a full URL.
Class Method Details
.async_record(message, time = nil) ⇒ Object
Public
This method behaves the same as record, but uses resque to send the message.
73 74 75 76 77 78 79 80 81 |
# File 'lib/loggly.rb', line 73 def self.async_record(, time=nil) begin Resque.enqueue(LogglyResque, self.name, , time) rescue => e puts e puts "There was an error cueing loggly" end end |
.record(message, time = nil) ⇒ Object
Public This method sends a message to the Loggly API.
BEAWARE: That Loggle.new is an abstract class and lacks the token to authenticate with loggly. You should subclass loggly and add a method named token that returns a string with the appropiate token. SEE the method token on this class to know more about it
EXAMPLES USAGE: Let’s say you have a class named TicketLoggly that subclasses Loggly.
TicketLoggly.record(“This works”)
You can also send a timestamp. For example:
TicketLoggly.record(“With a Timestamp”, Time.now)
Or you can get creative like:
TicketLoggly.record(Event.last.attributes.to_json ,Time.now )
65 66 67 |
# File 'lib/loggly.rb', line 65 def self.record(, time=nil) self.send_to_loggly(, time) end |
.send_to_loggly(message, time = nil) ⇒ Object
Private
We use this method internally to send messages to loggly.
It is used by the Resque worker and by the record method.
86 87 88 89 90 91 92 93 |
# File 'lib/loggly.rb', line 86 def self.send_to_loggly(, time=nil) begin RestClient.post(self.url, ( + " | Time : " + time.to_s)) rescue => e puts e puts "There was a problem making the HTTP call to Loggly" end end |
.token ⇒ Object
36 37 38 39 40 41 |
# File 'lib/loggly.rb', line 36 def self.token # Add the token in the subclasses. # This method must return a string # The idea is to have a subclass for each of the inputs that we create in loggly # URL to get the token from: https://venuedriver.loggly.com/inputs end |
.url ⇒ Object
Contructing a full URL. It has the endpoint + the token we generate at: venuedriver.loggly.com/inputs
32 33 34 |
# File 'lib/loggly.rb', line 32 def self.url @@endpoint + self.token end |