Class: Hatchet::HipChatAppender
- Inherits:
-
Object
- Object
- Hatchet::HipChatAppender
- Includes:
- LevelManager
- Defined in:
- lib/hatchet-hipchat/hipchat_appender.rb
Overview
Public: Class for sending log messages to a HipChat room.
API reference: www.hipchat.com/docs/api/method/rooms/message
Constant Summary collapse
- CLIENT =
Internal: The class to use to create HipChat clients.
HipChat::API
- COLOR_MAP =
Internal: Map for log level to message color.
{ :debug => 'gray', :info => 'gray', :warn => 'yellow', :error => 'red', :fatal => 'red' }
Instance Attribute Summary collapse
-
#api_token ⇒ Object
Public: The API token to use to connect to HipChat’s API.
-
#formatter ⇒ Object
Public: The formatter used to format messages before sending them to the HipChat room.
-
#name ⇒ Object
Public: The name to post the messages as (default: Hatchet).
-
#room_id ⇒ Object
Public: The ID of the room to send messages to.
Instance Method Summary collapse
-
#add(level, context, message) ⇒ Object
Internal: Sends a message to HipChat.
-
#client ⇒ Object
Internal: Returns the client used to send messages to HipChat.
-
#initialize {|_self| ... } ⇒ HipChatAppender
constructor
Public: Creates a new instance.
Constructor Details
#initialize {|_self| ... } ⇒ HipChatAppender
Public: Creates a new instance.
By default the appender is created with a SimpleFormatter.
block - Optional block that can be used to customize the appender. The
appender itself is passed to the block.
48 49 50 51 52 |
# File 'lib/hatchet-hipchat/hipchat_appender.rb', line 48 def initialize @name = 'Hatchet' @formatter = SimpleFormatter.new yield self if block_given? end |
Instance Attribute Details
#api_token ⇒ Object
Public: The API token to use to connect to HipChat’s API.
31 32 33 |
# File 'lib/hatchet-hipchat/hipchat_appender.rb', line 31 def api_token @api_token end |
#formatter ⇒ Object
Public: The formatter used to format messages before sending them to the HipChat room.
27 28 29 |
# File 'lib/hatchet-hipchat/hipchat_appender.rb', line 27 def formatter @formatter end |
#name ⇒ Object
Public: The name to post the messages as (default: Hatchet).
39 40 41 |
# File 'lib/hatchet-hipchat/hipchat_appender.rb', line 39 def name @name end |
#room_id ⇒ Object
Public: The ID of the room to send messages to.
35 36 37 |
# File 'lib/hatchet-hipchat/hipchat_appender.rb', line 35 def room_id @room_id end |
Instance Method Details
#add(level, context, message) ⇒ Object
Internal: Sends a message to HipChat.
level - The level of the message. context - The context of the message. message - The unformatted message.
Returns nothing.
62 63 64 65 |
# File 'lib/hatchet-hipchat/hipchat_appender.rb', line 62 def add(level, context, ) = @formatter.format(level, context, ) client. @room_id, @name, , 0, COLOR_MAP[level], 'text' end |