Skip to content

Commit 5c49d04

Browse files
committed
Proxy logging
1 parent 461943d commit 5c49d04

36 files changed

+269
-122
lines changed

android/airship-framework-proxy/src/main/java/com/urbanairship/android/framework/proxy/AirshipListener.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.urbanairship.android.framework.proxy
22

33
import com.urbanairship.Airship
4+
import com.urbanairship.UALog
45
import com.urbanairship.actions.DeepLinkListener
56
import com.urbanairship.android.framework.proxy.events.ChannelCreatedEvent
67
import com.urbanairship.android.framework.proxy.events.DeepLinkEvent
@@ -120,7 +121,7 @@ internal class AirshipListener(
120121
val override = AirshipPluginExtensions.onDeepLink?.invoke(deepLink)
121122
when(override) {
122123
is AirshipPluginOverride.Override -> {
123-
ProxyLogger.debug("Deeplink handling for $deepLink overridden by plugin extension")
124+
UALog.d { "Deeplink handling for $deepLink overridden by plugin extension" }
124125
}
125126
is AirshipPluginOverride.UseDefault, null -> {
126127
eventEmitter.addEvent(DeepLinkEvent(deepLink))

android/airship-framework-proxy/src/main/java/com/urbanairship/android/framework/proxy/BaseAutopilot.kt

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import androidx.annotation.XmlRes
1010
import com.urbanairship.Airship
1111
import com.urbanairship.AirshipConfigOptions
1212
import com.urbanairship.Autopilot
13+
import com.urbanairship.UALog
1314
import com.urbanairship.Predicate
1415
import com.urbanairship.android.framework.proxy.Utils.getNamedResource
1516
import com.urbanairship.android.framework.proxy.events.EventEmitter
@@ -41,8 +42,7 @@ public abstract class BaseAutopilot : Autopilot() {
4142
private val dispatcher = CoroutineScope(Dispatchers.Main + SupervisorJob())
4243

4344
final override fun onAirshipReady(context: Context) {
44-
45-
ProxyLogger.setLogLevel(Airship.airshipConfigOptions.logLevel.level)
45+
UALog.v { "Airship ready, registering listeners and applying notification config" }
4646

4747
val proxyStore = AirshipProxy.shared(context).proxyStore
4848
val airshipListener = AirshipListener(
@@ -111,6 +111,7 @@ public abstract class BaseAutopilot : Autopilot() {
111111
loadCustomNotificationChannels(context)
112112
loadCustomNotificationButtonGroups(context)
113113

114+
UALog.v { "Notification config and listeners applied" }
114115
onReady(context)
115116

116117
extenderProvider.get(context)?.onAirshipReady(context)
@@ -125,7 +126,7 @@ public abstract class BaseAutopilot : Autopilot() {
125126
@XmlRes val resId = context.resources.getIdentifier("ua_custom_notification_channels", "xml", packageName)
126127

127128
if (resId != 0) {
128-
ProxyLogger.debug("Loading custom notification channels")
129+
UALog.d { "Loading custom notification channels" }
129130
Airship.push.notificationChannelRegistry.createNotificationChannels(resId)
130131
}
131132
}
@@ -136,7 +137,7 @@ public abstract class BaseAutopilot : Autopilot() {
136137
@XmlRes val resId = context.resources.getIdentifier("ua_custom_notification_buttons", "xml", packageName)
137138

138139
if (resId != 0) {
139-
ProxyLogger.debug("Loading custom notification button groups")
140+
UALog.d { "Loading custom notification button groups" }
140141
Airship.push.addNotificationActionButtonGroups(context, resId)
141142
}
142143
}
@@ -149,6 +150,7 @@ public abstract class BaseAutopilot : Autopilot() {
149150

150151
var builder = createConfigBuilder(context)
151152
AirshipProxy.shared(context).proxyStore.airshipConfig?.let {
153+
UALog.v { "Applying proxy config to Airship config" }
152154
builder.applyProxyConfig(context, it)
153155
}
154156

@@ -159,8 +161,10 @@ public abstract class BaseAutopilot : Autopilot() {
159161
return try {
160162
configOptions.validate()
161163
this.configOptions = configOptions
164+
UALog.i { "Airship config validated successfully" }
162165
true
163-
} catch (_: Exception) {
166+
} catch (e: Exception) {
167+
UALog.w { "Airship config validation failed: ${e.message}" }
164168
false
165169
}
166170
}
@@ -171,7 +175,7 @@ public abstract class BaseAutopilot : Autopilot() {
171175
try {
172176
it.tryApplyDefaultProperties(context)
173177
} catch (e: Exception) {
174-
ProxyLogger.verbose("Failed to load config from properties file: " + e.message)
178+
UALog.v { "Failed to load config from properties file: ${e.message}" }
175179
}
176180
it
177181
}
@@ -275,7 +279,7 @@ private class ExtenderProvider {
275279
val extenderClass = Class.forName(classname)
276280
return extenderClass.getDeclaredConstructor().newInstance() as AirshipPluginExtender
277281
} catch (e: Exception) {
278-
ProxyLogger.error(e, "Unable to create extender: $classname")
282+
UALog.e(e) { "Unable to create extender: $classname" }
279283
}
280284
return null
281285
}

android/airship-framework-proxy/src/main/java/com/urbanairship/android/framework/proxy/CustomMessageActivity.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class CustomMessageActivity : FragmentActivity() {
4040
Autopilot.automaticTakeOff(application)
4141

4242
if (!Airship.isFlyingOrTakingOff) {
43-
UALog.e("MessageActivity - unable to create Activity, takeOff not called.")
43+
UALog.e { "MessageActivity - unable to create Activity, takeOff not called. intent=$intent" }
4444
finish()
4545
return
4646
}
@@ -49,7 +49,7 @@ public class CustomMessageActivity : FragmentActivity() {
4949
?: MessageCenter.parseMessageId(intent)
5050

5151
if (messageId == null) {
52-
UALog.w("MessageActivity - unable to display message, messageId is null!")
52+
UALog.w { "MessageActivity - unable to display message, messageId is null. intent=$intent" }
5353
finish()
5454
return
5555
}

android/airship-framework-proxy/src/main/java/com/urbanairship/android/framework/proxy/CustomMessageCenterActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public class CustomMessageCenterActivity : FragmentActivity() {
3636
Autopilot.automaticTakeOff(application)
3737

3838
if (!Airship.isFlyingOrTakingOff) {
39-
UALog.e("MessageCenterActivity - unable to create activity, takeOff not called.")
39+
UALog.e { "MessageCenterActivity - unable to create activity, takeOff not called. intent=$intent" }
4040
finish()
4141
return
4242
}

android/airship-framework-proxy/src/main/java/com/urbanairship/android/framework/proxy/ProxyLogger.kt

Lines changed: 27 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,26 @@
22

33
package com.urbanairship.android.framework.proxy
44

5-
import android.util.Log
6-
import java.util.*
5+
import com.urbanairship.UALog
76

87
/**
9-
* Plugin logger
8+
* Plugin logger.
9+
*
10+
* @deprecated Use [UALog] instead. This class is retained for backward compatibility only.
1011
*/
12+
@Deprecated("Use UALog instead", ReplaceWith("UALog"))
1113
public object ProxyLogger {
1214

13-
private const val TAG = "UALib-Framework"
14-
15-
/**
16-
* The current log level, as defined by `android.util.Log`.
17-
* Defaults to `android.util.Log.ERROR`.
18-
*/
19-
private var logLevel = Log.VERBOSE
20-
21-
/**
22-
* Sets the log level.
23-
*
24-
* @param logLevel The log level.
25-
*/
26-
@JvmStatic
27-
internal fun setLogLevel(logLevel: Int) {
28-
this.logLevel = logLevel
29-
}
30-
3115
/**
3216
* Send a warning log message.
3317
*
3418
* @param message The message you would like logged.
3519
* @param args The message args.
3620
*/
21+
@Deprecated("Use UALog.w instead", ReplaceWith("UALog.w(message, *args)"))
3722
@JvmStatic
3823
public fun warn(message: String, vararg args: Any?) {
39-
log(Log.WARN, null, message, *args)
24+
UALog.w(message, *args)
4025
}
4126

4227
/**
@@ -46,19 +31,21 @@ public object ProxyLogger {
4631
* @param message The message you would like logged.
4732
* @param args The message args.
4833
*/
34+
@Deprecated("Use UALog.w instead", ReplaceWith("UALog.w(t, message, *args)"))
4935
@JvmStatic
5036
public fun warn(t: Throwable, message: String, vararg args: Any?) {
51-
log(Log.WARN, t, message, *args)
37+
UALog.w(t, message, *args)
5238
}
5339

5440
/**
5541
* Send a warning log message.
5642
*
5743
* @param t An exception to log
5844
*/
45+
@Deprecated("Use UALog.w instead", ReplaceWith("UALog.w(t)"))
5946
@JvmStatic
6047
public fun warn(t: Throwable) {
61-
log(Log.WARN, t, null)
48+
UALog.w(t)
6249
}
6350

6451
/**
@@ -67,9 +54,10 @@ public object ProxyLogger {
6754
* @param message The message you would like logged.
6855
* @param args The message args.
6956
*/
57+
@Deprecated("Use UALog.v instead", ReplaceWith("UALog.v(message, *args)"))
7058
@JvmStatic
7159
public fun verbose(message: String, vararg args: Any?) {
72-
log(Log.VERBOSE, null, message, *args)
60+
UALog.v(message, *args)
7361
}
7462

7563
/**
@@ -78,9 +66,10 @@ public object ProxyLogger {
7866
* @param message The message you would like logged.
7967
* @param args The message args.
8068
*/
69+
@Deprecated("Use UALog.d instead", ReplaceWith("UALog.d(message, *args)"))
8170
@JvmStatic
8271
public fun debug(message: String, vararg args: Any?) {
83-
log(Log.DEBUG, null, message, *args)
72+
UALog.d(message, *args)
8473
}
8574

8675
/**
@@ -90,9 +79,10 @@ public object ProxyLogger {
9079
* @param message The message you would like logged.
9180
* @param args The message args.
9281
*/
82+
@Deprecated("Use UALog.d instead", ReplaceWith("UALog.d(t, message, *args)"))
9383
@JvmStatic
9484
public fun debug(t: Throwable, message: String, vararg args: Any?) {
95-
log(Log.DEBUG, t, message, *args)
85+
UALog.d(t, message, *args)
9686
}
9787

9888
/**
@@ -101,9 +91,10 @@ public object ProxyLogger {
10191
* @param message The message you would like logged.
10292
* @param args The message args.
10393
*/
94+
@Deprecated("Use UALog.i instead", ReplaceWith("UALog.i(message, *args)"))
10495
@JvmStatic
10596
public fun info(message: String, vararg args: Any) {
106-
log(Log.INFO, null, message, *args)
97+
UALog.i(message, *args)
10798
}
10899

109100
/**
@@ -113,9 +104,10 @@ public object ProxyLogger {
113104
* @param message The message you would like logged.
114105
* @param args The message args.
115106
*/
107+
@Deprecated("Use UALog.i instead", ReplaceWith("UALog.i(t, message, *args)"))
116108
@JvmStatic
117109
public fun info(t: Throwable, message: String, vararg args: Any?) {
118-
log(Log.INFO, t, message, *args)
110+
UALog.i(t, message, *args)
119111
}
120112

121113
/**
@@ -124,19 +116,21 @@ public object ProxyLogger {
124116
* @param message The message you would like logged.
125117
* @param args The message args.
126118
*/
119+
@Deprecated("Use UALog.e instead", ReplaceWith("UALog.e(message, *args)"))
127120
@JvmStatic
128121
public fun error(message: String, vararg args: Any?) {
129-
log(Log.ERROR, null, message, *args)
122+
UALog.e(message, *args)
130123
}
131124

132125
/**
133126
* Send an error log message.
134127
*
135128
* @param t An exception to log
136129
*/
130+
@Deprecated("Use UALog.e instead", ReplaceWith("UALog.e(t)"))
137131
@JvmStatic
138132
public fun error(t: Throwable) {
139-
log(Log.ERROR, t, null)
133+
UALog.e(t)
140134
}
141135

142136
/**
@@ -146,61 +140,9 @@ public object ProxyLogger {
146140
* @param message The message you would like logged.
147141
* @param args The message args.
148142
*/
143+
@Deprecated("Use UALog.e instead", ReplaceWith("UALog.e(t, message, *args)"))
149144
@JvmStatic
150145
public fun error(t: Throwable, message: String, vararg args: Any?) {
151-
log(Log.ERROR, t, message, *args)
152-
}
153-
154-
/**
155-
* Helper method that performs the logging.
156-
*
157-
* @param priority The log priority level.
158-
* @param throwable The optional exception.
159-
* @param message The optional message.
160-
* @param args The optional message args.
161-
*/
162-
private fun log(priority: Int, throwable: Throwable?, message: String?, vararg args: Any?) {
163-
if (logLevel > priority) {
164-
return
165-
}
166-
167-
if (message == null && throwable == null) {
168-
return
169-
}
170-
171-
val formattedMessage: String? = if (message.isNullOrEmpty()) {
172-
// Default to empty string
173-
""
174-
} else {
175-
// Format the message if we have arguments
176-
try {
177-
if (args.isEmpty()) {
178-
message
179-
} else {
180-
String.format(Locale.ROOT, message!!, *args)
181-
}
182-
} catch (e: Exception) {
183-
Log.wtf(TAG, "Failed to format log.", e)
184-
return
185-
}
186-
}
187-
188-
// Log directly if we do not have a throwable
189-
if (throwable == null) {
190-
if (priority == Log.ASSERT) {
191-
Log.wtf(TAG, formattedMessage)
192-
} else {
193-
Log.println(priority, TAG, formattedMessage!!)
194-
}
195-
return
196-
}
197-
when (priority) {
198-
Log.INFO -> Log.i(TAG, formattedMessage, throwable)
199-
Log.DEBUG -> Log.d(TAG, formattedMessage, throwable)
200-
Log.VERBOSE -> Log.v(TAG, formattedMessage, throwable)
201-
Log.WARN -> Log.w(TAG, formattedMessage, throwable)
202-
Log.ERROR -> Log.e(TAG, formattedMessage, throwable)
203-
Log.ASSERT -> Log.wtf(TAG, formattedMessage, throwable)
204-
}
146+
UALog.e(t, message, *args)
205147
}
206148
}

android/airship-framework-proxy/src/main/java/com/urbanairship/android/framework/proxy/ProxyStore.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package com.urbanairship.android.framework.proxy
55
import android.annotation.SuppressLint
66
import android.content.Context
77
import com.urbanairship.android.framework.proxy.proxies.PushProxy
8+
import com.urbanairship.UALog
89
import com.urbanairship.json.JsonSerializable
910
import com.urbanairship.json.JsonValue
1011
import com.urbanairship.json.jsonMapOf
@@ -72,7 +73,7 @@ public class ProxyStore internal constructor(private val context: Context) {
7273
val json = JsonValue.parseString(jsonString)
7374
parser(json)
7475
} catch (e: Exception) {
75-
ProxyLogger.error("Failed to parse $key in config.", e)
76+
UALog.e(e) { "Failed to parse $key in config." }
7677
null
7778
}
7879
}

android/airship-framework-proxy/src/main/java/com/urbanairship/android/framework/proxy/Utils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import android.util.Log
88
import androidx.annotation.ColorInt
99
import com.urbanairship.AirshipConfigOptions
1010
import com.urbanairship.PrivacyManager
11-
import com.urbanairship.android.framework.proxy.ProxyLogger.error
11+
import com.urbanairship.UALog
1212
import com.urbanairship.json.JsonException
1313
import com.urbanairship.json.JsonValue
1414
import com.urbanairship.push.PushMessage
@@ -107,7 +107,7 @@ public object Utils {
107107
if (id != 0) {
108108
return id
109109
} else {
110-
error("Unable to find resource with name: %s", resourceName)
110+
UALog.e { "Unable to find resource with name: $resourceName" }
111111
}
112112
}
113113
return 0
@@ -127,7 +127,7 @@ public object Utils {
127127
try {
128128
return hexColor.toColorInt()
129129
} catch (e: IllegalArgumentException) {
130-
error(e, "Unable to parse color: %s", hexColor)
130+
UALog.e(e) { "Unable to parse color: $hexColor" }
131131
}
132132
}
133133
return defaultColor

0 commit comments

Comments
 (0)