Skip to content

Commit

Permalink
Expose function to get the current log level
Browse files Browse the repository at this point in the history
This will allow to avoid unnecessary processing for creating logs which
will be discarded anyway.
  • Loading branch information
rom1v committed Jun 20, 2021
1 parent 5c95d18 commit 4889911
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/src/util/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,33 @@ log_level_sc_to_sdl(enum sc_log_level level) {
}
}

static enum sc_log_level
log_level_sdl_to_sc(SDL_LogPriority priority) {
switch (priority) {
case SDL_LOG_PRIORITY_VERBOSE:
return SC_LOG_LEVEL_VERBOSE;
case SDL_LOG_PRIORITY_DEBUG:
return SC_LOG_LEVEL_DEBUG;
case SDL_LOG_PRIORITY_INFO:
return SC_LOG_LEVEL_INFO;
case SDL_LOG_PRIORITY_WARN:
return SC_LOG_LEVEL_WARN;
case SDL_LOG_PRIORITY_ERROR:
return SC_LOG_LEVEL_ERROR;
default:
assert(!"unexpected log level");
return SC_LOG_LEVEL_INFO;
}
}

void
sc_set_log_level(enum sc_log_level level) {
SDL_LogPriority sdl_log = log_level_sc_to_sdl(level);
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, sdl_log);
}

enum sc_log_level
sc_get_log_level(void) {
SDL_LogPriority sdl_log = SDL_LogGetPriority(SDL_LOG_CATEGORY_APPLICATION);
return log_level_sdl_to_sc(sdl_log);
}
3 changes: 3 additions & 0 deletions app/src/util/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,7 @@
void
sc_set_log_level(enum sc_log_level level);

enum sc_log_level
sc_get_log_level(void);

#endif

0 comments on commit 4889911

Please sign in to comment.