logger.py
Go to the documentation of this file.
1 import datetime
2 import threading
3 
4 LOG_ERROR = 0
5 LOG_WARN = 1
6 LOG_INFO = 2
7 LOG_DEBUG = 3
8 LOG_ALL = 99
9 
10 
11 class Logger(object): #Object inheritence for child 'RospyLogger' (Jordy)
12  def __init__(self, header=''):
13  self.log_level = LOG_INFO
14  self.header_string = header
15  self.lock = threading.Lock()
16 
17  def header(self):
18  now = datetime.datetime.now()
19  ts = ("%02d:%02d:%02d.%03d" % (now.hour, now.minute, now.second, now.microsecond/1000))
20  return "%s: %s" % (self.header_string, ts)
21 
22  def set_level(self, level):
23  self.log_level = level
24 
25  def output(self, msg):
26  self.lock.acquire()
27  print(msg)
28  self.lock.release()
29 
30  def error(self, str):
31  if self.log_level < LOG_ERROR:
32  return
33  self.output("%s: Error: %s" % (self.header(), str))
34 
35  def warn(self, str):
36  if self.log_level < LOG_WARN:
37  return
38  self.output("%s: Warn: %s" % (self.header(), str))
39 
40  def info(self, str):
41  if self.log_level < LOG_INFO:
42  return
43  self.output("%s: Info: %s" % (self.header(), str))
44 
45  def debug(self, str):
46  if self.log_level < LOG_DEBUG:
47  return
48  self.output("%s: Debug: %s" % (self.header(), str))
49 
50 if __name__ == '__main__':
51  log = Logger('test')
52  log.error('This is an error message')
53  log.warn('This is a warning message')
54  log.info('This is an info message')
55  log.debug('This should ** NOT ** be displayed')
56  log.set_level(LOG_ALL)
57  log.debug('This is a debug message')
def warn(self, str)
Definition: logger.py:35
def info(self, str)
Definition: logger.py:40
def output(self, msg)
Definition: logger.py:25
def error(self, str)
Definition: logger.py:30
def __init__(self, header='')
Definition: logger.py:12
def set_level(self, level)
Definition: logger.py:22
def debug(self, str)
Definition: logger.py:45


tello_driver
Author(s): Jordy van Appeven
autogenerated on Wed May 13 2020 03:34:54