Logging
The FACEIT SDK outputs log messages during operation. Each SDK feature outputs its log messages on a corresponding log channel, whose verbosity may be set according to user preference.
Although the examples below are written in reference to the game client SDK, the same principle applies for the server SDK.
Log Callback
If a developer chooses to use the FACEIT SDK libraries directly, they must set a log callback in order to receive log messages. The developer may then choose to forward these log messages however they like - for example, to an output stream, or a file on disk.
info
Log messages emitted by the FACEIT Unreal Engine plugins do not require a callback to be set. These messages are passed directly to Unreal's logging system, using Unreal logging classes defined for the client and server plugins respectively.
- C++
- C#
#include <string>
#include <cstdio>
#include "FACEITGameClientSDK/Log.h"
#include "FACEITGameClientSDK/Utilities/StringHelpers.h"
FGCSDK_SetLogMessageCallback(
[](const FGCSDK_LogMessageCallbackInfo* info)
{
const std::string logChannelString = FGCSDK_ToString(FGCSDK_GetLogChannelString, info->channel);
const std::string logLevelString = FGCSDK_ToString(FGCSDK_GetLogLevelString, info->level);
// This call prints a log message that might look like:
// [Matchmaking] (Session:BeginSession) Warning: This is a warning message
printf("[%s] (%s:%s) %s: %s\n",
logChannelString.c_str(),
info->context,
info->source,
logLevelString.c_str(),
info->message);
});
using FACEITGameClientSDK;
Log.SetLogMessageCallback(OnLogMessage);
private static void OnLogMessage(in Log.LogMessageCallbackInfo info)
{
string channelName = Log.GetLogChannelString(info.Channel);
string levelName = Log.GetLogLevelString(info.Level);
// This call prints a log message that might look like:
// [Matchmaking] (Session:BeginSession) Warning: This is a warning message
Console.WriteLine($"[{channelName}] ({info.Context}:{info.Source}) {levelName}: {info.Message}");
}
The log callback can also be cleared by calling ClearLogMessageCallback()
.
- C++
- C#
FGCSDK_ClearLogMessageCallback();
Log.ClearLogMessageCallback();
Log Levels
Log verbosity levels can be set per channel, or a single level may be set collectively for all channels. When setting a verbosity level, only log messages that are at least as severe as this level will be emitted on the log callback.
Setting a log level for a specific channel can either be done by calling the SetLogVerbosity()
function in the logging interface and specifying a channel:
- C++
- C#
#include "FACEITGameClientSDK/Log.h"
FGCSDK_SetLogVerbosity(FGCSDK_ANTICHEAT_LOG_CHANNEL, FGCSDK_LOG_DEBUG);
using FACEITGameClientSDK;
Log.SetLogVerbosity(Log.Channel.Anticheat, Log.Level.Debug);
Or by calling the SetLogVerbosity()
function included in the interface for a specific feature:
- C++
- C#
#include "FACEITGameClientSDK/Anticheat/Anticheat.h"
FGCSDK_AC_SetLogVerbosity(FGCSDK_LOG_DEBUG);
using FACEITGameClientSDK;
Anticheat.SetLogVerbosity(Log.Level.Debug);
Setting the same log verbosity level for all SDK log channels can be achieved by calling the SetLogVerbosityForEveryChannel()
function in the logging interface.
- C++
- C#
#include "FACEITGameClientSDK/Log.h"
FGCSDK_SetLogVerbosityForEveryChannel(FGCSDK_LOG_DEBUG);
using FACEITGameClientSDK;
Log.SetLogVerbosityForEveryChannel(Log.Level.Debug);
info
The Match Life Cycle feature in the server SDK will automatically update the log level from the value stored in the FACEIT_SERVER_PLUGIN_LOGLEVEL
environment variable. This update is performed when a new Match Life Cycle session is started.
The Match Life Cycle feature is currently the only area of the server SDK where changing settings via environment variables is supported. Other interfaces may support this in future.