File size: 1,635 Bytes
0fb23b8
86cf81a
1ef4e10
 
0fb23b8
 
 
86cf81a
 
 
 
 
 
 
1ef4e10
0fb23b8
 
1ef4e10
0fb23b8
 
1ef4e10
0fb23b8
86cf81a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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}")