Appearance
PH Logger
Summary
PH Logger is an interface that allows apps to implement their own custom logger to consume information about events triggering inside Platform Hub. This will be useful for logging information to end user monitoring services.
How it works in Android
App needs to implement the Logger which is provided by the platformHub which has overriden method fun log(logInfo: LogInfo) of Logger class which can be used to log events.
LoggingInfo
LogInfo is the base class to log information which provides the common fields for the other log info classes to inherit from.
kotlin
class LogInfo(
open val messageType: MessageType,
open val messageName: String,
open val payload: JSONObject?
)Parameters:
- MessageType : The type of message being logged (i.e. Command, Query, etc.)
- messageName : The name of the message being logged
- payload : The input payload of the message being
MessageType :
MessageType describes the information exchange and events that take place in the PlatformHub ecosystem. It is an enum containing different cases to depict the different messages, events and internal plugin actions that occur in the PlatformHub ecosystem at runtime.
kotlin
enum class MessageType {
EventStream, Command, NavigationQuery, Query, InternalPluginAction
}PlatformHub maintains an enum with 5 different types of messages.
- EventStream : The [EventStream] message type is used by the [Plugin.publisher] and [Plugin.subscribe] to publish and receive messages.
kotlin
LogInfo.EventStreamInfo -> """
===============Event Info===============
Publisher: ${logInfo.publisherPlugin}
Subscribers: ${logInfo.subscriberPlugins}
Message: ${logInfo.messageName}
Message Type: ${logInfo.messageType.name}
Input Payload: ${logInfo.payload?.toString()}
Timestamp: ${logInfo.timestamp}
EventStreamResult:${logInfo.resultPayload}
========================================
""".trimIndent()- Command : The [Command] message type is used for messages that performs some background tasks before returning results.
kotlin
if (logInfo.messageType == MessageType.Command) {
"""
==============Message Info==============
Sender: ${logInfo.senderPlugin}
Receiver: ${logInfo.receiverPlugin}
Message: ${logInfo.messageName}
Message Type: ${logInfo.messageType.name}
Input Payload: ${logInfo.payload?.toString()}
Output Payload: ${logInfo.responsePayload?.toString()}
Timestamp: ${logInfo.timestamp}
========================================
""".trimIndent()
}- NavigationQuery : The [NavigationQuery] message type is used for navigating from one plugin to another.
kotlin
if (logInfo.messageType == MessageType.NavigationQuery) {
"""
==============Message Info==============
Sender: ${logInfo.senderPlugin}
Receiver: ${logInfo.receiverPlugin}
Message: ${logInfo.messageName}
Message Type: ${logInfo.messageType.name}
Input Payload: ${logInfo.payload?.toString()}
Timestamp: ${logInfo.timestamp}
========================================
""".trimIndent()
}- Query : The [Query] message type is used for messages that return results immediately.
kotlin
if (logInfo.messageType == MessageType.Query) {
"""
==============Message Info==============
Sender: ${logInfo.senderPlugin}
Receiver: ${logInfo.receiverPlugin}
Message: ${logInfo.messageName}
Message Type: ${logInfo.messageType.name}
Input Payload: ${logInfo.payload?.toString()}
Output Payload: ${logInfo.responsePayload?.toString()}
Timestamp: ${logInfo.timestamp}
========================================
""".trimIndent()
}- InternalPluginAction : Provides log information for internal actions.
kotlin
LogInfo.InternalPluginAction -> """
===============PluginInternalAction Info===============
Message: ${logInfo.pluginName}
Message: ${logInfo.messageName}
Message Type: ${logInfo.messageType.name}
Input Payload: ${logInfo.payload?.toString()}
Timestamp: ${logInfo.timestamp}
========================================
""".trimIndent()
}MultiLogger
MultiLogger inherits Logging protocol and allows to have several loggers in use for example: There could be a logger which logs information to the console and there is another one which sends logs to Analytics.
kotlin
abstract class MultiLogger(val assetsLoader: AssetsLoader, private val loggers: List<Logger>) : Logger(assetsLoader) {
override fun log(logInfo: LogInfo) {}
}Parameters:
- assetLoader : Loads file from the assets directory by name.
- loggers : An array of Loggers (Logging Protocol) which contains all the passed loggers and used to log PlatformHub operations.
Note:
In recent PH release, The Logger class now requires an AssetLoader instance to be provided via its constructor. This affects any existing code that directly instantiates Logger. Ensure to update code accordingly by providing an AssetLoader instance when creating a new Logger or extending the Logger class.