Sha256: 8b0002820aad57ce8543a81f4fa91cc4d12de7e6e98d8c3bd40ab36995468489

Contents?: true

Size: 823 Bytes

Versions: 1

Compression:

Stored size: 823 Bytes

Contents

require_relative "../base"

module Rsg
  module Logging
    class LogrageGenerator < Rsg::Generators::Base
      def self.source_root
        Pathname.new(__FILE__).dirname.join("templates").expand_path
      end

      def banner
        say "Configuring lograge with JSON logging"
      end

      def add_lograge
        append_gem "lograge", install: false
        append_gem "logstash-event", after: "lograge"
      end

      def initializer
        copy_file "initializer_lograge.rb", "config/initializers/logging.rb"
      end

      def json_logs_env_var
        inject_into_file "config/application.rb", <<-CODE, before: /^  end$/
\n    # Enable JSON logs with lograge
    config.x.json_logs = Rails.env.production? || %w[1 true yes].include?(ENV.fetch('JSON_LOGS', '0'))
        CODE
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rsg-0.0.1 lib/rsg/generators/logging/lograge_generator.rb