Message Logging

Alpha Documentation

The documentation for the Enjin SDKs pertain to the Project and Player schemas which are currently in an Alpha release. The Project and Player schemas are not yet publicly available and therefore this documentation is limited only to those who already have access. For any queries, please contact Enjin Support.

Logger

ILogger Interface

For logging the SDKs define a 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:
  • TRACE
  • DEBUG
  • INFO
  • WARN
  • ERROR/ERR
  • SEVERE

Logger Provider

The LoggerProvider is the highest level class that we interact with when utilizing a SDKs logging functions. The LoggerProvider allows components within the SDKs to share log settings and resources if we desire and in turn helps us save resources as well.
To use the LoggerProvider we must pass it 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#
C++
1
import com.enjin.sdk.utils.Logger;
2
import com.enjin.sdk.utils.LoggerProvider;
3
​
4
Logger logger = new Logger();
5
​
6
LoggerProvider provider = new LoggerProvider(logger);
Copied!
1
using Enjin.SDK.Utils;
2
​
3
Logger logger = new Logger();
4
​
5
LoggerProvider provider = new LoggerProvider(logger);
Copied!
1
#include "enjinsdk/Logger.hpp"
2
#include "enjinsdk/LoggerProvider.hpp"
3
#include <memory>
4
​
5
using namespace enjin::sdk::utils;
6
​
7
std::shared_ptr<Logger> logger = std::make_shared<Logger>();
8
​
9
std::shared_ptr<LoggerProvider> provider = std::make_shared<LoggerProvider>(logger);
Copied!
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#
C++
1
import com.enjin.sdk.utils.LogLevel;
2
import com.enjin.sdk.utils.LoggerProvider;
3
​
4
LogLevel message = LogLevel.WARN;
5
LogLevel debug = LogLevel.ERROR;
6
​
7
// With a defined ILogger instance
8
new LoggerProvider(logger, message, debug);
Copied!
1
using Enjin.SDK.Utils;
2
​
3
LogLevel message = LogLevel.WARN;
4
LogLevel debug = LogLevel.ERROR;
5
​
6
// With a defined ILogger instance
7
new LoggerProvider(logger, message, debug);
Copied!
1
#include "enjinsdk/ILogger.hpp"
2
#include "enjinsdk/LoggerProvider.hpp"
3
#include <memory>
4
​
5
using namespace enjin::sdk::utils;
6
​
7
LogLevel message = LogLevel::WARN;
8
LogLevel debug = LogLevel::ERR;
9
​
10
// With a defined ILogger instance
11
std::make_shared<LoggerProvider>(logger, message, debug);
Copied!
By default the LoggerProvider sets the message level to INFO and the debug level to DEBUG if we do not define them ourselves.
We may pass the LoggerProvider to top level SDK class that accept it, such as the ProjectClient as can be seen below:
Java
C#
C++
1
import com.enjin.sdk.ProjectClient;
2
​
3
ProjectClient client = new ProjectClient("<enjin-host-uri>", true, provider);
Copied!
1
using Enjin.SDK;
2
​
3
ProjectClient client = new ProjectClient("<enjin-host-uri>", provider);
Copied!
1
#include "enjinsdk/ProjectClient.hpp"
2
#include <memory>
3
​
4
using namespace enjin::sdk;
5
​
6
std::unique_ptr<ProjectClient> client = ProjectClientBuilder()
7
.base_uri("<enjin-host-uri>")
8
.logger_provider(provider)
9
.build();
Copied!
Last modified 2mo ago