All of my custom Debug logs are not allowing me to compile my code

I add

.h

Declare_Log_Category_Extern(MyLog, Log, All);

.cpp

Define_Log_Category(MyLog);

Once i compile I get these errors:

error C2146: syntax error: missing ‘;’ before identifier ‘MyLog’

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2780: ‘void FMsg::Logf_Internal(const ANSICHAR *,int32,const FName &,ELogVerbosity::Type,const FmtType &,Types…)’: expects 6 arguments - 4 provided

error C2065: ‘CompileTimeVerbosity’: undeclared identifier

error C2653: ‘FLogCategoryMyLog’: is not a class or namespace name

error C2065: ‘MyLog’: undeclared identifier

error C2672: ‘FMsg::Logf_Internal’: no matching overloaded function found

error C2146: syntax error: missing ‘;’ before identifier ‘MyLog’

I already checked the wiki for Logs and print messages, that didnt help.
Where is the proper location to declare and define a custom debug log within a script?
Is it within the class? Outside of the class? on top, underneath the includes?

Hello,

I’m pretty sure there is log category in a cpp.

DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity);

So you should invert your declaration. From CPP to H and from H to CPP.

@Przemek2222
I tried that instead of 15 errors i get 2 sets of the same error

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

error C2146: syntax error: missing ‘;’ before identifier ‘MyLog’

In C++, capitalisation matters. Your post suggests you’ve used

Declare_Log_Category_Extern(MyLog, Log, All);

Instead of

DECLARE_LOG_CATEGORY_EXTERN(MyLog, Log, All);

And

Define_Log_Category(MyLog);

Instead of

DEFINE_LOG_CATEGORY(MyLog);

Update to use capitals and see if that fixes the issue.

Also, My DEFINE_LOG_CATEGORY are in .cpp and DECLATE_LOG_CATEGORY_EXTERN is in .h

Macros are written all with big letters so make sure you have
DECLARE_LOG_CATEGORY_EXTERN not Declare_Log_Category_Extern …

I understand, However, i still received the same errors, all caps or not :frowning:

This is what works for me. Hopefully it will help you as well.

In your project header file (MyProject.h), add the following:

DECLARE_LOG_CATEGORY_EXTERN(LogMyGame, Warning, All);

In your project cpp file (MyProject.cpp), add the following:

DEFINE_LOG_CATEGORY(LogMyGame);

Hope this helps.

I was having the same issue in regard to the above and the compiler didn’t like the code until the custom logs were being implemented somewhere. Intellisense doesn’t like it and it throws a red.

In the game.h:

DECLARE_LOG_CATEGORY_EXTERN(YourLog, Verbose, All);

In the game.cpp:

DEFINE_LOG_CATEGORY(YourLog);

Implementation in my character.cpp. Include the game.h:

UE_LOG(YourLog, Warning, TEXT("YourLog Warning"));

It runs and allows all variations of the custom debug message e.g. Verbose, Very Verbose etc.

Hope this helps.

1 Like