Hi, I write a class to do the thing I write in the tittle of this topic. If someone have some questions or think that something should be corrected please write it.
namespace MyLogger{
#define DEBVAR(Value) *FString::Printf(TEXT(“\t%s: “),TEXT(value)) << Value<<”\t”
class MyDebugLogs;
typedef MyDebugLogs Looger;
class WAROFWAVES2_API MyDebugLogs{
public:
~MyDebugLogs(){
UE_LOG(LogTemp, Warning, TEXT("%s"), *FString(LogString));
}
MyDebugLogs& operator<<(const FString& Value){
LogString += Value;
return *this;
}
MyDebugLogs& operator<<(const int& Value){
LogString += FString::FromInt(Value);
return *this;
}
MyDebugLogs& operator<<(const float& Value){
LogString += FString::SanitizeFloat(Value);
return *this;
}
MyDebugLogs& operator<<(const FVector& Value){
LogString += "X: " + FString::SanitizeFloat(Value.X) + " ";
LogString += "Y: " + FString::SanitizeFloat(Value.Y) + " ";
LogString += "Z: " + FString::SanitizeFloat(Value.Z) + " ";
return *this;
}
MyDebugLogs& operator<<(const char* Value){
if(Value == nullptr){
return *this;
}
LogString += Value;
return *this;
}
private:
FString LogString;
};
};
And there you have example of using it:
int z = 5;
FVector vec{15.4,13.1,99.0};
FQuat quat;
Looger() << test << DEBVAR(z) << DEBVAR(vec)<<Kolejny testttttt;// << q;
As you can see class is used like streams from c++ libraries( cout, cin etc.). If you want to make additional types you must write method “MyDebugLogs& operator<<(const T* Value)” with T as your own type if you make it, please write that code here so that more people could use it).