Logging¶
The Scorbit SDK includes a flexible logging system to help developers debug and monitor networking activity. It supports configurable log levels, allowing developers to control the verbosity of output based on the severity of messages.
Logging Levels¶
The logging system supports the following levels of severity:
Debug
: Detailed information, typically of interest only when diagnosing problems.Info
: Confirmation that things are working as expected.Warn
: An indication that something unexpected happened, or indicative of some problem in the near future. The software is still functioning as expected.Error
: Due to a more serious problem, the software has not been able to perform some function.
Timestamps and Log Order¶
Each log message generated by the Scorbit SDK includes a timestamp in milliseconds since the Unix epoch. This helps identify when each event occurred.
However, since Scorbit SDK logs are queued and processed in a separate thread from where they are generated, the timestamp may appear slightly earlier than the moment the corresponding callback or event handler is actually invoked. This can lead to log order discrepancies when mixing SDK logs with your own application logs.
Example:
[2025-06-01 17:36:60.030] Game client's own log message
[2025-06-01 17:36:59.932] [INF] API send installed: type=sdk, version=1.0.3, installed=true, log: none
In this example, the SDK log appears with an earlier timestamp than the game’s own log message, even though it was processed later. This is expected behavior due to asynchronous logging.
Recommendation
If precise log synchronization is important for your debugging workflow, consider tagging SDK log entries with your own timestamping mechanism at the point they are received. This will help ensure consistent chronological ordering in your combined logs.
Setup Logging callbacks¶
To set up logging callbacks, you can use the set_log_callback
function. This function allows you to specify a callback that will be called whenever a log message is generated.
For C you can give a user data pointer which will be passed to the callback function, for C++ and Python you can use a lambda function or a method of a class.
// Custom logger callback function
void loggerCallback(const char *message, sb_log_level_t level, const char *file, int line,
int64_t timestamp, void *use_data)
{
// Handle the log message
}
...
// Setup logger. It's signature is:
// void sb_add_logger_callback(sb_log_callback_t callback, void *userData);
sb_add_logger_callback(loggerCallback, NULL);
The logger callback receives the following parameters:
Parameter | Type | Description |
---|---|---|
message |
string | The log message text |
level |
enum (int) | Log severity (Debug, Info, Warning, Error) |
file |
string | Source file generating the log |
line |
integer | Line number in source file |
timestamp |
integer (int64_t) | Timestamp in milliseconds since epoch |
userData |
pointer | Optional user data for context which was set by sb_add_logger_callback() (C only) |
Reset Logging Callbacks¶
To clear the logging callbacks, you can use the reset_logger
function. This function will remove all previously set logging callbacks. Generally, you do not need to call this function.
Example Usage¶
For complete examples, refer to the Scorbit SDK examples which demonstrate a full game loop implementation in C, C++, and Python.