<commit_before>require 'rollbar/configuration'
require 'rollbar/lazy_store'
require 'rollbar/util'
require 'rollbar/json'
require 'rollbar/exceptions'
require 'rollbar/language_support'
require 'rollbar/delay/girl_friday'
require 'rollbar/delay/thread'
require 'rollbar/logger_proxy'
require 'rollbar/item'
require 'rollbar/notifier/trace_with_bindings'
require 'ostruct'

module Rollbar
  # The notifier class. It has the core functionality
  # for sending reports to the API.
  class Notifier
    attr_accessor :configuration
    attr_accessor :last_report
    attr_accessor :scope_object

    MUTEX = Mutex.new
    EXTENSION_REGEXP = /.rollbar\z/.freeze

    def initialize(parent_notifier = nil, payload_options = nil, scope = nil)
      if parent_notifier
        self.configuration = parent_notifier.configuration.clone
        self.scope_object = parent_notifier.scope_object.clone

        Rollbar::Util.deep_merge(scope_object, scope) if scope
      else
        self.configuration = ::Rollbar::Configuration.new
        self.scope_object = ::Rollbar::LazyStore.new(scope)
      end

      Rollbar::Util.deep_merge(configuration.payload_options, payload_options) if payload_options
    end

    def reset!
      self.scope_object = ::Rollbar::LazyStore.new({})
    end

    # Similar to configure below, but used only internally within the gem
    # to configure it without initializing any of the third party hooks
    def preconfigure
      yield(configuration.configured_options)
    end

    # Configures the notifier instance
    def configure
      configuration.enabled = true if configuration.enabled.nil?

      yield(configuration.configured_options)
    end

    def reconfigure
      self.configuration = Configuration.new
      configuration.enabled = true

      yield(configuration.configured_options)
    end

    def unconfigure
      self.configuration = nil
    end

    def scope(scope_overrides = {}, config_overrides = {})
      new_notifier = self.class.new(self, nil, scope_overrides)
      new_notifier.configuration = configuration.merge(config_overrides)

      new_notifier
    end

    def scope!(options = {}, config_overrides = {})
      Rollbar::Util.deep_merge(scope_object, options)
      configuration.merge!(config_overrides)

      self
    end

    # Returns a new notifier with same configuration options
    # but it sets Configuration#safely to true.
    # We are using this flag to avoid having inifite loops
    # when evaluating some custom user methods.
    def safely
      new_notifier = scope
      new_notifier.configuration.safely = true

      new_notifier
    end

    # Turns off reporting for the given block.
    #
    # @example
    #   Rollbar.silenced { raise }
    #
    # @yield Block which exceptions won't be reported.
    def silenced
      yield
    rescue StandardError => e
      e.instance_variable_set(:@_rollbar_do_not_report, true)
      raise
    end

    # Sends a report to Rollbar.
    #
    # Accepts any number of arguments. The last String argument will become
    # the message or description of the report. The last Exception argument
    # will become the associated exception for the report. The last hash
    # argument will be used as the extra data for the report.
    #
    # If the extra hash contains a symbol key :custom_data_method_context
    # the value of the key will be used as the context for
    # configuration.custom_data_method and will be removed from the extra
    # hash.
    #
    # @example
    #   begin
    #     foo = bar
    #   rescue => e
    #     Rollbar.log(e)
    #   end
    #
    # @example
    #   Rollbar.log('This is a simple log message')
    #
    # @example
    #   Rollbar.log(e, 'This is a description of the exception')
    #
    def log(level, *args)
      return 'disabled' unless enabled?

      message, exception, extra, context = extract_arguments(args)
      use_exception_level_filters = use_exception_level_filters?(extra)
<commit_msg>doc: fix code comment to use level argument in examples<commit_after>require 'rollbar/configuration'
require 'rollbar/lazy_store'
require 'rollbar/util'
require 'rollbar/json'
require 'rollbar/exceptions'
require 'rollbar/language_support'
require 'rollbar/delay/girl_friday'
require 'rollbar/delay/thread'
require 'rollbar/logger_proxy'
require 'rollbar/item'
require 'rollbar/notifier/trace_with_bindings'
require 'ostruct'

module Rollbar
  # The notifier class. It has the core functionality
  # for sending reports to the API.
  class Notifier
    attr_accessor :configuration
    attr_accessor :last_report
    attr_accessor :scope_object

    MUTEX = Mutex.new
    EXTENSION_REGEXP = /.rollbar\z/.freeze

    def initialize(parent_notifier = nil, payload_options = nil, scope = nil)
      if parent_notifier
        self.configuration = parent_notifier.configuration.clone
        self.scope_object = parent_notifier.scope_object.clone

        Rollbar::Util.deep_merge(scope_object, scope) if scope
      else
        self.configuration = ::Rollbar::Configuration.new
        self.scope_object = ::Rollbar::LazyStore.new(scope)
      end

      Rollbar::Util.deep_merge(configuration.payload_options, payload_options) if payload_options
    end

    def reset!
      self.scope_object = ::Rollbar::LazyStore.new({})
    end

    # Similar to configure below, but used only internally within the gem
    # to configure it without initializing any of the third party hooks
    def preconfigure
      yield(configuration.configured_options)
    end

    # Configures the notifier instance
    def configure
      configuration.enabled = true if configuration.enabled.nil?

      yield(configuration.configured_options)
    end

    def reconfigure
      self.configuration = Configuration.new
      configuration.enabled = true

      yield(configuration.configured_options)
    end

    def unconfigure
      self.configuration = nil
    end

    def scope(scope_overrides = {}, config_overrides = {})
      new_notifier = self.class.new(self, nil, scope_overrides)
      new_notifier.configuration = configuration.merge(config_overrides)

      new_notifier
    end

    def scope!(options = {}, config_overrides = {})
      Rollbar::Util.deep_merge(scope_object, options)
      configuration.merge!(config_overrides)

      self
    end

    # Returns a new notifier with same configuration options
    # but it sets Configuration#safely to true.
    # We are using this flag to avoid having inifite loops
    # when evaluating some custom user methods.
    def safely
      new_notifier = scope
      new_notifier.configuration.safely = true

      new_notifier
    end

    # Turns off reporting for the given block.
    #
    # @example
    #   Rollbar.silenced { raise }
    #
    # @yield Block which exceptions won't be reported.
    def silenced
      yield
    rescue StandardError => e
      e.instance_variable_set(:@_rollbar_do_not_report, true)
      raise
    end

    # Sends a report to Rollbar.
    #
    # Accepts a level string plus any number of arguments. The last String
    # argument will become the message or description of the report. The last
    # Exception argument will become the associated exception for the report.
    # The last hash argument will be used as the extra data for the report.
    #
    # If the extra hash contains a symbol key :custom_data_method_context
    # the value of the key will be used as the context for
    # configuration.custom_data_method and will be removed from the extra
    # hash.
    #
    # @example
    #   begin
    #     foo = bar
    #   rescue => e
    #     Rollbar.log('error', e)
    #   end
    #
    # @example
    #   Rollbar.log('info', 'This is a simple log message')
    #
    # @example
    #   Rollbar.log('error', e, 'This is a description of the exception')
    #
    def log(level, *args)
      return 'disabled' unless enabled?

      message, exception, extra, context = extract_arguments(args)
      use_exception_level_filters = use_exception_level_filters?(extra)

{'fraction_non_alphanumeric': 0.07110890104425659, 'fraction_numerical': 0.0, 'mean_word_length': 3.028542814221332, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2096374', 'n_tokens_mistral': 2286, 'n_tokens_neox': 2255, 'n_words': 690}