1 // Copyright 2015-present 650 Industries. All rights reserved. 2 package host.exp.exponent.analytics 3 4 import android.util.Log 5 import host.exp.exponent.Constants 6 import org.json.JSONObject 7 8 // EXpo Log 9 object EXL { 10 private val TAG = EXL::class.java.simpleName 11 12 // Use this for errors that we expect to happen in tests. They will only log it 13 // they occur outside of a test environment. 14 fun testError(e: Throwable) { 15 if (!Constants.isTest()) { 16 e.printStackTrace() 17 } 18 } 19 20 @JvmStatic fun d(tag: String?, msg: String) { 21 Log.d(tag, msg) 22 } 23 24 @JvmStatic fun w(tag: String?, msg: String) { 25 Log.w(tag, msg) 26 } 27 28 // TODO send string version of Throwable to Amplitude 29 @JvmStatic fun e(tag: String?, e: Throwable) { 30 Log.e(tag, e.toString()) 31 } 32 33 @JvmStatic fun e(tag: String?, msg: String?) { 34 Log.e(tag, msg ?: "") 35 36 try { 37 val stackTrace = Log.getStackTraceString(Throwable()) 38 val eventProperties = JSONObject().apply { 39 put("TAG", tag) 40 put("MESSAGE", msg) 41 put("STACK_TRACE", stackTrace) 42 } 43 Analytics.logEvent(Analytics.AnalyticsEvent.LOG_ERROR, eventProperties) 44 } catch (e: Throwable) { 45 Log.e(TAG, e.toString()) 46 } 47 } 48 } 49