Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Passing formatted string to a macro

hello, I want to be able to write my own logs like this :

 MY_LOG(LogDebug, Verbose, (TEXT("Item named %s has spawned"), *Name.ToString()))

and here is my macro:

 #define MY_LOG(CategoryName,Verbosity,Message, ...)    
 UE_LOG(CategoryName,Verbosity,TEXT("%s [%s]: %s"),*GET_CLASSNAME_WITH_FUNCTION,*GET_LINE_NUMBER,*FString(Message),##__VA_ARGS__)    

i added the "..." and "##VA_ARGS" because i received error that my macro has too many arguments. the text that gets logged is "Item named %s has spawned" (not formatted with the value) is there a way to pass a formatted string to the macro? i.e.

 auto formattedText= FORMAT(TEXT("Item named %s has spawned"), *Name.ToString())    
  MY_LOG(LogDebug, Verbose,formattedText)

or even make it work like in the first line of code above?

Product Version: UE 4.20
more ▼

asked Oct 30 '18 at 10:43 AM in C++ Programming

avatar image

12 1 1 5

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

Well.... i didnt find the solution i was hoping for, but for anyone trying to figure out how to save formatted string into variables, i ended up using this:

 MY_LOG(LogDebug, Verbose,FString::Printf( TEXT("Actor named %s has spawned"), *Name.ToString()))

more ▼

answered Nov 01 '18 at 05:39 PM

avatar image

12 1 1 5

(comments are locked)
10|2000 characters needed characters left

You can actually see exactly what unreal's log macro is doing in LogMacros.h. You could take that code and do some string manipulation of Format inside your macro to preprend the extra info you want before moving ahead with the rest of the normal logging functionality.

more ▼

answered Oct 30 '18 at 07:11 PM

Brian Johnstone (suspended)
avatar image Kidakaka Oct 30 '18 at 08:13 PM

Thank you for replying, yeah i already tried to dive into the UE_LOG macro but i saw it calls for other methods which were way too complex for me to understand

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question