fkudinov

Color for logs

May 5th, 2026
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | Source Code | 0 0
  1. # pip  install structlog
  2. import structlog
  3.  
  4.  
  5. logger = structlog.getLogger(__name__)
  6.  
  7.  
  8. def setup_logger():
  9.     cr = structlog.dev.ConsoleRenderer.get_active()
  10.     cr.colors = True
  11.  
  12.  
  13. def main():
  14.     logger.debug("Debug: Starting the main function.")
  15.     logger.info("Hello, world!")
  16.     logger.warning("Warning: This is a warning message.")
  17.     logger.error("Error: This is an error message.")
  18.     logger.debug("Debug: This is a debug message.")
  19.  
  20.  
  21. if __name__ == "__main__":
  22.     setup_logger()
  23.     main()
  24.  
Tags: python Logging
Advertisement
Add Comment
Please, Sign In to add comment