<commit_before>ttm.define "logger", ['lib/class_mixer'], (class_mixer)->
  class LogEntry
    initialize: ((@level, @args)->)
    createStrMsg: ->
      message = ''
      for arg in @args
        arg = JSON.stringify(arg) unless typeof arg is 'string'
        message += "#{arg} "
      "#{@level}: #{message}"

    createArrMsg: ->
      ret = []
      current_str = "#{@level}: "
      for arg in @args
        if typeof arg is 'string'
          current_str += " #{@arg}"
        else
          ret.push current_str unless current_str.length == 0
          current_str = ""
          ret.push arg
      ret
    display: (force_string)->
      if force_string
        @createStrMsg()
      else
        @createArrMsg()

  class_mixer(LogEntry)

  class InstrumentedFunctionLogEntry
    initialize: ((@args)->)

  class_mixer(InstrumentedFunctionLogEntry)

  class Logger
    initialize: (opts={})->
      @log_entry_types = ['error','warn','info','debug', 'log', 'instrumented']

      @log_entry_display_types = @typesForLevel(opts.log_level || 'production')

      @console_log = opts.console_log
      @stringify_objects = opts.stringify_objects
      @entries = []
      @unique_id = 0

    setLogLevel: (new_level) ->
      @log_entry_display_types  = @typesForLevel(new_level)

    add: (type, args = []) ->
      entry = LogEntry.build(type, args)
      @entries.push entry

      if @log_entry_display_types.indexOf(type) != -1
        @console_log entry.display(@stringify_objects)

    typesForLevel: (level)->
      switch level
        when 'production' then ['error', 'warn']
        when 'firehose' then @log_entry_types # all

    error: -> @add('error', arguments)
    warn:  -> @add('warn', arguments)
    info:  -> @add('info', arguments)
    debug: -> @add('debug', arguments)
    log:   -> @add('log', arguments)

    getUniqueId: -> @unique_id += 1

    instrument: (opts)->
      __logger = @
      ->
        arr = Array.prototype.slice.call(arguments)
        arr.unshift(@)
        arr.unshift "#{opts.name} call: "
        __logger.add('instrumented', arr)
        retval = opts.fn.apply(@, arguments)
        __logger.add('instrumented', ["#{opts.name} return: ", retval])
        retval
<commit_msg>Fixed a couple of bugs in Logger<commit_after>ttm.define "logger", ['lib/class_mixer'], (class_mixer)->
  class LogEntry
    initialize: ((@level, @args)->)
    createStrMsg: ->
      message = ''
      for arg in @args
        arg = JSON.stringify(arg) unless typeof arg is 'string'
        message += "#{arg} "
      "#{@level}: #{message}"

    createArrMsg: ->
      ret = []
      current_str = "#{@level}: "
      for arg in @args
        if typeof arg is 'string'
          current_str += " #{arg}"
        else
          ret.push current_str unless current_str.length == 0
          current_str = ""
          ret.push arg
      ret.push current_str unless current_str.length == 0
      ret
    display: (force_string)->
      if force_string
        [@createStrMsg()]
      else
        @createArrMsg()

  class_mixer(LogEntry)

  class InstrumentedFunctionLogEntry
    initialize: ((@args)->)

  class_mixer(InstrumentedFunctionLogEntry)

  class Logger
    initialize: (opts={})->
      @log_entry_types = ['error','warn','info','debug', 'log', 'instrumented']

      @log_entry_display_types = @typesForLevel(opts.log_level || 'production')

      @console_log = opts.console_log
      @stringify_objects = opts.stringify_objects
      @entries = []
      @unique_id = 0

    setLogLevel: (new_level) ->
      @log_entry_display_types  = @typesForLevel(new_level)

    add: (type, args = []) ->
      entry = LogEntry.build(type, args)
      @entries.push entry

      if @log_entry_display_types.indexOf(type) != -1
        @console_log.apply(null, entry.display(@stringify_objects))

    typesForLevel: (level)->
      switch level
        when 'production' then ['error', 'warn']
        when 'firehose' then @log_entry_types # all

    error: -> @add('error', arguments)
    warn:  -> @add('warn', arguments)
    info:  -> @add('info', arguments)
    debug: -> @add('debug', arguments)
    log:   -> @add('log', arguments)

    getUniqueId: -> @unique_id += 1

    instrument: (opts)->
      __logger = @
      ->
        arr = Array.prototype.slice.call(arguments)
        arr.unshift(@)
        arr.unshift "#{opts.name} call: "
        __logger.add('instrumented', arr)
        retval = opts.fn.apply(@, arguments)
        __logger.add('instrumented', ["#{opts.name} return: ", retval])
        retval

{'fraction_non_alphanumeric': 0.14568226763348716, 'fraction_numerical': 0.001977587343441002, 'mean_word_length': 2.5396578538102643, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, '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': '7123542', 'n_tokens_mistral': 1425, 'n_tokens_neox': 1403, 'n_words': 311}