# coding=utf8

import sys, os, time, errno, random, traceback
from parms import Parms

class D():
	def __init__(self, debid):
		self.debid = debid

	def ll(self, level):
		return level <= Parms.debugLevel

	def log(self, *msg, sev=0):
		if self.ll(sev):
			print("{} {:10.6f} {}:".format(time.strftime("%Y/%m/%d.%H:%M:%S"), time.time() - D.t0, self.debid), *msg, file=sys.stderr)
			sys.stderr.flush()

	def d(self, msg):
		self.log("+++ ====>", str(msg))

	def abendMsg(self, msg, e=None):
		emsg = "{}".format(e) if e else ""
		self.log("ABEND: {}".format(msg + (": " + emsg if emsg else "")))
		traceback.print_tb(sys.exc_info()[2])

	def abend(self, msg, e):
		self.abendMsg(msg, e=e)
		if Parms.clientMode: sys.exit(1)

	def abendHard(self, msg, e):
		self.abendMsg(msg, e=e)
		sys.exit(1)

	def warn(self, *msg):
		self.log("Warning:", *msg)
