mirror of
https://github.com/Genymobile/scrcpy
synced 2024-12-22 07:10:34 +00:00
Move log level conversion to log API
This commit is contained in:
parent
1039f9b531
commit
5c95d18beb
@ -20,6 +20,7 @@ src = [
|
||||
'src/stream.c',
|
||||
'src/tiny_xpm.c',
|
||||
'src/video_buffer.c',
|
||||
'src/util/log.c',
|
||||
'src/util/net.c',
|
||||
'src/util/process.c',
|
||||
'src/util/str_util.c',
|
||||
|
@ -38,26 +38,6 @@ print_version(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
static SDL_LogPriority
|
||||
convert_log_level_to_sdl(enum sc_log_level level) {
|
||||
switch (level) {
|
||||
case SC_LOG_LEVEL_VERBOSE:
|
||||
return SDL_LOG_PRIORITY_VERBOSE;
|
||||
case SC_LOG_LEVEL_DEBUG:
|
||||
return SDL_LOG_PRIORITY_DEBUG;
|
||||
case SC_LOG_LEVEL_INFO:
|
||||
return SDL_LOG_PRIORITY_INFO;
|
||||
case SC_LOG_LEVEL_WARN:
|
||||
return SDL_LOG_PRIORITY_WARN;
|
||||
case SC_LOG_LEVEL_ERROR:
|
||||
return SDL_LOG_PRIORITY_ERROR;
|
||||
default:
|
||||
assert(!"unexpected log level");
|
||||
return SDL_LOG_PRIORITY_INFO;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
main(int argc, char *argv[]) {
|
||||
#ifdef __WINDOWS__
|
||||
@ -81,8 +61,7 @@ main(int argc, char *argv[]) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
SDL_LogPriority sdl_log = convert_log_level_to_sdl(args.opts.log_level);
|
||||
SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, sdl_log);
|
||||
sc_set_log_level(args.opts.log_level);
|
||||
|
||||
if (args.help) {
|
||||
scrcpy_print_usage(argv[0]);
|
||||
|
28
app/src/util/log.c
Normal file
28
app/src/util/log.c
Normal file
@ -0,0 +1,28 @@
|
||||
#include "log.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
static SDL_LogPriority
|
||||
log_level_sc_to_sdl(enum sc_log_level level) {
|
||||
switch (level) {
|
||||
case SC_LOG_LEVEL_VERBOSE:
|
||||
return SDL_LOG_PRIORITY_VERBOSE;
|
||||
case SC_LOG_LEVEL_DEBUG:
|
||||
return SDL_LOG_PRIORITY_DEBUG;
|
||||
case SC_LOG_LEVEL_INFO:
|
||||
return SDL_LOG_PRIORITY_INFO;
|
||||
case SC_LOG_LEVEL_WARN:
|
||||
return SDL_LOG_PRIORITY_WARN;
|
||||
case SC_LOG_LEVEL_ERROR:
|
||||
return SDL_LOG_PRIORITY_ERROR;
|
||||
default:
|
||||
assert(!"unexpected log level");
|
||||
return SDL_LOG_PRIORITY_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);
|
||||
}
|
@ -1,8 +1,12 @@
|
||||
#ifndef LOG_H
|
||||
#define LOG_H
|
||||
#ifndef SC_LOG_H
|
||||
#define SC_LOG_H
|
||||
|
||||
#include "common.h"
|
||||
|
||||
#include <SDL2/SDL_log.h>
|
||||
|
||||
#include "scrcpy.h"
|
||||
|
||||
#define LOGV(...) SDL_LogVerbose(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
#define LOGD(...) SDL_LogDebug(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
#define LOGI(...) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
@ -10,4 +14,7 @@
|
||||
#define LOGE(...) SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
#define LOGC(...) SDL_LogCritical(SDL_LOG_CATEGORY_APPLICATION, __VA_ARGS__)
|
||||
|
||||
void
|
||||
sc_set_log_level(enum sc_log_level level);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user