Esempio n. 1
0
def fail(message):
  message = __format_message(message)

  sc = __COLORS.RED if (__SHOW_COLORS) else ''
  ec = __COLORS.ENDC if (__SHOW_COLORS) else ''

  os = "%s[%s%sFAIL] %s%s" % (sc, systools.now_string(), __caller_string(), message, ec)
  ls = "[%s%sFAIL] %s" % (systools.now_string(), __caller_string(), message)

  print_message(os, "error")
  log_message(ls, "error")
Esempio n. 2
0
def warning(message):
  message = __format_message(message)

  sc = __COLORS.YELLOW if (__SHOW_COLORS) else ''
  ec = __COLORS.ENDC if (__SHOW_COLORS) else ''

  os = "%s[%s%sWARNING] %s%s" % (sc, systools.now_string(), __caller_string(), message, ec)
  ls = "[%s%sWARNING] %s" % (systools.now_string(), __caller_string(), message)

  print_message(os, "warning")
  log_message(ls, "warning")
Esempio n. 3
0
def success(message):
  message = __format_message(message)

  sc = __COLORS.GREEN if (__SHOW_COLORS) else ''
  ec = __COLORS.ENDC if (__SHOW_COLORS) else ''

  os = "%s[%s%sSUCCESS] %s%s" % (sc, systools.now_string(), __caller_string(), message, ec)
  ls = "[%s%sSUCCESS] %s" % (systools.now_string(), __caller_string(), message)

  print_message(os, "info")
  log_message(ls, "info")
Esempio n. 4
0
def info(message):
  message = __format_message(message)

  os = "[%s%sINFO] %s" % (systools.now_string(), __caller_string(), message)
  ls = os
  print_message(os, "info")
  log_message(ls, "info")
Esempio n. 5
0
def log_message(message, verbosity_level):
  if not (__DO_LOG):
    return

  if (verbosity_level not in __VERBOSITY_MAPPING[__LOG_VERBOSITY]):
    return

  global __LOGDIR
  if (__LOGDIR == None):
    __LOGDIR = systools.maindir_realpath() + "logs" + os.sep

  systools.makedirs(__LOGDIR)
  logfile_path = __LOGDIR + __LOGNAME

  if (systools.file_exists(logfile_path)):
    if (systools.file_size(logfile_path) > __MAX_LOG_SIZE):
      destfile = __LOGDIR + ("%s.txt" % systools.now_string(systools.ISO_DATETIME_FORMAT_FSAFE))
      shutil.copy(logfile_path, destfile)
      logfile = open(logfile_path, 'w')
    else:
      logfile = open(logfile_path, 'a')
  else:
    logfile = open(logfile_path, 'w')
  #print(message)
  print(message, file=logfile)
  logfile.close()
Esempio n. 6
0
def debug(message):
  message = __format_message(message)

  os = "[%s%sDEBUG] %s" % (systools.now_string(), __caller_string(), message)
  ls = os

  print_message(os, "debug")
  log_message(ls, "debug")