1
- import type { LogSeverityLevel , Log , Client , ParameterizedString } from '@sentry/core' ;
2
- import { getClient , _INTERNAL_captureLog , _INTERNAL_flushLogsBuffer } from '@sentry/core' ;
3
-
4
- import { WINDOW } from './helpers' ;
5
-
6
- /**
7
- * TODO: Make this configurable
8
- */
9
- const DEFAULT_FLUSH_INTERVAL = 5000 ;
10
-
11
- let timeout : ReturnType < typeof setTimeout > | undefined ;
12
-
13
- /**
14
- * This is a global timeout that is used to flush the logs buffer.
15
- * It is used to ensure that logs are flushed even if the client is not flushed.
16
- */
17
- function startFlushTimeout ( client : Client ) : void {
18
- if ( timeout ) {
19
- clearTimeout ( timeout ) ;
20
- }
21
-
22
- timeout = setTimeout ( ( ) => {
23
- _INTERNAL_flushLogsBuffer ( client ) ;
24
- } , DEFAULT_FLUSH_INTERVAL ) ;
25
- }
26
-
27
- let isClientListenerAdded = false ;
28
- /**
29
- * This is a function that is used to add a flush listener to the client.
30
- * It is used to ensure that the logger buffer is flushed when the client is flushed.
31
- */
32
- function addFlushingListeners ( client : Client ) : void {
33
- if ( isClientListenerAdded || ! client . getOptions ( ) . _experiments ?. enableLogs ) {
34
- return ;
35
- }
36
-
37
- isClientListenerAdded = true ;
38
-
39
- if ( WINDOW . document ) {
40
- WINDOW . document . addEventListener ( 'visibilitychange' , ( ) => {
41
- if ( WINDOW . document . visibilityState === 'hidden' ) {
42
- _INTERNAL_flushLogsBuffer ( client ) ;
43
- }
44
- } ) ;
45
- }
46
-
47
- client . on ( 'flush' , ( ) => {
48
- _INTERNAL_flushLogsBuffer ( client ) ;
49
- } ) ;
50
- }
1
+ import type { LogSeverityLevel , Log , ParameterizedString } from '@sentry/core' ;
2
+ import { _INTERNAL_captureLog } from '@sentry/core' ;
51
3
52
4
/**
53
5
* Capture a log with the given level.
@@ -63,14 +15,7 @@ function captureLog(
63
15
attributes ?: Log [ 'attributes' ] ,
64
16
severityNumber ?: Log [ 'severityNumber' ] ,
65
17
) : void {
66
- const client = getClient ( ) ;
67
- if ( client ) {
68
- addFlushingListeners ( client ) ;
69
-
70
- startFlushTimeout ( client ) ;
71
- }
72
-
73
- _INTERNAL_captureLog ( { level, message, attributes, severityNumber } , client , undefined ) ;
18
+ _INTERNAL_captureLog ( { level, message, attributes, severityNumber } ) ;
74
19
}
75
20
76
21
/**
0 commit comments