Wiki Code Tutorials

Class and Line Number for your Screen and Log Messages!

Dear Community,

I am giving you easy-to-use pre-processor commands to get a UE4 String that tells you the Class Name, Function Name, and Line Number of the calling code!

Logs, Printing the Class Name, Function Name, and Line Number of your Calling Code!
https://wiki.unrealengine./Logs,_Printing_the_Class_Name,_Function_Name,_Line_Number_of_your_Calling_Code!#My_C.2B.2B_Code_For_You


**Pics**

![a51b4eb12a773cd47ef504c3015401ed5a1222f7.jpeg|1280x960](upload://nyBhSL7AeJYRaiuAA8hU6eu26hN.jpeg)

After you get my .h file below, the code for the above picture is !



```


//~~~ Tick ~~~
void AEVCoreDefense::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	//~~~~~~~~~~~~~

	VSCREENMSG("Got Here!");  //Class and line number get printed for you! ♥ 
}


```



UE_LOG Versions

I’ve also added several macros to support adding class and line number information to UE_LOG messages!



//will print the class and line number along with the character name!
V_LOG2(YourLogCat, "Hit Character Name is",Hit.GetActor()->GetName());



**Code**

**Here is the entire file you can #include in your code base!**

I made a file called JoyCurrentClassFuncLine.h

So you would then do somewhere at the top of one of your core classes:



```


// Joy Class Func Line
**#include "JoyCurrentClassFuncLine.h"**


```





```


/*
	Joy String 
		Current Class, File, and Line Number!
			by
 
	PreProcessor commands to get 
		a. Class name
		b. Function Name
		c. Line number 
		d. Function Signature (including parameters)
 
	Gives you a UE4 FString anywhere in your code that these macros are used!
 
	Ex: 
		You can use JOYSTR_CUR_CLASS anywhere to get a UE4 FString back telling you 
		what the current class is where you called macro!
 
	Ex:
		macro prints the class and line along with the message of your choosing!
		VSCREENMSG("Have fun today!");
	<3 
*/
#pragma once
 
//Current Class Name + Function Name where is called!
#define JOYSTR_CUR_CLASS_FUNC (FString(__FUNCTION__))
 
//Current Class where is called!
#define JOYSTR_CUR_CLASS (FString(__FUNCTION__).Left(FString(__FUNCTION__).Find(TEXT(":"))) )
 
//Current Function Name where is called!
#define JOYSTR_CUR_FUNC (FString(__FUNCTION__).Right(FString(__FUNCTION__).Len() - FString(__FUNCTION__).Find(TEXT("::")) - 2 ))
 
//Current Line Number in the code where is called!
#define JOYSTR_CUR_LINE  (FString::FromInt(__LINE__))
 
//Current Class and Line Number where is called!
#define JOYSTR_CUR_CLASS_LINE (JOYSTR_CUR_CLASS + "(" + JOYSTR_CUR_LINE + ")")
 
//Current Function Signature where is called!
#define JOYSTR_CUR_FUNCSIG (FString(__FUNCSIG__))
 
 
//Victory Screen Message
// 	Gives you the Class name and exact line number where you print a message to yourself!
#define VSCREENMSG(Param1) (GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *(JOYSTR_CUR_CLASS_LINE + ": " + Param1)) )
 
#define VSCREENMSG2(Param1,Param2) (GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *(JOYSTR_CUR_CLASS_LINE + ": " + Param1 + " " + Param2)) )
 
#define VSCREENMSGF(Param1,Param2) (GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *(JOYSTR_CUR_CLASS_LINE + ": " + Param1 + " " + FString::SanitizeFloat(Param2))) )
 
//UE LOG!
#define V_LOG(LogCat, Param1) 		UE_LOG(LogCat,Warning,TEXT("%s: %s"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1))
 
#define V_LOG2(LogCat, Param1,Param2) 	UE_LOG(LogCat,Warning,TEXT("%s: %s %s"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1),*FString(Param2))
 
#define V_LOGF(LogCat, Param1,Param2) 	UE_LOG(LogCat,Warning,TEXT("%s: %s %f"), *JOYSTR_CUR_CLASS_LINE, *FString(Param1),Param2)
 
#define V_LOGM(LogCat, FormatString , ...) UE_LOG(LogCat,Warning,TEXT("%s: %s"), 	*JOYSTR_CUR_CLASS_LINE, *FString::Printf(TEXT(FormatString), ##__VA_ARGS__ ) )


```



Enjoy!

:)