<commit_before>require "log"
require "log/json"

module Raven
  # `::Log::Backend` recording logged messages.
  #
  # ```
  # Log.setup do |c|
  #   c.bind "*", :info, Log::IOBackend.new
  #   c.bind "*", :info, Raven::LogBackend.new(record_breadcrumbs: true)
  #   c.bind "*", :warn, Raven::LogBackend.new(capture_exceptions: true)
  #   c.bind "*", :fatal, Raven::LogBackend.new(capture_all: true)
  # end
  # ```
  class LogBackend < ::Log::Backend
    private BREADCRUMB_LEVELS = {
      :trace  => :debug,
      :debug  => :debug,
      :info   => :info,
      :notice => :info,
      :warn   => :warning,
      :error  => :error,
      :fatal  => :critical,
    } of ::Log::Severity => Breadcrumb::Severity

    private EXCEPTION_LEVELS = {
      :trace  => :debug,
      :debug  => :debug,
      :info   => :info,
      :notice => :info,
      :warn   => :warning,
      :error  => :error,
      :fatal  => :fatal,
    } of ::Log::Severity => Event::Severity

    # Records each logged entry as a breadcrumb.
    #
    # See `Raven.breadcrumbs`
    property? record_breadcrumbs : Bool

    # Captures `Exception` attached to the logged entry, if present.
    #
    # See `Raven.capture`
    property? capture_exceptions : Bool

    # Captures each logged entry.
    #
    # See `Raven.capture`
    property? capture_all : Bool

    # Default name of the root logger.
    #
    # See `Event#logger`, `Breadcrumb#category`
    property default_logger : String

    {% if compare_versions(Crystal::VERSION, "1.0.0-dev") >= 0 %}
      def initialize(
        dispatch_mode : ::Log::DispatchMode = :sync,
        *,
        @record_breadcrumbs = false,
        @capture_exceptions = false,
        @capture_all = false,
        @default_logger = "logger"
      )
        super(dispatch_mode)
      end
    {% else %}
      def initialize(
        *,
        @record_breadcrumbs = false,
        @capture_exceptions = false,
        @capture_all = false,
        @default_logger = "logger"
      )
      end
    {% end %}

    protected delegate :ignored_logger?,
      to: Raven.configuration

    protected def deansify(message : String?) : String?
      message.try &.gsub(/\x1b[^m]*m/, "").presence
    end<commit_msg>Make it work with Crystal nightlies (0.36.0) again<commit_after>require "log"
require "log/json"

module Raven
  # `::Log::Backend` recording logged messages.
  #
  # ```
  # Log.setup do |c|
  #   c.bind "*", :info, Log::IOBackend.new
  #   c.bind "*", :info, Raven::LogBackend.new(record_breadcrumbs: true)
  #   c.bind "*", :warn, Raven::LogBackend.new(capture_exceptions: true)
  #   c.bind "*", :fatal, Raven::LogBackend.new(capture_all: true)
  # end
  # ```
  class LogBackend < ::Log::Backend
    private BREADCRUMB_LEVELS = {
      :trace  => :debug,
      :debug  => :debug,
      :info   => :info,
      :notice => :info,
      :warn   => :warning,
      :error  => :error,
      :fatal  => :critical,
    } of ::Log::Severity => Breadcrumb::Severity

    private EXCEPTION_LEVELS = {
      :trace  => :debug,
      :debug  => :debug,
      :info   => :info,
      :notice => :info,
      :warn   => :warning,
      :error  => :error,
      :fatal  => :fatal,
    } of ::Log::Severity => Event::Severity

    # Records each logged entry as a breadcrumb.
    #
    # See `Raven.breadcrumbs`
    property? record_breadcrumbs : Bool

    # Captures `Exception` attached to the logged entry, if present.
    #
    # See `Raven.capture`
    property? capture_exceptions : Bool

    # Captures each logged entry.
    #
    # See `Raven.capture`
    property? capture_all : Bool

    # Default name of the root logger.
    #
    # See `Event#logger`, `Breadcrumb#category`
    property default_logger : String

    {% if compare_versions(Crystal::VERSION, "0.35.1") > 0 %}
      def initialize(
        dispatch_mode : ::Log::DispatchMode = :sync,
        *,
        @record_breadcrumbs = false,
        @capture_exceptions = false,
        @capture_all = false,
        @default_logger = "logger"
      )
        super(dispatch_mode)
      end
    {% else %}
      def initialize(
        *,
        @record_breadcrumbs = false,
        @capture_exceptions = false,
        @capture_all = false,
        @default_logger = "logger"
      )
      end
    {% end %}

    protected delegate :ignored_logger?,
      to: Raven.configuration

    protected def deansify(message : String?) : String?
      message.try &.gsub(/\x1b[^m]*m/, "").presence
    end
{'fraction_non_alphanumeric': 0.1419959812458138, 'fraction_numerical': 0.003348961821835231, 'mean_word_length': 2.396512509476876, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '7025034', 'n_tokens_mistral': 1521, 'n_tokens_neox': 1482, 'n_words': 332}