logger = None
verbose = False
limit = 0
position = 0

def setlog(log, verb):
  global logger
  global verbose
  logger = log
  verbose = verb

def printtolog(str, anyway=False):
  global logger
  global verbose
  if anyway or verbose:
    if logger == None:
      print(str)
    else:
      logger.AddInfo(str)

def refresh():
  global logger
  if logger != None:
    logger.Refresh()

def createprogmeter(msg, lim):
  global logger
  global limit
  global position
  if logger == None:
    limit = lim
    position = 0
    print(msg)
  else:
    logger.CreateProgressMeter(msg, lim)

def progress():
  global logger
  global limit
  global position
  position = position + 1
  if logger == None:
    print("{0} of {1}".format(position, limit))
  else:
    logger.Progress()

def finishprogress():
  global logger
  if logger != None:
    logger.FinishProgressMeter()
