tts_labeling / utils /logger.py
vargha's picture
sentry intergration
86cf81a
from datetime import datetime
import sentry_sdk
class Logger:
def _log(self, level, message):
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(f"[{now}] [{level.upper()}] {message}")
# Send to Sentry based on level
if level == 'error':
sentry_sdk.capture_message(message, level='error')
elif level == 'warning':
sentry_sdk.capture_message(message, level='warning')
# Info messages are not sent to Sentry to avoid noise
def info(self, message):
self._log('info', message)
def warning(self, message):
self._log('warning', message)
def error(self, message):
self._log('error', message)
def exception(self, message, exc_info=None):
"""Log an exception with full traceback"""
now = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
print(f"[{now}] [ERROR] {message}")
# Capture exception in Sentry
if exc_info:
sentry_sdk.capture_exception(exc_info)
else:
sentry_sdk.capture_exception()
def capture_user_action(self, action, user_id=None, **kwargs):
"""Capture user actions for analytics"""
# try:
from utils.sentry_integration import capture_annotation_event
capture_annotation_event(action, user_id=user_id, **kwargs)
# except ImportError:
# # Fallback if sentry_integration is not available
# self.info(f"User action: {action} (user_id: {user_id})")
# except Exception as e:
# self.error(f"Failed to capture user action: {e}")