Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ALTV-330 Add runtime prefix for logs #156

Merged
merged 5 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions client/thirdparty/Log.h → c-api/Log.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <sstream>
#include "cpp-sdk/ICore.h"
#include "../cpp-sdk/ICore.h"

namespace cs {
class Log
Expand All @@ -23,6 +23,8 @@ class Log
Log() = default;

public:
static constexpr const char* LOG_PREFIX = "[C#]";

Log(const Log&) = delete;
Log(Log&&) = delete;
Log& operator=(const Log&) = delete;
Expand Down Expand Up @@ -104,11 +106,11 @@ class Log
{
switch(log.type)
{
case INFO: alt::ICore::Instance().LogInfo(log.buf.str()); break;
case DEBUG: alt::ICore::Instance().LogDebug(log.buf.str().c_str()); break;
case WARNING: alt::ICore::Instance().LogWarning(log.buf.str().c_str()); break;
case ERR: alt::ICore::Instance().LogError(log.buf.str().c_str()); break;
case COLORED: alt::ICore::Instance().LogColored(log.buf.str().c_str()); break;
case INFO: alt::ICore::Instance().LogInfo(LOG_PREFIX, log.buf.str()); break;
case DEBUG: alt::ICore::Instance().LogDebug(LOG_PREFIX, log.buf.str().c_str()); break;
case WARNING: alt::ICore::Instance().LogWarning(LOG_PREFIX, log.buf.str().c_str()); break;
case ERR: alt::ICore::Instance().LogError(LOG_PREFIX, log.buf.str().c_str()); break;
case COLORED: alt::ICore::Instance().LogColored(LOG_PREFIX, log.buf.str().c_str()); break;
}

log.buf.str("");
Expand Down
12 changes: 6 additions & 6 deletions c-api/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@
CAPI_START()

void Core_LogInfo(alt::ICore* core, const char* str) {
core->LogInfo(str);
core->LogInfo(cs::Log::LOG_PREFIX, str);
}

void Core_LogDebug(alt::ICore* core, const char* str) {
core->LogDebug(str);
core->LogDebug(cs::Log::LOG_PREFIX, str);
}

void Core_LogWarning(alt::ICore* core, const char* str) {
core->LogWarning(str);
core->LogWarning(cs::Log::LOG_PREFIX, str);
}

void Core_LogError(alt::ICore* core, const char* str) {
core->LogError(str);
core->LogError(cs::Log::LOG_PREFIX, str);
}

void Core_LogColored(alt::ICore* core, const char* str) {
core->LogColored(str);
core->LogColored(cs::Log::LOG_PREFIX, str);
}

alt::MValueConst* Core_CreateMValueNil(alt::ICore* core) {
Expand Down Expand Up @@ -1218,7 +1218,7 @@ void Core_TriggerServerEventUnreliable(alt::ICore* core, const char* event, alt:
void Core_ShowCursor(alt::ICore* core, alt::IResource* resource, uint8_t state) {
if(!resource->ToggleCursor(state))
{
core->LogWarning("Cursor state can't go < 0");
core->LogWarning(cs::Log::LOG_PREFIX, "Cursor state can't go < 0");
}
}

Expand Down
1 change: 1 addition & 0 deletions c-api/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "data/ped_model_info.h"
#include "data/weapon_model_info.h"
#include "utils/export.h"
#include "Log.h"

#ifdef ALT_SERVER_API
#include <CSharpResourceImpl.h>
Expand Down
2 changes: 1 addition & 1 deletion client/src/coreclr/CoreClr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
#include <sstream>
#include <filesystem>
#include <fstream>
#include <Log.h>
#include <zip_file.hpp>

#include "utils.h"
#include "../../c-api/client.h"
#include "../../c-api/func_table.h"
#include "../../c-api/Log.h"

using namespace alt;
using namespace std;
Expand Down
12 changes: 6 additions & 6 deletions client/src/coreclr/CoreClr.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "cpp-sdk/ICore.h"
#include <coreclr.h>
#include <filesystem>
#include <Log.h>
#include <../../c-api/Log.h>
#include <optional>

#include "nuget/NuGet.h"
Expand All @@ -20,12 +20,12 @@ struct Progress
float total;
float current;
progressfn_t& updateFn;

void Update() const
{
updateFn(state, current, total, 1000);
}

void Advance(float value)
{
current += value;
Expand Down Expand Up @@ -63,7 +63,7 @@ class CoreClr {
coreclr_shutdown_2_ptr _shutdownCoreClr = nullptr;
coreclr_create_delegate_ptr _createDelegate = nullptr;
coreclr_execute_assembly_ptr _executeAssembly = nullptr;

void* _runtimeHost = nullptr;
unsigned int _domainId = 0;
std::optional<NuGet> _nuget;
Expand All @@ -78,9 +78,9 @@ class CoreClr {
void DownloadHost(alt::IHttpClient* httpClient, Progress& progress) const;
void DownloadNuGet(alt::IHttpClient* httpClient, nlohmann::json json, Progress& progress);
void DownloadNuGets(alt::IHttpClient* httpClient, progressfn_t& progress);

void InitializeCoreclr();
void Update(progressfn_t progressFn, int attempt);

std::string GetBaseCdnUrl() const;
};
2 changes: 1 addition & 1 deletion client/src/coreclr/CoreClrValidation.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <json.hpp>
#include <Log.h>
#include <../../c-api/Log.h>
#include <sha1.hpp>
#include <sha512.hpp>
#include <iomanip>
Expand Down
2 changes: 1 addition & 1 deletion client/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#ifdef ALTV_CSHARP_SHARED
#include "cpp-sdk/version/version.h"
#endif
#include <Log.h>
#include <../../c-api/Log.h>

using namespace alt;

Expand Down
2 changes: 1 addition & 1 deletion client/src/nuget/NuGet.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "NuGet.h"

#include <Log.h>
#include <../../c-api/Log.h>

#include "utils.h"

Expand Down
2 changes: 1 addition & 1 deletion client/src/runtime/CSharpResourceImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <vector>
#include "CSharpScriptRuntime.h"
#include "CSharpResourceImpl.h"
#include <Log.h>
#include <../../c-api/Log.h>
#include "CRC.h"
#include <sstream>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion client/src/runtime/CSharpScriptRuntime.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include <Log.h>
#include <../../c-api/Log.h>
#include "CSharpScriptRuntime.h"
#include "CSharpResourceImpl.h"
#include "natives.h"
Expand Down
2 changes: 1 addition & 1 deletion client/src/runtime/natives.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "../../c-api/data/types.h"
#include "../../c-api/data/function_table.h"
#include "../../c-api/client.h"
#include "Log.h"
#include "../../c-api/Log.h"
#include <cstring>
#include <type_traits>
#include <stdlib.h>
Expand Down
16 changes: 8 additions & 8 deletions client/src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <string>
#include <codecvt>
#include <future>
#include <Log.h>
#include <../../c-api/Log.h>

EXTERN_C IMAGE_DOS_HEADER __ImageBase;

Expand Down Expand Up @@ -59,7 +59,7 @@ namespace utils
std::char_traits<T>::copy(returnStr, str, ulSize);
return returnStr;
}

template <typename T, typename... Args>
T *get_clr_value(Args &&...args)
{
Expand Down Expand Up @@ -99,27 +99,27 @@ namespace utils
std::transform(str.begin(), str.end(), str.begin(), [](const unsigned char c){ return std::tolower(c); });
return str;
}

inline alt::IHttpClient::HttpResponse download_file_sync(alt::IHttpClient* httpClient, const std::string& url) {
auto attempt = 0;

while (true)
{
if (++attempt > 5) throw std::runtime_error("Failed to download file " + url);

std::promise<alt::IHttpClient::HttpResponse> promise;
std::future<alt::IHttpClient::HttpResponse> future = promise.get_future();

httpClient->Get([](alt::IHttpClient::HttpResponse response, const void* data) {
const auto innerPromise = (std::promise<alt::IHttpClient::HttpResponse>*) data;

if (response.statusCode != 200) {
std::stringstream ss;
ss << "HTTP " << response.statusCode << " " << response.body;
innerPromise->set_exception(std::make_exception_ptr(std::runtime_error(ss.str())));
return;
}

innerPromise->set_value(response);
}, url, &promise);

Expand Down
2 changes: 1 addition & 1 deletion cpp-sdk
Submodule cpp-sdk updated 2 files
+5 −5 ICore.h
+6 −1 objects/IEntity.h
Loading
Loading