Skip to content

Commit fd814e9

Browse files
committed
Remove double implementation of the loglevel
1 parent a16308d commit fd814e9

File tree

2 files changed

+22
-27
lines changed

2 files changed

+22
-27
lines changed

analytics/src/analytics_desktop.cc

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "app/src/include/firebase/future.h"
2727
#include "app/src/include/firebase/variant.h"
2828
#include "app/src/log.h"
29+
#include "firebase/log.h"
2930

3031
#if defined(_WIN32)
3132
#include <windows.h>
@@ -388,28 +389,29 @@ void ResetAnalyticsData() {
388389
g_fake_instance_id++;
389390
}
390391

391-
// C-style callback that will be passed to the Google Analytics C API.
392-
static void GoogleAnalyticsWraperLogCallback(GoogleAnalytics_LogLevel log_level,
393-
const char* message) {
394-
if (g_log_callback) {
395-
LogLevel sdk_log_level;
396-
switch (log_level) {
397-
case kDebug:
398-
sdk_log_level = kLogLevelDebug;
399-
break;
392+
LogLevel ConvertAnalyticsLogLevelToFirebaseLogLevel(
393+
GoogleAnalytics_LogLevel log_level) {
394+
switch (log_level) {
395+
case kDebug:
396+
return kLogLevelDebug;
400397
case kInfo:
401-
sdk_log_level = kLogLevelInfo;
402-
break;
398+
return kLogLevelInfo;
403399
case kWarning:
404-
sdk_log_level = kLogLevelWarning;
405-
break;
400+
return kLogLevelWarning;
406401
case kError:
407-
sdk_log_level = kLogLevelError;
408-
break;
402+
return kLogLevelError;
409403
default:
410-
sdk_log_level = kLogLevelInfo;
411-
}
412-
g_log_callback(sdk_log_level, message);
404+
return kLogLevelInfo;
405+
}
406+
}
407+
408+
// C-style callback that will be passed to the Google Analytics C API.
409+
static void GoogleAnalyticsWraperLogCallback(GoogleAnalytics_LogLevel log_level,
410+
const char* message) {
411+
if (g_log_callback) {
412+
LogLevel firebase_log_level =
413+
ConvertAnalyticsLogLevelToFirebaseLogLevel(log_level);
414+
g_log_callback(firebase_log_level, message);
413415
}
414416
}
415417

analytics/src/include/firebase/analytics.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <vector>
2626

2727
#include "firebase/app.h"
28+
#include "firebase/log.h"
2829
#include "firebase/future.h"
2930
#include "firebase/internal/common.h"
3031
#include "firebase/variant.h"
@@ -559,14 +560,6 @@ void SetSessionTimeoutDuration(int64_t milliseconds);
559560
/// instance id.
560561
void ResetAnalyticsData();
561562

562-
/// @brief The log level of the message logged by the SDK.
563-
enum LogLevel {
564-
kLogLevelDebug,
565-
kLogLevelInfo,
566-
kLogLevelWarning,
567-
kLogLevelError,
568-
};
569-
570563
/// @brief The callback type for logging messages from the SDK.
571564
///
572565
/// The callback is invoked whenever the SDK logs a message.
@@ -576,7 +569,7 @@ enum LogLevel {
576569
using LogCallback = std::function<void(LogLevel, const char*)>;
577570

578571
/// @brief Allows the passing of a callback to be used when the SDK logs any
579-
/// messages regarding its behavior. The callback must be thread-safe.
572+
/// messages regarding its behaviour. The callback must be thread-safe.
580573
///
581574
/// @param[in] callback The callback to use. Must be thread-safe.
582575
void SetLogCallback(const LogCallback& callback);

0 commit comments

Comments
 (0)