Skip to content

Commit

Permalink
refactor: adjust severities of log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed May 10, 2024
1 parent dfaa39b commit 7cf7e68
Show file tree
Hide file tree
Showing 25 changed files with 49 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,13 @@ private void startImpl(@NonNull Context context,
}

if (ApkToolsConfig.IS_SDK_DISABLED) {
logger.logInfo("SDK disabled through ApkToolsConfig");
logger.logInfo("SDK disabled through ApkToolsConfig", null);
stop();
return;
}

final long startTimeMs = sdkClock.now();
logger.logInfo("Starting SDK for framework " + framework.name());
logger.logInfo("Starting SDK for framework " + framework.name(), null);
moduleInitBootstrapper.init(context, framework, startTimeMs, customAppId, configServiceProvider);
Systrace.startSynchronous("post-services-setup");
telemetryService = moduleInitBootstrapper.getInitModule().getTelemetryService();
Expand All @@ -280,7 +280,7 @@ private void startImpl(@NonNull Context context,

final EssentialServiceModule essentialServiceModule = moduleInitBootstrapper.getEssentialServiceModule();
if (essentialServiceModule.getConfigService().isSdkDisabled()) {
logger.logInfo("Interrupting SDK start because it is disabled");
logger.logInfo("Interrupting SDK start because it is disabled", null);
stop();
return;
}
Expand Down Expand Up @@ -368,7 +368,7 @@ private void startImpl(@NonNull Context context,

final String startMsg = "Embrace SDK started. App ID: " +
essentialServiceModule.getConfigService().getSdkModeBehavior().getAppId() + " Version: " + BuildConfig.VERSION_NAME;
logger.logInfo(startMsg);
logger.logInfo(startMsg, null);

final long endTimeMs = sdkClock.now();
started.set(true);
Expand Down Expand Up @@ -471,7 +471,7 @@ boolean setAppId(@NonNull String appId) {
*/
void stop() {
if (started.compareAndSet(true, false)) {
logger.logInfo("Shutting down Embrace SDK.");
logger.logInfo("Shutting down Embrace SDK.", null);
try {
if (composeActivityListenerInstance != null && application != null) {
unregisterComposeActivityListener(application);
Expand Down Expand Up @@ -999,7 +999,7 @@ String getCurrentSessionId() {
if (sessionId != null) {
return sessionId;
} else {
logger.logInfo("Session ID is null");
logger.logInfo("Session ID is null", null);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ internal class UnityInternalInterfaceImpl(
exceptionType: LogExceptionType
) {
if (embrace.isStarted) {
logger.logError("message: $message -- stacktrace: $stacktrace")
embrace.logMessage(
EventType.ERROR_LOG,
"Unity exception",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ internal class EmbraceAnrService(
}
anrMonitorWorker.submit(callable).get(MAX_DATA_WAIT_MS, TimeUnit.MILLISECONDS)
} catch (exc: Exception) {
logger.logError("Failed to getAnrIntervals()", exc, true)
logger.logWarning("Failed to getAnrIntervals()", exc, true)
emptyList()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal class LivenessCheckScheduler internal constructor(
} catch (exc: Exception) {
// ignore any RejectedExecution - ScheduledExecutorService only throws when shutting down.
val message = "ANR capture initialization failed"
logger.logError(message, exc, true)
logger.logWarning(message, exc, true)
}
}

Expand Down Expand Up @@ -154,7 +154,7 @@ internal class LivenessCheckScheduler internal constructor(
private fun sendHeartbeatMessage() {
val heartbeatMessage = Message.obtain(targetThreadHandler, HEARTBEAT_REQUEST)
if (!targetThreadHandler.sendMessage(heartbeatMessage)) {
logger.logError(
logger.logWarning(
"Failed to send message to targetHandler, main thread likely shutting down.",
IllegalStateException("Failed to send message to targetHandler"),
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal class UnbalancedCallDetector(
private fun checkTimeTravel(name: String, timestamp: Long) {
if (lastTimestamp > timestamp) {
val msg = "Time travel in $name. $lastTimestamp to $timestamp"
logger.logError(msg, IllegalStateException(msg), true)
logger.logWarning(msg, IllegalStateException(msg), true)
}
lastTimestamp = timestamp
}
Expand All @@ -42,7 +42,7 @@ internal class UnbalancedCallDetector(
if (blocked != expected) {
val threadName = Thread.currentThread().name
val msg = "Unbalanced call to $name in ANR detection. Thread=$threadName"
logger.logError(msg, IllegalStateException(msg), true)
logger.logWarning(msg, IllegalStateException(msg), true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ internal class EmbraceNetworkConnectivityService(
}
}
} catch (ex: Exception) {
logger.logDebug("Failed to record network connectivity", ex)
logger.logWarning("Failed to record network connectivity", ex)
}
}

Expand Down Expand Up @@ -96,7 +96,7 @@ internal class EmbraceNetworkConnectivityService(
try {
context.registerReceiver(this, intentFilter)
} catch (ex: Exception) {
logger.logDebug(
logger.logInfo(
"Failed to register EmbraceNetworkConnectivityService " +
"broadcast receiver. Connectivity status will be unavailable.",
ex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ internal class EmbraceCpuInfoDelegate(
try {
getNativeCpuName()
} catch (exception: LinkageError) {
logger.logError("Could not get the CPU name. Exception: $exception", exception)
logger.logWarning("Could not get the CPU name. Exception: $exception", exception)
null
}
} else {
Expand All @@ -26,7 +26,7 @@ internal class EmbraceCpuInfoDelegate(
try {
getNativeEgl()
} catch (exception: LinkageError) {
logger.logError("Could not get the EGL name. Exception: $exception", exception)
logger.logWarning("Could not get the EGL name. Exception: $exception", exception)
null
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ internal class EmbraceUncaughtExceptionHandler(
try {
crashService.handleCrash(exception)
} catch (ex: Exception) {
logger.logDebug("Error occurred in the uncaught exception handler", ex)
logger.logError("Error occurred in the uncaught exception handler", ex)
} finally {
logger.logDebug("Finished handling exception. Delegating to default handler.", exception)
defaultHandler?.uncaughtException(thread, exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class RnBreadcrumbDataSource(
RnActionBreadcrumb(name, startTime, endTime, properties, bytesSent, output)
)
} catch (ex: Exception) {
logger.logDebug("Failed to log RN Action breadcrumb with name $name", ex)
logger.logWarning("Failed to log RN Action breadcrumb", ex)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ internal class DeviceImpl(
displayMetrics.heightPixels
)
} catch (ex: Exception) {
logger.logDebug("Could not determine screen resolution", ex)
logger.logWarning("Could not determine screen resolution", ex)
""
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ internal class ComponentCallbackService(
try {
memoryService.onMemoryWarning()
} catch (ex: Exception) {
logger.logDebug(
logger.logWarning(
"Failed to handle onTrimMemory (low memory) event",
ex
)
Expand All @@ -42,7 +42,7 @@ internal class ComponentCallbackService(
try {
application.applicationContext.unregisterComponentCallbacks(this)
} catch (ex: Exception) {
logger.logDebug(
logger.logWarning(
"Error when closing ComponentCallbackService",
ex
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ internal class EmbraceWebViewService(
if (message.length < SCRIPT_MESSAGE_MAXIMUM_ALLOWED_LENGTH) {
return serializer.fromJson(message, WebViewInfo::class.java)
} else {
logger.logError("Web Vital info is too large to parse")
logger.logWarning("Web Vital info is too large to parse")
}
} catch (e: Exception) {
logger.logError("Cannot parse Web Vital", e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ internal class EmbraceCacheService(
try {
return serializer.fromJson(file.inputStream(), clazz)
} catch (ex: FileNotFoundException) {
logger.logDebug("Cache file cannot be found " + file.path)
logger.logInfo("Cache file cannot be found " + file.path)
} catch (ex: Exception) {
logger.logDebug("Failed to read cache object " + file.path, ex)
}
Expand All @@ -90,7 +90,7 @@ internal class EmbraceCacheService(
try {
file.delete()
} catch (ex: Exception) {
logger.logDebug("Failed to delete cache object " + file.path)
logger.logInfo("Failed to delete cache object " + file.path)
}
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ internal class EmbraceConfigService @JvmOverloads constructor(
try {
listener()
} catch (ex: Exception) {
logger.logDebug("Failed to notify configListener", ex)
logger.logWarning("Failed to notify configListener", ex)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ internal class EmbraceLogMessageService(
}
}
} catch (ex: Exception) {
logger.logDebug("Failed to log network call using Embrace SDK.", ex)
logger.logInfo("Failed to log network call using Embrace SDK.", ex)
}
}

Expand Down Expand Up @@ -144,7 +144,7 @@ internal class EmbraceLogMessageService(
backgroundWorker.submit {
synchronized(lock) {
if (!configService.dataCaptureEventBehavior.isLogMessageEnabled(message)) {
logger.logWarning("Log message disabled. Ignoring log with message $message")
logger.logInfo("Log message disabled. Ignoring log with message $message")
return@submit
}
val id = getEmbUuid()
Expand All @@ -153,23 +153,23 @@ internal class EmbraceLogMessageService(
if (infoLogIds.size < configService.logMessageBehavior.getInfoLogLimit()) {
infoLogIds[timestamp] = id
} else {
logger.logWarning("Info Log limit has been reached.")
logger.logInfo("Info Log limit has been reached.")
return@submit
}
} else if (type == EventType.WARNING_LOG) {
logsWarnCount.incrementAndGet()
if (warningLogIds.size < configService.logMessageBehavior.getWarnLogLimit()) {
warningLogIds[timestamp] = id
} else {
logger.logWarning("Warning Log limit has been reached.")
logger.logInfo("Warning Log limit has been reached.")
return@submit
}
} else if (type == EventType.ERROR_LOG) {
logsErrorCount.incrementAndGet()
if (errorLogIds.size < configService.logMessageBehavior.getErrorLogLimit()) {
errorLogIds[timestamp] = id
} else {
logger.logWarning("Error Log limit has been reached.")
logger.logInfo("Error Log limit has been reached.")
return@submit
}
} else {
Expand Down Expand Up @@ -226,7 +226,7 @@ internal class EmbraceLogMessageService(
null
)
if (checkIfShouldGateLog(type)) {
logger.logDebug("$type was gated by config. The event wasnot sent.")
logger.logDebug("$type was gated by config. The event was not sent.")
return@submit
}

Expand Down Expand Up @@ -284,7 +284,7 @@ internal class EmbraceLogMessageService(
maxLength >= endChars.length -> maxLength - endChars.length
else -> LogMessageBehavior.LOG_MESSAGE_MAXIMUM_ALLOWED_LENGTH - endChars.length
}
logger.logWarning("Truncating message to ${message.length} characters")
logger.logInfo("Truncating message to ${message.length} characters")
message.substring(0, allowedLength) + endChars
} else {
message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ internal class LogCounter(
if (logIds.size < getConfigLogLimit.invoke()) {
logIds[timestamp] = logId
} else {
logger.logWarning("$name log limit has been reached.")
logger.logInfo("$name log limit has been reached.")
return false
}
return true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal interface EmbLogger {
/**
* Logs an informational message.
*/
fun logInfo(msg: String)
fun logInfo(msg: String, throwable: Throwable? = null)

/**
* Logs a warning message with an optional throwable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ internal class EmbLoggerImpl : EmbLogger {
log(msg, Severity.DEBUG, throwable, true)
}

override fun logInfo(msg: String) {
log(msg, Severity.INFO, null, false)
override fun logInfo(msg: String, throwable: Throwable?) {
log(msg, Severity.INFO, throwable, false)
}

override fun logWarning(msg: String, throwable: Throwable?, logStacktrace: Boolean) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class EmbraceMemoryCleanerService(private val logger: EmbLogger) : Memo
try {
listener.cleanCollections()
} catch (ex: Exception) {
logger.logDebug("Failed to clean collections on service listener", ex)
logger.logWarning("Failed to clean collections on service listener", ex)
}
}
internalErrorService.resetExceptionErrorObject()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ internal class PeriodicBackgroundActivityCacher(
lastSaved = clock.now()
}
} catch (ex: Exception) {
logger.logDebug("Error while caching active session", ex)
logger.logWarning("Error while caching active session", ex)
}
}
scheduledFuture = scheduledWorker.schedule<Unit>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ internal class PeriodicSessionCacher(
try {
provider()
} catch (ex: Exception) {
logger.logDebug("Error while caching active session", ex)
logger.logWarning("Error while caching active session", ex)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ internal class ActivityLifecycleTracker(
try {
orientationService.onOrientationChanged(activity.resources.configuration.orientation)
} catch (ex: Exception) {
logger.logDebug("Failed to register an orientation change", ex)
logger.logWarning("Failed to register an orientation change", ex)
}
}

Expand All @@ -78,7 +78,7 @@ internal class ActivityLifecycleTracker(
try {
listener.onActivityCreated(activity, bundle)
} catch (ex: Exception) {
logger.logDebug(ERROR_FAILED_TO_NOTIFY, ex)
logger.logWarning(ERROR_FAILED_TO_NOTIFY, ex)
}
}
}
Expand All @@ -89,7 +89,7 @@ internal class ActivityLifecycleTracker(
try {
listener.onView(activity)
} catch (ex: Exception) {
logger.logDebug(ERROR_FAILED_TO_NOTIFY, ex)
logger.logWarning(ERROR_FAILED_TO_NOTIFY, ex)
}
}
}
Expand All @@ -102,7 +102,7 @@ internal class ActivityLifecycleTracker(
try {
listener.applicationStartupComplete()
} catch (ex: Exception) {
logger.logDebug(ERROR_FAILED_TO_NOTIFY, ex)
logger.logWarning(ERROR_FAILED_TO_NOTIFY, ex)
}
}
}
Expand All @@ -114,7 +114,7 @@ internal class ActivityLifecycleTracker(
try {
listener.onViewClose(activity)
} catch (ex: Exception) {
logger.logDebug(ERROR_FAILED_TO_NOTIFY, ex)
logger.logWarning(ERROR_FAILED_TO_NOTIFY, ex)
}
}
}
Expand All @@ -135,7 +135,7 @@ internal class ActivityLifecycleTracker(
application.unregisterActivityLifecycleCallbacks(this)
listeners.clear()
} catch (ex: Exception) {
logger.logDebug("Error when closing EmbraceActivityService", ex)
logger.logWarning("Error when closing EmbraceActivityService", ex)
}
}

Expand Down
Loading

0 comments on commit 7cf7e68

Please sign in to comment.