Sha256: fc48629218271d1a189b1c794a2c51dba4e3780594d47e9b59c2204c1f73d160

Contents?: true

Size: 1.02 KB

Versions: 90

Compression:

Stored size: 1.02 KB

Contents

module ItamaeMitsurin
  module Handler
    class Fluentd < Base
      attr_accessor :fluent_logger # for test

      def initialize(*)
        super
        load_fluent_logger
      end

      def event(type, payload = {})
        super

        unless @fluent_logger.post(type, payload.merge(hostname: hostname))
          ItamaeMitsurin.logger.warn "Sending logs to Fluentd failed: #{@fluent_logger.last_error}"
        end
      end

      private

      def load_fluent_logger
        begin
          require 'fluent-logger'
        rescue LoadError
          raise "Loading fluent-logger gem failed. Please install 'fluent-logger' gem to use fluentd handler."
        end

        @fluent_logger = Fluent::Logger::FluentLogger.new(tag_prefix, host: fluentd_host, port: fluentd_port)
      end

      def tag_prefix
        @options['tag_prefix'] || 'itamae_server'
      end

      def fluentd_host
        @options['host'] || 'localhost'
      end

      def fluentd_port
        (@options['port'] || 24224).to_i
      end
    end
  end
end

Version data entries

90 entries across 47 versions & 1 rubygems

Version Path
itamae-mitsurin-1.0.3 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-1.0.2 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-1.0.1 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-1.0.0 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.50 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.50 test/test_itamae-mitsurin/handler/test_fluentd.rb
itamae-mitsurin-0.49 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.49 test/test_itamae-mitsurin/handler/test_fluentd.rb
itamae-mitsurin-0.48 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.48 test/test_itamae-mitsurin/handler/test_fluentd.rb
itamae-mitsurin-0.47 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.47 test/test_itamae-mitsurin/handler/test_fluentd.rb
itamae-mitsurin-0.46 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.46 test/test_itamae-mitsurin/handler/test_fluentd.rb
itamae-mitsurin-0.45 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.45 test/test_itamae-mitsurin/handler/test_fluentd.rb
itamae-mitsurin-0.44 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.44 test/test_itamae-mitsurin/handler/test_fluentd.rb
itamae-mitsurin-0.43 lib/itamae-mitsurin/handler/fluentd.rb
itamae-mitsurin-0.43 test/test_itamae-mitsurin/handler/test_fluentd.rb