Class: Lita::Handlers::Logger

Inherits:
Handler
  • Object
show all
Defined in:
lib/lita/handlers/logger.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_config(config) ⇒ Object



8
9
10
11
# File 'lib/lita/handlers/logger.rb', line 8

def self.default_config(config)
  config.log_file = nil
  config.enable_http_log = false
end

Instance Method Details

#chat_log(request, response) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/lita/handlers/logger.rb', line 27

def chat_log(request, response)
  if !Lita.config.handlers.logger.log_file || !Lita.config.handlers.logger.enable_http_log
    return
  end

  response.headers["Content-Type"] = "text/plain"

  File.open(Lita.config.handlers.logger.log_file, "r") do |f|
    response.write f.read
  end
end

#logger(response) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/lita/handlers/logger.rb', line 17

def logger(response)
  if !Lita.config.handlers.logger.log_file || response.message.source.private_message || !response.message.body
    return
  end

  File.open(Lita.config.handlers.logger.log_file, 'a') do |f|
    f.puts "[#{Time.now}] [#{response.user.name} in #{response.message.source.room}] #{response.message.body}"
  end
end