Advertisement
Guest User

logger

a guest
Oct 14th, 2024
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | None | 0 0
  1. import inspect
  2. logging_function = """
  3. def print_{}(msg, indent=0):
  4.    print(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") + " (" + inspect.stack()[1].function + ") {}: -" + " "*indent*2 + " " + msg)
  5. """
  6. for loglevel in ["DEBUG ", "INFO  ", "WARN  ", "ERROR ", "FATAL "]:
  7.   exec(logging_function.format(loglevel.lower().strip(), loglevel))
  8.  
  9. print_info("This is an info message", 1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement