# Print in UE\_LOG variable name with value

**URL:** <https://forums.unrealengine.com/t/print-in-ue-log-variable-name-with-value/1637052>\
**Category:** Programming & Scripting\
**Tags:** logging, Debugging, unreal-engine, CPP\
**Created:** [January 23, 2024, 5:08pm UTC](https://forums.unrealengine.com/t/print-in-ue-log-variable-name-with-value/1637052 "2024-01-23T17:08:34Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ppasterz](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Ppasterz](https://forums.unrealengine.com/u/Ppasterz)\
**Post date:** [January 23, 2024, 5:08pm UTC](https://forums.unrealengine.com/t/print-in-ue-log-variable-name-with-value/1637052/1 "2024-01-23T17:08:34Z")

</div>

## 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).
