 # Private functions
 # -----------------
 
+# Indicate whether or not logging is enabled for specified `level`.
+canLog = (level) ->
+  log.logger.enabled and log.logger.level >= level
+
 # Attempt to dig down in to the `root` object and stop on the parent of the
 # target property.  
 # Return the progress of the mining as an array in this structure;


log = window.log =

  # Output all failed `assertions`.
  assert: (assertions...) ->
    console.assert assertion for assertion in assertions if @enabled()

  # Create/increment a counter and output its current count for all `names`.
  count: (names...) ->
    console.count name for name in names if @enabled()

  # Output all debug `entries`.
  debug: (entries...) ->
    console.debug entry for entry in entries if @enabled()

  # Display an interactive listing of the properties of all `entries`.
  dir: (entries...) ->
    console.dir entry for entry in entries if @enabled()

  # Indicate whether or not logging is enabled.
  enabled: ->
    store.get 'log'

  # Output all error `entries`.
  error: (entries...) ->
    console.error entry for entry in entries if @enabled()

  # Output all informative `entries`.
  info: (entries...) ->
    console.info entry for entry in entries if @enabled()

  # Output all general `entries`.
  out: (entries...) ->
    console.log entry for entry in entries if @enabled()

  # Start a timer for all `names`.
  time: (names...) ->
    console.time name for name in names if @enabled()

  # Stop a timer and output its elapsed time in milliseconds for all `names`.
  timeEnd: (names...) ->
    console.timeEnd name for name in names if @enabled()

  # Output a stack trace.
  trace: ->
    console.trace() if @enabled()

  # Output all warning `entries`.
  warn: (entries...) ->
    console.warn entry for entry in entries if @enabled()

# Storage setup
# -------------

store = window.store =

  # Clear all keys from `localStorage`.
  clear: ->

      str += repeatStr for i in [1..count] if count > 0
      # Repeat to the left if `count` is negative.
      str = repeatStr + str for i in [1..count*-1] if count < 0
    str

# Initialize logging.
store.init 'logger', {}
store.modify 'logger', (logger) ->
  logger.assertions ?= no
  logger.enabled    ?= no
  logger.level      ?= log.DEBUG
  log.logger = logger