-
Notifications
You must be signed in to change notification settings - Fork 42
/
internal_logger.dart
62 lines (54 loc) · 2.33 KB
/
internal_logger.dart
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
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2019-2022 Datadog, Inc.
import 'package:flutter/foundation.dart';
import 'datadog_configuration.dart';
import 'datadog_sdk_platform_interface.dart';
import 'helpers.dart';
/// This class is used internally by the SDK to log issues to the client
/// developers. Note that all logging from the Flutter portions of the SDK are
/// disabled if kDebugMode is not set.
class InternalLogger {
bool useEmoji = true;
Verbosity sdkVerbosity = Verbosity.info;
static const _emojiMap = {
Verbosity.debug: '🐞',
Verbosity.info: 'ℹ️',
Verbosity.warn: '⚠️',
Verbosity.error: '💥'
};
void debug(String message) => log(Verbosity.debug, message);
void info(String message) => log(Verbosity.info, message);
void warn(String message) => log(Verbosity.warn, message);
void error(String message) => log(Verbosity.error, message);
void log(Verbosity verbosity, String message) {
if (kDebugMode && verbosity.index >= sdkVerbosity.index) {
final prefixString = useEmoji
? '[Datadog 🐶${_emojiMap[verbosity]} ]'
: '[Datadog - ${verbosity.name}]';
// ignore: avoid_print
print('$prefixString $message');
}
}
/// Send a log to the Datadog org, not to the customer's org. This feature is
/// used mostly to track potential issues in the Datadog SDK. The rate at which
/// data is sent to Datadog is set by [DdSdkConfiguration.telemetrySampleRate]
void sendToDatadog(String message, StackTrace? stack, String? kind) {
DatadogSdkPlatform.instance
.sendTelemetryError(message, stack.toString(), kind);
}
// Standard error strings
static String argumentWarning(String methodName, ArgumentError e,
Map<String, Object?>? serializedAttributes) {
var warning =
'ArgumentError when calling $methodName: parameter ${e.message}.';
if (serializedAttributes != null) {
final badAttribute = findInvalidAttribute(serializedAttributes);
if (badAttribute != null) {
warning +=
' It looks like ${badAttribute.propertyName} is of type ${badAttribute.propertyType}, which is not supported.';
}
}
return warning;
}
}