File: logger.rb

package info (click to toggle)
ruby-httparty 0.13.7-1%2Bdeb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 736 kB
  • sloc: ruby: 4,741; xml: 425; sh: 35; makefile: 11
file content (26 lines) | stat: -rw-r--r-- 701 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require 'httparty/logger/apache_formatter'
require 'httparty/logger/curl_formatter'

module HTTParty
  module Logger
    def self.formatters
      @formatters ||= {
        :curl => Logger::CurlFormatter,
        :apache => Logger::ApacheFormatter
      }
    end

    def self.add_formatter(name, formatter)
      raise HTTParty::Error.new("Log Formatter with name #{name} already exists") if formatters.include?(name)
      formatters.merge!(name.to_sym => formatter)
    end

    def self.build(logger, level, formatter)
      level ||= :info
      formatter ||= :apache

      logger_klass = formatters[formatter] || Logger::ApacheFormatter
      logger_klass.new(logger, level)
    end
  end
end