logger.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. from typing import Literal, Union, Any
  2. from uuid import UUID
  3. EventLevel = Literal["info", "warn", "error", "success", "debug"]
  4. LEVEL_MAP = {
  5. "info": "INFO",
  6. "warn": "WARN",
  7. "error": "FAILED",
  8. "success": "SUCCESS",
  9. "debug": "DEBUG",
  10. }
  11. class TestLogger:
  12. @staticmethod
  13. def _format_message(type: str, message: str) -> str:
  14. """Format the log message with type prefix"""
  15. return f"[{type.upper()}] {message}"
  16. @staticmethod
  17. def _create_log(sketch_id: Union[str, UUID], log_type: str, content: str) -> Any:
  18. """Create a dummy log object for testing"""
  19. class DummyLog:
  20. def __init__(self):
  21. self.id = "dummy_id"
  22. return DummyLog()
  23. @staticmethod
  24. def info(sketch_id: Union[str, UUID], message: str):
  25. """Log an info message"""
  26. formatted_message = TestLogger._format_message("INFO", message)
  27. print(formatted_message)
  28. @staticmethod
  29. def error(sketch_id: Union[str, UUID], message: str):
  30. """Log an error message"""
  31. formatted_message = TestLogger._format_message("FAILED", message)
  32. print(formatted_message)
  33. @staticmethod
  34. def warn(sketch_id: Union[str, UUID], message: str):
  35. """Log a warning message"""
  36. formatted_message = TestLogger._format_message("WARNING", message)
  37. print(formatted_message)
  38. @staticmethod
  39. def debug(sketch_id: Union[str, UUID], message: str):
  40. """Log a debug message"""
  41. formatted_message = TestLogger._format_message("DEBUG", message)
  42. print(formatted_message)
  43. @staticmethod
  44. def success(sketch_id: Union[str, UUID], message: str):
  45. """Log a success message"""
  46. formatted_message = TestLogger._format_message("SUCCESS", message)
  47. print(formatted_message)