提交 771eac60 编写于 作者: J jp9000

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.
上级 4e10eeda
......@@ -1591,7 +1591,7 @@ void vertexbuffer_destroy(vertbuffer_t vertbuffer)
void vertexbuffer_flush(vertbuffer_t vertbuffer, bool rebuild)
{
if (!vertbuffer->dynamic) {
blog(LOG_WARNING, "vertexbuffer_flush: vertex buffer is "
blog(LOG_ERROR, "vertexbuffer_flush: vertex buffer is "
"not dynamic");
return;
}
......
......@@ -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,7 +505,7 @@ 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 "
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,7 +485,7 @@ 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 "
blog(LOG_ERROR, "audio_input_init: Failed to "
"create resampler");
return false;
}
......
......@@ -235,10 +235,10 @@ 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 "
blog(LOG_ERROR, "video_input_init: Bad "
"scale conversion type");
else
blog(LOG_WARNING, "video_input_init: Failed to "
blog(LOG_ERROR, "video_input_init: Failed to "
"create scaler");
return false;
......
......@@ -95,7 +95,7 @@ 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 "
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,7 +35,7 @@ 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 "
blog(LOG_ERROR, "Required module function '%s' in module '%s' not "
"found, loading of module failed",
name, path);
return MODULE_FUNCTION_NOT_FOUND;
......@@ -75,7 +75,7 @@ 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: "
blog(LOG_ERROR, "Module '%s' failed to load: "
"obs_module_load failed", path);
return MODULE_ERROR;
}
......@@ -136,12 +136,12 @@ 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"
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,7 +167,7 @@ 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 \
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" \
blog(LOG_ERROR, "Required value '" #val " for" \
"'%s' not found. " #func \
" failed.", \
info->id);\
" 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;
#ifdef _DEBUG
static int log_output_level = LOG_DEBUG;
#else
static int log_output_level = LOG_INFO;
#endif
static int crashing = 0;
static void def_log_handler(enum log_type type, const char *format,
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, ...);
......
......@@ -34,7 +34,7 @@
using namespace std;
static void do_log(enum log_type type, const char *msg, va_list args)
static void do_log(int log_level, const char *msg, va_list args)
{
#ifdef _WIN32
char bla[4096];
......@@ -43,14 +43,14 @@ static void do_log(enum log_type type, const char *msg, va_list args)
OutputDebugStringA(bla);
OutputDebugStringA("\n");
if (type >= LOG_WARNING && IsDebuggerPresent())
if (log_level <= LOG_WARNING && IsDebuggerPresent())
__debugbreak();
#else
vprintf(msg, args);
printf("\n");
#endif
UNUSED_PARAMETER(type);
UNUSED_PARAMETER(level);
#endif
}
bool OBSApp::InitGlobalConfigDefaults()
......@@ -164,10 +164,10 @@ bool OBSApp::InitLocale()
string path;
if (GetDataFilePath(file.str().c_str(), path)) {
if (!text_lookup_add(textLookup, path.c_str()))
blog(LOG_WARNING, "Failed to add locale file '%s'",
blog(LOG_ERROR, "Failed to add locale file '%s'",
path.c_str());
} else {
blog(LOG_WARNING, "Could not find locale file '%s'",
blog(LOG_ERROR, "Could not find locale file '%s'",
file.str().c_str());
}
......@@ -285,7 +285,9 @@ int main(int argc, char *argv[])
{
int ret = -1;
QCoreApplication::addLibraryPath(".");
#ifdef _WIN32
base_set_log_handler(do_log);
#endif
try {
OBSApp program(argc, argv);
......
......@@ -106,14 +106,14 @@ static bool new_stream(struct ffmpeg_data *data, AVStream **stream,
{
*codec = avcodec_find_encoder(id);
if (!*codec) {
blog(LOG_ERROR, "Couldn't find encoder '%s'",
blog(LOG_WARNING, "Couldn't find encoder '%s'",
avcodec_get_name(id));
return false;
}
*stream = avformat_new_stream(data->output, *codec);
if (!*stream) {
blog(LOG_ERROR, "Couldn't create stream for encoder '%s'",
blog(LOG_WARNING, "Couldn't create stream for encoder '%s'",
avcodec_get_name(id));
return false;
}
......@@ -132,14 +132,14 @@ static bool open_video_codec(struct ffmpeg_data *data)
ret = avcodec_open2(context, data->vcodec, NULL);
if (ret < 0) {
blog(LOG_ERROR, "Failed to open video codec: %s",
blog(LOG_WARNING, "Failed to open video codec: %s",
av_err2str(ret));
return false;
}
data->vframe = av_frame_alloc();
if (!data->vframe) {
blog(LOG_ERROR, "Failed to allocate video frame");
blog(LOG_WARNING, "Failed to allocate video frame");
return false;
}
......@@ -150,7 +150,7 @@ static bool open_video_codec(struct ffmpeg_data *data)
ret = avpicture_alloc(&data->dst_picture, context->pix_fmt,
context->width, context->height);
if (ret < 0) {
blog(LOG_ERROR, "Failed to allocate dst_picture: %s",
blog(LOG_WARNING, "Failed to allocate dst_picture: %s",
av_err2str(ret));
return false;
}
......@@ -167,7 +167,7 @@ static bool init_swscale(struct ffmpeg_data *data, AVCodecContext *context)
SWS_BICUBIC, NULL, NULL, NULL);
if (!data->swscale) {
blog(LOG_ERROR, "Could not initialize swscale");
blog(LOG_WARNING, "Could not initialize swscale");
return false;
}
......@@ -180,7 +180,7 @@ static bool create_video_stream(struct ffmpeg_data *data)
struct obs_video_info ovi;
if (!obs_get_video_info(&ovi)) {
blog(LOG_ERROR, "No active video");
blog(LOG_WARNING, "No active video");
return false;
}
......@@ -218,7 +218,7 @@ static bool open_audio_codec(struct ffmpeg_data *data)
data->aframe = av_frame_alloc();
if (!data->aframe) {
blog(LOG_ERROR, "Failed to allocate audio frame");
blog(LOG_WARNING, "Failed to allocate audio frame");
return false;
}
......@@ -226,7 +226,7 @@ static bool open_audio_codec(struct ffmpeg_data *data)
ret = avcodec_open2(context, data->acodec, NULL);
if (ret < 0) {
blog(LOG_ERROR, "Failed to open audio codec: %s",
blog(LOG_WARNING, "Failed to open audio codec: %s",
av_err2str(ret));
return false;
}
......@@ -236,7 +236,7 @@ static bool open_audio_codec(struct ffmpeg_data *data)
ret = av_samples_alloc(data->samples, NULL, context->channels,
data->frame_size, context->sample_fmt, 0);
if (ret < 0) {
blog(LOG_ERROR, "Failed to create audio buffer: %s",
blog(LOG_WARNING, "Failed to create audio buffer: %s",
av_err2str(ret));
return false;
}
......@@ -250,7 +250,7 @@ static bool create_audio_stream(struct ffmpeg_data *data)
struct audio_output_info aoi;
if (!obs_get_audio_info(&aoi)) {
blog(LOG_ERROR, "No active audio");
blog(LOG_WARNING, "No active audio");
return false;
}
......@@ -300,7 +300,7 @@ static inline bool open_output_file(struct ffmpeg_data *data)
ret = avio_open(&data->output->pb, data->filename_test,
AVIO_FLAG_WRITE);
if (ret < 0) {
blog(LOG_ERROR, "Couldn't open file '%s', %s",
blog(LOG_WARNING, "Couldn't open file '%s', %s",
data->filename_test, av_err2str(ret));
return false;
}
......@@ -308,7 +308,7 @@ static inline bool open_output_file(struct ffmpeg_data *data)
ret = avformat_write_header(data->output, NULL);
if (ret < 0) {
blog(LOG_ERROR, "Error opening file '%s': %s",
blog(LOG_WARNING, "Error opening file '%s': %s",
data->filename_test, av_err2str(ret));
return false;
}
......@@ -373,7 +373,7 @@ static bool ffmpeg_data_init(struct ffmpeg_data *data, const char *filename)
avformat_alloc_output_context2(&data->output, NULL, NULL,
data->filename_test);
if (!data->output) {
blog(LOG_ERROR, "Couldn't create avformat context");
blog(LOG_WARNING, "Couldn't create avformat context");
goto fail;
}
......@@ -386,7 +386,7 @@ static bool ffmpeg_data_init(struct ffmpeg_data *data, const char *filename)
return true;
fail:
blog(LOG_ERROR, "ffmpeg_data_init failed");
blog(LOG_WARNING, "ffmpeg_data_init failed");
ffmpeg_data_free(data);
return false;
}
......@@ -496,7 +496,7 @@ static void receive_video(void *param, const struct video_data *frame)
ret = avcodec_encode_video2(context, &packet, data->vframe,
&got_packet);
if (ret < 0) {
blog(LOG_ERROR, "receive_video: Error encoding "
blog(LOG_WARNING, "receive_video: Error encoding "
"video: %s", av_err2str(ret));
return;
}
......@@ -520,7 +520,7 @@ static void receive_video(void *param, const struct video_data *frame)
}
if (ret != 0) {
blog(LOG_ERROR, "receive_video: Error writing video: %s",
blog(LOG_WARNING, "receive_video: Error writing video: %s",
av_err2str(ret));
}
......@@ -543,7 +543,7 @@ static inline void encode_audio(struct ffmpeg_data *output,
context->sample_fmt, output->samples[0],
(int)total_size, 1);
if (ret < 0) {
blog(LOG_ERROR, "receive_audio: avcodec_fill_audio_frame "
blog(LOG_WARNING, "receive_audio: avcodec_fill_audio_frame "
"failed: %s", av_err2str(ret));
return;
}
......@@ -553,7 +553,7 @@ static inline void encode_audio(struct ffmpeg_data *output,
ret = avcodec_encode_audio2(context, &packet, output->aframe,
&got_packet);
if (ret < 0) {
blog(LOG_ERROR, "receive_audio: Error encoding audio: %s",
blog(LOG_WARNING, "receive_audio: Error encoding audio: %s",
av_err2str(ret));
return;
}
......@@ -570,7 +570,7 @@ static inline void encode_audio(struct ffmpeg_data *output,
pthread_mutex_lock(&output->write_mutex);
ret = av_interleaved_write_frame(output->output, &packet);
if (ret != 0)
blog(LOG_ERROR, "receive_audio: Error writing audio: %s",
blog(LOG_WARNING, "receive_audio: Error writing audio: %s",
av_err2str(ret));
pthread_mutex_unlock(&output->write_mutex);
}
......@@ -638,8 +638,8 @@ static bool ffmpeg_output_start(void *data)
audio_t audio = obs_audio();
if (!video || !audio) {
blog(LOG_ERROR, "ffmpeg_output_start: audio and video must "
"both be active (at least as of this writing)");
blog(LOG_WARNING, "ffmpeg_output_start: audio and video must "
"both be active (as of this writing)");
return false;
}
......
......@@ -51,7 +51,7 @@ static LRESULT CALLBACK sceneProc(HWND hwnd, UINT message, WPARAM wParam,
return 0;
}
static void do_log(enum log_type type, const char *msg, va_list args)
static void do_log(int log_level, const char *msg, va_list args)
{
char bla[4096];
vsnprintf(bla, 4095, msg, args);
......@@ -59,7 +59,7 @@ static void do_log(enum log_type type, const char *msg, va_list args)
OutputDebugStringA(bla);
OutputDebugStringA("\n");
if (type >= LOG_WARNING)
if (log_level <= LOG_WARNING)
__debugbreak();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册