Skip to content

Commit b5d2172

Browse files
committed
RUMM-2050 fix code review comments
1 parent b9b9966 commit b5d2172

File tree

6 files changed

+142
-109
lines changed

6 files changed

+142
-109
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ config.sampleRate = 80
5555
// Optional: set the reported service name (by default, it'll use the package name / bundleIdentifier of your Android / iOS app respectively)
5656
config.serviceName = "com.example.reactnative"
5757
// Optional: let the SDK print internal logs (above or equal to the provided level. Default = undefined (meaning no logs))
58-
configuration.verbosity = SdkVerbosity.WARN
58+
config.verbosity = SdkVerbosity.WARN
5959

6060
await DdSdkReactNative.initialize(config)
6161

packages/core/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ config.sampleRate = 80
5151
// Optional: set the reported service name (by default, it'll use the package name / bundleIdentifier of your Android / iOS app respectively)
5252
config.serviceName = "com.example.reactnative"
5353
// Optional: let the SDK print internal logs (above or equal to the provided level. Default = undefined (meaning no logs))
54-
configuration.verbosity = SdkVerbosity.WARN
54+
config.verbosity = SdkVerbosity.WARN
5555

5656
await DdSdkReactNative.initialize(config)
5757

packages/core/src/DdSdkReactNative.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ export class DdSdkReactNative {
115115
*/
116116
// eslint-disable-next-line @typescript-eslint/ban-types
117117
static setAttributes(attributes: object): Promise<void> {
118-
InternalLog.log("Setting attributes " + JSON.stringify(attributes), SdkVerbosity.DEBUG);
118+
InternalLog.log("Setting attributes " + JSON.stringify(attributes), SdkVerbosity.DEBUG);
119119
return DdSdk.setAttributes(attributes)
120120
}
121121

@@ -126,7 +126,7 @@ export class DdSdkReactNative {
126126
*/
127127
// eslint-disable-next-line @typescript-eslint/ban-types
128128
static setUser(user: object): Promise<void> {
129-
InternalLog.log("Setting user " + JSON.stringify(user), SdkVerbosity.DEBUG);
129+
InternalLog.log("Setting user " + JSON.stringify(user), SdkVerbosity.DEBUG);
130130
return DdSdk.setUser(user)
131131
}
132132

@@ -136,7 +136,7 @@ export class DdSdkReactNative {
136136
* @returns a Promise.
137137
*/
138138
static setTrackingConsent(consent: TrackingConsent): Promise<void> {
139-
InternalLog.log("Setting consent " + consent, SdkVerbosity.DEBUG);
139+
InternalLog.log("Setting consent " + consent, SdkVerbosity.DEBUG);
140140
return DdSdk.setTrackingConsent(consent)
141141
}
142142

packages/core/src/InternalLog.tsx

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,41 @@ import {SdkVerbosity} from './SdkVerbosity'
88

99
export class InternalLog {
1010

11+
private static levelMap = new Map<SdkVerbosity, number>([
12+
[SdkVerbosity.DEBUG, 1],
13+
[SdkVerbosity.INFO, 2],
14+
[SdkVerbosity.WARN, 3],
15+
[SdkVerbosity.ERROR, 4]
16+
]);
17+
1118
public static verbosity: SdkVerbosity|undefined = undefined
1219

13-
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
14-
public static log (message: any, verbosity: SdkVerbosity) {
20+
public static log (message: string, verbosity: SdkVerbosity): void {
21+
if (InternalLog.verbosity === undefined) {
22+
return;
23+
}
24+
const requiredLevel = InternalLog.levelMap.get(verbosity);
25+
const allowedLevel = InternalLog.levelMap.get(InternalLog.verbosity);
26+
if (allowedLevel === undefined || requiredLevel === undefined) {
27+
return;
28+
}
1529
const prefixedMessage = "DATADOG: " + message
16-
if (verbosity == SdkVerbosity.ERROR && (
17-
(InternalLog.verbosity == SdkVerbosity.ERROR) ||
18-
(InternalLog.verbosity == SdkVerbosity.WARN) ||
19-
(InternalLog.verbosity == SdkVerbosity.INFO) ||
20-
(InternalLog.verbosity == SdkVerbosity.DEBUG)
21-
)) {
30+
if (verbosity == SdkVerbosity.ERROR && (requiredLevel >= allowedLevel)) {
2231
console.error(prefixedMessage)
2332
}
2433

25-
if (verbosity == SdkVerbosity.WARN && (
26-
(InternalLog.verbosity == SdkVerbosity.WARN) ||
27-
(InternalLog.verbosity == SdkVerbosity.INFO) ||
28-
(InternalLog.verbosity == SdkVerbosity.DEBUG)
29-
)) {
34+
if (verbosity == SdkVerbosity.WARN && (requiredLevel >= allowedLevel)) {
3035
console.warn(prefixedMessage)
3136
}
3237

33-
if (verbosity == SdkVerbosity.INFO && (
34-
(InternalLog.verbosity == SdkVerbosity.INFO) ||
35-
(InternalLog.verbosity == SdkVerbosity.DEBUG)
36-
)) {
37-
console.log(prefixedMessage)
38+
if (verbosity == SdkVerbosity.INFO && (requiredLevel >= allowedLevel)) {
39+
console.info(prefixedMessage)
3840
}
3941

40-
if (verbosity == SdkVerbosity.DEBUG && (
41-
(InternalLog.verbosity == SdkVerbosity.DEBUG)
42-
)) {
43-
console.log(prefixedMessage)
42+
if (verbosity == SdkVerbosity.DEBUG && (requiredLevel >= allowedLevel)) {
43+
console.debug(prefixedMessage)
4444
}
4545
}
46+
47+
4648
}

packages/core/src/SdkVerbosity.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
/**
8-
* Enum specifying possible consent options for DD SDK.
8+
* Enum specifying possible log levels for DD SDK.
99
*/
1010
export enum SdkVerbosity {
1111
DEBUG = "debug",

0 commit comments

Comments
 (0)