Message Logging

Logger

ILogger Interface

For logging, the SDKs define an ILogger interface that provides a common API for their logging purposes.

Built-in Logger

Each SDK comes with a built-in Logger class that implements the ILogger interface. These loggers offer basic functionality that allow us to jump into using logging features without dedicating too much time to develop our own implementation first.

Message Levels

For logging, the SDKs define six levels that messages may be logged on. These log levels are:
  • DEBUG
  • TRACE
  • INFO
  • WARN
  • ERROR
  • SEVERE
Some SDKs may not support all message levels for their built-in Logger class. Check the class documentation to see which log levels the logger may utilize.

Logger Provider

The LoggerProvider is the highest level class that we interact with when utilizing logging functions in the SDKs. The logger provider allows components within the SDKs to share log settings and resources and helps us save resources as well.
To use LoggerProvider we must pass an instance of a class implementing the ILogger interface, such as the Logger class built into the SDKs as shown in the example below:
Java
C# | Unity
C++
import com.enjin.sdk.utils.Logger;
import com.enjin.sdk.utils.LoggerProvider;
Logger logger = new Logger();
LoggerProvider provider = new LoggerProvider(logger);
using Enjin.SDK.Utils;
Logger logger = new Logger();
LoggerProvider provider = new LoggerProvider(logger);
#include "enjinsdk/Logger.hpp"
#include "enjinsdk/LoggerProvider.hpp"
#include <memory>
using namespace enjin::sdk::utils;
std::shared_ptr<Logger> logger = std::make_shared<Logger>();
std::shared_ptr<LoggerProvider> provider = std::make_shared<LoggerProvider>(logger);
When creating the LoggerProvider we may also choose to define the default message level and the default debug level it calls the logger on as shown in the example below:
Java
C# | Unity
C++
import com.enjin.sdk.utils.LogLevel;
import com.enjin.sdk.utils.LoggerProvider;
LogLevel message = LogLevel.WARN;
LogLevel debug = LogLevel.ERROR;
// With a defined ILogger instance
new LoggerProvider(logger, message, debug);
using Enjin.SDK.Utils;
LogLevel message = LogLevel.WARN;
LogLevel debug = LogLevel.ERROR;
// With a defined ILogger instance
new LoggerProvider(logger, message, debug);
#include "enjinsdk/LogLevel.hpp"
#include "enjinsdk/LoggerProvider.hpp"
#include <memory>
using namespace enjin::sdk::utils;
LogLevel message = LogLevel::Warn;
LogLevel debug = LogLevel::Error;
// With a defined ILogger instance
std::make_shared<LoggerProvider>(logger, message, debug);
By default, LoggerProvider sets the message level to INFO and the debug level to DEBUG if we do not define them ourselves.

HTTP Traffic Logging

Platform clients may be configured to log the traffic of the requests and responses they send to and receive from the platform. We use an enum, HttpLogLevel to define the log levels we may use for HTTP traffic. These log levels are:
  • NONE
  • BASIC
  • HEADERS
  • BODY
The default log level for HTTP traffic is NONE making this an opt-in feature, which will require us to declare the log level we will want to use. BASIC enables logging of the request method (e.g. GET, POST, etc...), the URI, the content-length as well as the response's status, URI, and round-trip time. HEADERS is similar to BASIC, but also includes the request and response headers. And finally, BODY logs similar information as HEADERS but also includes the entire content body of out going requests and incoming responses.
CAUTION: When using the BODY log level, any AuthProject request will be logged as well as the project's secret key which is sent as a parameter of the request.
To configure the client, we call a method on its builder to set the HTTP log level and we must also provide an instance of LoggerProvider that log messages will be sent to as shown in the example below:
Java
C# | Unity
C++
import com.enjin.sdk.http.HttpLogLevel;
HttpLogLevel basic = HttpLogLevel.BASIC;
HttpLogLevel headers = HttpLogLevel.HEADERS;
HttpLogLevel body = HttpLogLevel.BODY;
// Builder from either ProjectClient or PlayerClient
builder.httpLogLevel(/* HTTP log level here */)
.loggerProvider(/* LoggerProvider here */);
using Enjin.SDK.Http;
HttpLogLevel basic = HttpLogLevel.BASIC;
HttpLogLevel headers = HttpLogLevel.HEADERS;
HttpLogLevel body = HttpLogLevel.BODY;
// Builder from either ProjectClient or PlayerClient
builder.HttpLogLevel(/* HTTP log level here */)
.LoggerProvider(/* LoggerProvider here */);
#include "enjinsdk/HttpLogLevel.hpp"
using namespace enjin::sdk::http;
HttpLogLevel basic = HttpLogLevel::Basic;
HttpLogLevel headers = HttpLogLevel::Headers;
HttpLogLevel body = HttpLogLevel::Body;
// Builder from either ProjectClient or PlayerClient
builder.http_log_level(/* HTTP log level here */)
.logger_provider(/* LoggerProvider shared-pointer here */);

Cloud Event Logging

The PusherEventService may be configured to log incoming cloud events or any errors it encounters by providing its builder with a logger provider as shown below:
Java
C# | Unity
C++
// Builder from PusherEventService
builder.loggerProvider(/* LoggerProvider here */);
// Builder from PusherEventService
builder.LoggerProvider(/* LoggerProvider here */);
// Builder from PusherEventService
builder.logger_provider(/* LoggerProvider shared-pointer here */);