x

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"

How to pass variable LogCategory to UE_LOG?

Hi There,

I'm trying to write some helper functions which require passing around FLogCategory variables which in turn should be used somehow in the call to UE_LOG. I'm banging my head against this and can't figure it out. Any ideas on how to achieve this?

 void UPWNLogger::LogCat(const FLogCategoryBase& Kategory)
 {
     // Get log category name
     FName logCatName = Kategory.GetCategoryName();
 
 
     UE_LOG(LogTemp, Warning, TEXT("%s"), *(n.ToString()));    // Prints the expected log category as a string value using LogTemp category
     UE_LOG(logCatName.ToString(), Warning, TEXT("%s"), *(n.ToString()));    // Results in error 'FLogCategorylogCatName': undeclared identifier
 }
Product Version: UE 4.19
Tags:
more ▼

asked Apr 20 '18 at 02:21 AM in C++ Programming

avatar image

staticvoidlol
2.5k 93 40 111

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

1 answer: sort voted first

You need to declare log category first, you can read about it here:

https://wiki.unrealengine.com/Logs,_Printing_Messages_To_Yourself_During_Runtime

If you want to do easy quick debug you can also use GLog->Log(FString) which is easiest way to log but bypass advance log features.

more ▼

answered Apr 20 '18 at 07:22 AM

avatar image

Shadowriver
33.9k 916 164 1093

avatar image staticvoidlol Apr 20 '18 at 05:11 PM

Thanks Shadowriver. The issue is not how to declare a custom log category, I have already done that and it's working fine. My issue is that I want to write some helper methods (not macros) that in turn calls the UE_LOG macro with specifically prepared data. In order to do this I need to pass my log category to a function (as in my first post) which seems to be working, however the issue is I can't figure out how to use that variable when calling UE_LOG.

Essentially it seems that when passing my variable "logCatName" to UE_LOG it is not evaluated, and instead the macro takes the variable name ("logCatName") and prepends "FLogCategory" to result in the string "FLogCategorylogCatName" which cannot be resolved (as it doesn't exist).

I have very little experience with C++ macros so I'm probably trying something stupid here, but any suggestions will be appreciated.

avatar image Shadowriver Apr 20 '18 at 09:23 PM

Ah ok :> Then it can't be helped as those macros are made that way, you might try to look up on how UE_LOG is made and try to reproduce it, code from macro is pasted at point there are used so if you can declare your own fixed macro it should work the same way

https://github.com/EpicGames/UnrealEngine/blob/8e4560b8c22b309e73ff0ce90377742c3dfe13cc/Engine/Source/Runtime/Core/Public/Logging/LogMacros.h

just remember to make NO_LOGGING conditioning same as code above do, if you don't do that log will embeded in to binary even if logging system is no build which might lead in to some complications. UE4 use macros for that execly because of that to control whatever log messages and or not will be build in to binary.

You might try to experiment with GLog more, there bits of category system there too:

http://api.unrealengine.com/INT/API/Runtime/Core/Misc/FOutputDevice/index.html

(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