ATLAS Offline Software
Classes | Functions | Variables
python.logger Namespace Reference

Classes

class  ColoredFormatter
 
class  ExtendedLogger
 

Functions

def insert_seqs (message)
 
def get_log_handler (singleton={})
 
def log_level (level)
 
def get_level_for_opts (verbose, quiet)
 
def init_logger (verbose=False, quiet=False)
 

Variables

int VERBOSE_LEVEL = 15
 
 RED
 
 YELLOW
 
 BLUE
 
 WHITE
 
string RESET_SEQ = "\033[0m"
 
string COLOR_SEQ = "\033[1;%dm"
 
string BOLD_SEQ = "\033[1m"
 
dictionary COLORS
 
 LoggerClass = logging.getLoggerClass()
 

Function Documentation

◆ get_level_for_opts()

def python.logger.get_level_for_opts (   verbose,
  quiet 
)

Definition at line 101 of file logger.py.

101 def get_level_for_opts(verbose, quiet):
102  if quiet:
103  log_level = logging.WARNING
104  elif not verbose:
105  log_level = logging.INFO
106  elif verbose == 1:
107  log_level = VERBOSE_LEVEL
108  elif verbose > 1:
109  log_level = logging.DEBUG
110 
111  return log_level
112 

◆ get_log_handler()

def python.logger.get_log_handler (   singleton = {})
Return the STDOUT handler singleton used for all logging.

Definition at line 67 of file logger.py.

67 def get_log_handler(singleton={}):
68  """
69  Return the STDOUT handler singleton used for all logging.
70  """
71  if "value" in singleton:
72  return singleton["value"]
73 
74  handler = logging.StreamHandler()
75  if os.isatty(handler.stream.fileno()):
76  FORMAT = "[%(asctime)s][$BOLD%(name)-20s$RESET][%(levelname)-18s] %(message)s"
77  handler.setFormatter(ColoredFormatter(insert_seqs(FORMAT)))
78 
79  # Make the top level logger and make it as verbose as possible.
80  # The log messages which make it to the screen are controlled by the handler
81  log = logging.getLogger()
82  log.addHandler(handler)
83  log.setLevel(logging.DEBUG)
84 
85  singleton["value"] = handler
86  return handler
87 
88 @contextmanager

◆ init_logger()

def python.logger.init_logger (   verbose = False,
  quiet = False 
)
This function should be called only by programs (not by libraries)

Definition at line 113 of file logger.py.

113 def init_logger(verbose=False, quiet=False):
114  """
115  This function should be called only by programs (not by libraries)
116  """
117  handler = get_log_handler()
118  handler.setLevel(get_level_for_opts(verbose, quiet))

◆ insert_seqs()

def python.logger.insert_seqs (   message)

Definition at line 22 of file logger.py.

22 def insert_seqs(message):
23  return message.replace("$RESET", RESET_SEQ).replace("$BOLD", BOLD_SEQ)
24 

◆ log_level()

def python.logger.log_level (   level)
A log level context manager. Changes the log level for the duration.

Definition at line 89 of file logger.py.

89 def log_level(level):
90  """
91  A log level context manager. Changes the log level for the duration.
92  """
93  handler = get_log_handler()
94  old_level = handler.level
95  try:
96  handler.setLevel(level)
97  yield
98  finally:
99  handler.setLevel(old_level)
100 

Variable Documentation

◆ BLUE

python.logger.BLUE

Definition at line 15 of file logger.py.

◆ BOLD_SEQ

string python.logger.BOLD_SEQ = "\033[1m"

Definition at line 20 of file logger.py.

◆ COLOR_SEQ

string python.logger.COLOR_SEQ = "\033[1;%dm"

Definition at line 19 of file logger.py.

◆ COLORS

dictionary python.logger.COLORS
Initial value:
1 = {
2  'DEBUG' : BLUE,
3  'VERBOSE' : WHITE,
4  'INFO' : YELLOW,
5  'WARNING' : YELLOW,
6  'ERROR' : RED,
7  'FATAL' : RED,
8 }

Definition at line 25 of file logger.py.

◆ LoggerClass

python.logger.LoggerClass = logging.getLoggerClass()

Definition at line 48 of file logger.py.

◆ RED

python.logger.RED

Definition at line 15 of file logger.py.

◆ RESET_SEQ

string python.logger.RESET_SEQ = "\033[0m"

Definition at line 18 of file logger.py.

◆ VERBOSE_LEVEL

int python.logger.VERBOSE_LEVEL = 15

Definition at line 8 of file logger.py.

◆ WHITE

python.logger.WHITE

Definition at line 15 of file logger.py.

◆ YELLOW

python.logger.YELLOW

Definition at line 15 of file logger.py.

python.logger.get_log_handler
def get_log_handler(singleton={})
Definition: logger.py:67
replace
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition: hcg.cxx:307
python.logger.log_level
def log_level(level)
Definition: logger.py:89
python.logger.get_level_for_opts
def get_level_for_opts(verbose, quiet)
Definition: logger.py:101
python.logger.insert_seqs
def insert_seqs(message)
Definition: logger.py:22
python.logger.init_logger
def init_logger(verbose=False, quiet=False)
Definition: logger.py:113