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

    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

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

    logMethodCall: (name, object, method, args)->
      id = @getUniqueId()
      @info("method call (id #{id}): ", name, object, method, args)
      ret = object[method].apply(object, args)
      @info("method call return (id #{id}): ", name, object, method, args, ret)
      ret

  class_mixer Logger

