<commit_before>
require "logging"

module Bixby

  # A simple logging mixin
  module Log

    # Get a log instance for this class
    #
    # @return [Logger]
    def log
      @log ||= Logging.logger[self]
    end

    # Create a method for each log level. Allows receiver to simply call
    #
    #   warn "foo"
    %w{debug warn info error fatal}.each do |level|
      code = <<-EOF
      def #{level}(data=nil, &block)
        log.send(:#{level}, data, &block)
      end
      EOF
      eval(code)
    end

    # Setup logging
    #
    # @param [Symbol] level       Log level to use (default = :warn)
    # @param [String] pattern     Log pattern
    def self.setup_logger(level=nil, pattern=nil)
      # set level: ENV flag overrides; default to warn
      level = :debug if ENV["BIXBY_DEBUG"]
      level ||= :warn

      pattern ||= '%.1l, [%d] %5l -- %c: %m\n'

      # TODO always use stdout for now
      Logging.appenders.stdout(
        :level  => level,
        :layout => Logging.layouts.pattern(:pattern => pattern)
        )
      Logging::Logger.root.add_appenders(Logging.appenders.stdout)
      Logging::Logger.root.level = level
    end
<commit_msg>always log to a file<commit_after>
require "logging"

module Bixby

  # A simple logging mixin
  module Log

    # Get a log instance for this class
    #
    # @return [Logger]
    def log
      @log ||= Logging.logger[self]
    end

    # Create a method for each log level. Allows receiver to simply call
    #
    #   warn "foo"
    %w{debug warn info error fatal}.each do |level|
      code = <<-EOF
      def #{level}(data=nil, &block)
        log.send(:#{level}, data, &block)
      end
      EOF
      eval(code)
    end

    # Setup logging
    #
    # @param [Symbol] level       Log level to use (default = :warn)
    # @param [String] pattern     Log pattern
    def self.setup_logger(level=nil, pattern=nil)
      # set level: ENV flag overrides; default to warn
      level = :debug if ENV["BIXBY_DEBUG"]
      level ||= :warn

      pattern ||= '%.1l, [%d] %5l -- %c: %m\n'

      FileUtils.mkdir_p(Bixby.path("var"))

      # TODO always use stdout for now
      Logging.appenders.rolling_file("file",
        :filename      => Bixby.path("var", "bixby-agent.log"),
        :keep          => 7,
        :roll_by       => 'date',
        :age           => 'daily',
        :truncate      => false,
        :auto_flushing => true,
        :level         => level,
        :layout        => Logging.layouts.pattern(:pattern => pattern)
        )

      Logging::Logger.root.add_appenders("file")
      Logging::Logger.root.level = level
    end

{'fraction_non_alphanumeric': 0.12366818873668188, 'fraction_numerical': 0.001902587519025875, 'mean_word_length': 2.0676779463243875, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 15, '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': '6859823', 'n_tokens_mistral': 855, 'n_tokens_neox': 836, 'n_words': 244}