Be more consistent about log levels
LOG_ERROR should be used in places where though recoverable (or at least something that can be handled safely), was unexpected, and may affect the user/application. LOG_WARNING should be used in places where it's not entirely unexpected, is recoverable, and doesn't really affect the user/application.
This commit is contained in:
@@ -226,7 +226,7 @@ void gs_matrix_pop(void)
|
||||
return;
|
||||
|
||||
if (graphics->cur_matrix == 0) {
|
||||
blog(LOG_ERROR, "Tried to pop last matrix on stack");
|
||||
blog(LOG_WARNING, "Tried to pop last matrix on stack");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -505,9 +505,9 @@ static inline bool validvertsize(graphics_t graphics, size_t num,
|
||||
return false;
|
||||
|
||||
if (graphics->using_immediate && num == IMMEDIATE_COUNT) {
|
||||
blog(LOG_WARNING, "%s: tried to use over %u "
|
||||
"for immediate rendering",
|
||||
name, IMMEDIATE_COUNT);
|
||||
blog(LOG_ERROR, "%s: tried to use over %u "
|
||||
"for immediate rendering",
|
||||
name, IMMEDIATE_COUNT);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ effect_t gs_create_effect_from_file(const char *file, char **error_string)
|
||||
|
||||
file_string = os_quick_read_utf8_file(file);
|
||||
if (!file_string) {
|
||||
blog(LOG_WARNING, "Could not load effect file '%s'", file);
|
||||
blog(LOG_ERROR, "Could not load effect file '%s'", file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -642,7 +642,7 @@ shader_t gs_create_vertexshader_from_file(const char *file, char **error_string)
|
||||
|
||||
file_string = os_quick_read_utf8_file(file);
|
||||
if (!file_string) {
|
||||
blog(LOG_WARNING, "Could not load vertex shader file '%s'",
|
||||
blog(LOG_ERROR, "Could not load vertex shader file '%s'",
|
||||
file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -663,7 +663,7 @@ shader_t gs_create_pixelshader_from_file(const char *file, char **error_string)
|
||||
|
||||
file_string = os_quick_read_utf8_file(file);
|
||||
if (!file_string) {
|
||||
blog(LOG_WARNING, "Could not load pixel shader file '%s'",
|
||||
blog(LOG_ERROR, "Could not load pixel shader file '%s'",
|
||||
file);
|
||||
return NULL;
|
||||
}
|
||||
@@ -775,7 +775,7 @@ void gs_draw_sprite(texture_t tex, uint32_t flip, uint32_t width,
|
||||
return;
|
||||
|
||||
if (gs_gettexturetype(tex) != GS_TEXTURE_2D) {
|
||||
blog(LOG_ERROR, "A sprite must be a 2D texture");
|
||||
blog(LOG_WARNING, "A sprite must be a 2D texture");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@@ -485,8 +485,8 @@ static inline bool audio_input_init(struct audio_input *input,
|
||||
|
||||
input->resampler = audio_resampler_create(&to, &from);
|
||||
if (!input->resampler) {
|
||||
blog(LOG_WARNING, "audio_input_init: Failed to "
|
||||
"create resampler");
|
||||
blog(LOG_ERROR, "audio_input_init: Failed to "
|
||||
"create resampler");
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
|
@@ -235,11 +235,11 @@ static inline bool video_input_init(struct video_input *input,
|
||||
VIDEO_SCALE_FAST_BILINEAR);
|
||||
if (ret != VIDEO_SCALER_SUCCESS) {
|
||||
if (ret == VIDEO_SCALER_BAD_CONVERSION)
|
||||
blog(LOG_WARNING, "video_input_init: Bad "
|
||||
"scale conversion type");
|
||||
blog(LOG_ERROR, "video_input_init: Bad "
|
||||
"scale conversion type");
|
||||
else
|
||||
blog(LOG_WARNING, "video_input_init: Failed to "
|
||||
"create scaler");
|
||||
blog(LOG_ERROR, "video_input_init: Failed to "
|
||||
"create scaler");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@@ -95,8 +95,8 @@ int video_scaler_create(video_scaler_t *scaler_out,
|
||||
dst->width, dst->height, format_dst,
|
||||
scale_type, NULL, NULL, NULL);
|
||||
if (!scaler->swscale) {
|
||||
blog(LOG_WARNING, "video_scaler_create: Could not create "
|
||||
"swscale");
|
||||
blog(LOG_ERROR, "video_scaler_create: Could not create "
|
||||
"swscale");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ bool video_scaler_scale(video_scaler_t scaler,
|
||||
0, scaler->src_height,
|
||||
output, (const int *)out_linesize);
|
||||
if (ret <= 0) {
|
||||
blog(LOG_DEBUG, "video_scaler_scale: sws_scale failed: %d",
|
||||
blog(LOG_ERROR, "video_scaler_scale: sws_scale failed: %d",
|
||||
ret);
|
||||
return false;
|
||||
}
|
||||
|
@@ -35,9 +35,9 @@ static size_t cur_modeless_ui_size = 0;
|
||||
|
||||
static inline int req_func_not_found(const char *name, const char *path)
|
||||
{
|
||||
blog(LOG_WARNING, "Required module function '%s' in module '%s' not "
|
||||
"found, loading of module failed",
|
||||
name, path);
|
||||
blog(LOG_ERROR, "Required module function '%s' in module '%s' not "
|
||||
"found, loading of module failed",
|
||||
name, path);
|
||||
return MODULE_FUNCTION_NOT_FOUND;
|
||||
}
|
||||
|
||||
@@ -75,8 +75,8 @@ static int call_module_load(void *module, const char *path)
|
||||
cur_modeless_ui_size = obs_module_modeless_ui_size();
|
||||
|
||||
if (!obs_module_load(LIBOBS_API_VER)) {
|
||||
blog(LOG_WARNING, "Module '%s' failed to load: "
|
||||
"obs_module_load failed", path);
|
||||
blog(LOG_ERROR, "Module '%s' failed to load: "
|
||||
"obs_module_load failed", path);
|
||||
return MODULE_ERROR;
|
||||
}
|
||||
|
||||
@@ -136,13 +136,13 @@ void obs_register_source(const struct obs_source_info *info)
|
||||
struct darray *array;
|
||||
|
||||
if (!info) {
|
||||
blog(LOG_WARNING, "obs_register_source: NULL info");
|
||||
blog(LOG_ERROR, "obs_register_source: NULL info");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!cur_source_info_size) {
|
||||
blog(LOG_WARNING, "Tried to register obs_source_info"
|
||||
" outside of obs_module_load");
|
||||
blog(LOG_ERROR, "Tried to register obs_source_info"
|
||||
" outside of obs_module_load");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -155,7 +155,7 @@ void obs_register_source(const struct obs_source_info *info)
|
||||
} else if (info->type == OBS_SOURCE_TYPE_TRANSITION) {
|
||||
array = &obs->transition_types.da;
|
||||
} else {
|
||||
blog(LOG_WARNING, "Tried to register unknown source type: %u",
|
||||
blog(LOG_ERROR, "Tried to register unknown source type: %u",
|
||||
info->type);
|
||||
return;
|
||||
}
|
||||
@@ -167,8 +167,8 @@ void obs_register_source(const struct obs_source_info *info)
|
||||
do { \
|
||||
struct structure data = {0}; \
|
||||
if (!size_var) { \
|
||||
blog(LOG_WARNING, "Tried to register " #structure \
|
||||
" outside of obs_module_load"); \
|
||||
blog(LOG_ERROR, "Tried to register " #structure \
|
||||
" outside of obs_module_load"); \
|
||||
return; \
|
||||
} \
|
||||
\
|
||||
@@ -179,10 +179,9 @@ void obs_register_source(const struct obs_source_info *info)
|
||||
#define CHECK_REQUIRED_VAL(info, val, func) \
|
||||
do { \
|
||||
if (!info->val) {\
|
||||
blog(LOG_WARNING, "Required value '" #val " for" \
|
||||
"'%s' not found. " #func \
|
||||
" failed.", \
|
||||
info->id);\
|
||||
blog(LOG_ERROR, "Required value '" #val " for" \
|
||||
"'%s' not found. " #func \
|
||||
" failed.", info->id); \
|
||||
return; \
|
||||
} \
|
||||
} while (false)
|
||||
|
@@ -35,7 +35,7 @@ obs_output_t obs_output_create(const char *id, const char *name,
|
||||
struct obs_output *output;
|
||||
|
||||
if (!info) {
|
||||
blog(LOG_WARNING, "Output '%s' not found", id);
|
||||
blog(LOG_ERROR, "Output '%s' not found", id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -310,7 +310,7 @@ obs_sceneitem_t obs_scene_add(obs_scene_t scene, obs_source_t source)
|
||||
return NULL;
|
||||
|
||||
if (!source) {
|
||||
blog(LOG_WARNING, "Tried to add a NULL source to a scene");
|
||||
blog(LOG_ERROR, "Tried to add a NULL source to a scene");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -64,7 +64,7 @@ static const struct obs_source_info *get_source_info(enum obs_source_type type,
|
||||
|
||||
case OBS_SOURCE_TYPE_SCENE:
|
||||
default:
|
||||
blog(LOG_WARNING, "get_source_info: invalid source type");
|
||||
blog(LOG_ERROR, "get_source_info: invalid source type");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ obs_source_t obs_source_create(enum obs_source_type type, const char *id,
|
||||
|
||||
const struct obs_source_info *info = get_source_info(type, id);
|
||||
if (!info) {
|
||||
blog(LOG_WARNING, "Source '%s' not found", id);
|
||||
blog(LOG_ERROR, "Source '%s' not found", id);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@@ -354,7 +354,7 @@ static bool convert_frame(struct obs_core_video *video,
|
||||
new_frame->data, new_frame->linesize);
|
||||
|
||||
} else {
|
||||
blog(LOG_WARNING, "convert_frame: unsupported texture format");
|
||||
blog(LOG_ERROR, "convert_frame: unsupported texture format");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@@ -21,17 +21,22 @@
|
||||
#include "c99defs.h"
|
||||
#include "base.h"
|
||||
|
||||
static enum log_type log_output_level = LOG_WARNING;
|
||||
static int crashing = 0;
|
||||
#ifdef _DEBUG
|
||||
static int log_output_level = LOG_DEBUG;
|
||||
#else
|
||||
static int log_output_level = LOG_INFO;
|
||||
#endif
|
||||
|
||||
static void def_log_handler(enum log_type type, const char *format,
|
||||
static int crashing = 0;
|
||||
|
||||
static void def_log_handler(int log_level, const char *format,
|
||||
va_list args)
|
||||
{
|
||||
char out[4096];
|
||||
vsnprintf(out, sizeof(out), format, args);
|
||||
|
||||
if (type >= log_output_level) {
|
||||
switch (type) {
|
||||
if (log_level >= log_output_level) {
|
||||
switch (log_level) {
|
||||
case LOG_DEBUG:
|
||||
printf("debug: %s\n", out);
|
||||
break;
|
||||
@@ -41,7 +46,7 @@ static void def_log_handler(enum log_type type, const char *format,
|
||||
break;
|
||||
|
||||
case LOG_WARNING:
|
||||
fprintf(stderr, "warning: %s\n", out);
|
||||
printf("warning: %s\n", out);
|
||||
break;
|
||||
|
||||
case LOG_ERROR:
|
||||
@@ -62,12 +67,12 @@ NORETURN static void def_crash_handler(const char *format, va_list args)
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void (*log_handler)(enum log_type, const char *, va_list) =
|
||||
static void (*log_handler)(int log_level, const char *, va_list) =
|
||||
def_log_handler;
|
||||
static void (*crash_handler)(const char *, va_list) = def_crash_handler;
|
||||
|
||||
void base_set_log_handler(
|
||||
void (*handler)(enum log_type, const char *, va_list))
|
||||
void (*handler)(int log_level, const char *, va_list))
|
||||
{
|
||||
log_handler = handler;
|
||||
}
|
||||
@@ -92,16 +97,16 @@ void bcrash(const char *format, ...)
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void blogva(enum log_type type, const char *format, va_list args)
|
||||
void blogva(int log_level, const char *format, va_list args)
|
||||
{
|
||||
log_handler(type, format, args);
|
||||
log_handler(log_level, format, args);
|
||||
}
|
||||
|
||||
void blog(enum log_type type, const char *format, ...)
|
||||
void blog(int log_level, const char *format, ...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
va_start(args, format);
|
||||
log_handler(type, format, args);
|
||||
log_handler(log_level, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
@@ -28,18 +28,41 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum log_type {
|
||||
LOG_DEBUG,
|
||||
LOG_INFO,
|
||||
LOG_WARNING,
|
||||
LOG_ERROR
|
||||
enum {
|
||||
/**
|
||||
* Use if there's a problem that can potentially affect the program,
|
||||
* but isn't enough to require termination of the program.
|
||||
*
|
||||
* Use in creation functions and core subsystem functions. Places that
|
||||
* should definitely not fail.
|
||||
*/
|
||||
LOG_ERROR = 100,
|
||||
|
||||
/**
|
||||
* Use if a problem occurs that doesn't affect the program and is
|
||||
* recoverable.
|
||||
*
|
||||
* Use in places where where failure isn't entirely unexpected, and can
|
||||
* be handled safely.
|
||||
*/
|
||||
LOG_WARNING = 200,
|
||||
|
||||
/**
|
||||
* Informative essage to be displayed in the log.
|
||||
*/
|
||||
LOG_INFO = 300,
|
||||
|
||||
/**
|
||||
* Debug message to be used mostly by developers.
|
||||
*/
|
||||
LOG_DEBUG = 400
|
||||
};
|
||||
|
||||
EXPORT void base_set_log_handler(
|
||||
void (*handler)(enum log_type, const char *, va_list));
|
||||
void (*handler)(int log_level, const char *, va_list));
|
||||
EXPORT void base_set_crash_handler(void (*handler)(const char *, va_list));
|
||||
|
||||
EXPORT void blogva(enum log_type type, const char *format, va_list args);
|
||||
EXPORT void blogva(int log_level, const char *format, va_list args);
|
||||
|
||||
#ifndef _MSC_VER
|
||||
#define PRINTFATTR(f, a) __attribute__((__format__(__printf__, f, a)))
|
||||
@@ -48,7 +71,7 @@ EXPORT void blogva(enum log_type type, const char *format, va_list args);
|
||||
#endif
|
||||
|
||||
PRINTFATTR(2, 3)
|
||||
EXPORT void blog(enum log_type type, const char *format, ...);
|
||||
EXPORT void blog(int log_level, const char *format, ...);
|
||||
PRINTFATTR(1, 2)
|
||||
EXPORT void bcrash(const char *format, ...);
|
||||
|
||||
|
Reference in New Issue
Block a user