So this is probably really simple but I just cannot see it.

I've made my own log class using the SDL_Log functions to output to the console. Only thing is, is that it only outputs using one category type only.

For example. I use this:

Log::getInstance()->info(Log::getInstance()->CAT_APPLICATION, "This outputs fine.");
Log::getInstance()->info(Log::getInstance()->CAT_INPUT, "This doesn't get outputted");

which, in the log class, that uses the following code:

void Log::info(int category, const char* message, ...) { SDL_LogInfo(category, message); }



I've also tried the normal method:

SDL_LogInfo(SDL_LOG_CATEGORY_INPUT, "but this doesn't get outputted either if the app cat is outputted first");

Any ideas on why it's not outputting "CAT_INPUT" but is outputting "CAT_APPLICATION"? And how I could get it outputting all of them?


According to Ginkgobitter, All SDL2 Logging Categories except for Application are at SDL_LOG_PRIORITY_CRITICAL, whereas Application is at SDL_LOG_PRIORITY_INFO. Since you are using SDL_LogInfo(), it uses the SDL_LOG_PRIORITY_INFO, thus hiding all others.

Looking at the documentation, it would appear that most of the categories are for internal SDL use, and that you really should be using SDL_LOG_CATEGORY_CUSTOM as the start of an enum, as reference above.

| improve this answer | |
  • \$\begingroup\$ Ah, I didn't realise that they were internal, I'll look into the custom category then. Thanks! \$\endgroup\$ – Jamie Edwards Apr 2 '15 at 1:31
  • \$\begingroup\$ @JamieEdwards Glad I could help! If you could accept my answer, that might help other people with the same issue. \$\endgroup\$ – thePalindrome Apr 2 '15 at 2:06
  • \$\begingroup\$ OK, I feel a little stupid, I'm using enums beyond 20 and it's still not printing out. As you can probably tell, I'm quite new to SDL. How would one get the console to output the following: INFO: CRITICAL: WARN: ... With my own custom categories? \$\endgroup\$ – Jamie Edwards Apr 2 '15 at 2:09
  • \$\begingroup\$ @JamieEdwards After doing some looking around, here's what I've got. For what you want, you don't actually need to create a category, all you have to do is call SDL_LogSetPriority(SDL_LOG_CATEGORY_CUSTOM,SDL_LOG_PRIORITY_VERBOSE); Then what you can do is just call SDL_Log{Info,Warn,Verbose,Critical,Error}(SDL_LOG_CATEGORY_CUSTOM,"message"); \$\endgroup\$ – thePalindrome Apr 2 '15 at 2:35
  • \$\begingroup\$ Ahh, I was that tired last night I didn't understand what you mean't by calling the above... Now I'm a little more awake, I completely understand and feel a little stupid. That being said, it works completely now! Thank you! \$\endgroup\$ – Jamie Edwards Apr 2 '15 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.