-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcustom_telemetry_demo_service.dart
More file actions
67 lines (54 loc) · 2.29 KB
/
custom_telemetry_demo_service.dart
File metadata and controls
67 lines (54 loc) · 2.29 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import 'package:faro/faro.dart';
import 'package:faro_example/shared/models/demo_log_entry.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
typedef CustomTelemetryLogCallback =
void Function(String message, {DemoLogTone tone});
final customTelemetryDemoServiceProvider = Provider<CustomTelemetryDemoService>(
(ref) => const CustomTelemetryDemoService(),
);
/// Runs the custom telemetry demos shown in the example app.
class CustomTelemetryDemoService {
const CustomTelemetryDemoService();
void emitWarnLog(CustomTelemetryLogCallback log) {
Faro().pushLog('Custom Warning Log', level: LogLevel.warn);
log('Sent warn log: Custom Warning Log', tone: DemoLogTone.warning);
}
void emitInfoLog(CustomTelemetryLogCallback log) {
Faro().pushLog('This is an info message', level: LogLevel.info);
log('Sent info log: This is an info message', tone: DemoLogTone.info);
}
void emitErrorLog(CustomTelemetryLogCallback log) {
Faro().pushLog('This is an error message', level: LogLevel.error);
log('Sent error log: This is an error message', tone: DemoLogTone.error);
}
void emitDebugLog(CustomTelemetryLogCallback log) {
Faro().pushLog('This is a debug message', level: LogLevel.debug);
log('Sent debug log: This is a debug message', tone: DemoLogTone.neutral);
}
void emitTraceLog(CustomTelemetryLogCallback log) {
Faro().pushLog('This is a trace message', level: LogLevel.trace);
log('Sent trace log: This is a trace message', tone: DemoLogTone.neutral);
}
void emitMeasurement(CustomTelemetryLogCallback log) {
Faro().pushMeasurement({'custom_value': 1}, 'custom_measurement');
log(
'Sent measurement: custom_measurement {custom_value: 1}',
tone: DemoLogTone.highlight,
);
}
void emitEvent(CustomTelemetryLogCallback log) {
Faro().pushEvent('custom_event');
log('Sent event: custom_event', tone: DemoLogTone.highlight);
}
bool toggleDataCollection(CustomTelemetryLogCallback log) {
Faro().enableDataCollection = !Faro().enableDataCollection;
final isEnabled = Faro().enableDataCollection;
log(
isEnabled
? 'Data collection enabled for the current session.'
: 'Data collection disabled for the current session.',
tone: DemoLogTone.info,
);
return isEnabled;
}
}