mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-24 13:56:33 +02:00
Add AV_LOG_PRINT_LEVEL flag to include log severity in default log formatting.
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
parent
262ea965e7
commit
669a09fb37
@ -212,13 +212,38 @@ static int get_category(void *ptr){
|
||||
return avc->category + 16;
|
||||
}
|
||||
|
||||
static const char *get_level_str(int level)
|
||||
{
|
||||
switch (level) {
|
||||
case AV_LOG_QUIET:
|
||||
return "quiet";
|
||||
case AV_LOG_DEBUG:
|
||||
return "debug";
|
||||
case AV_LOG_VERBOSE:
|
||||
return "verbose";
|
||||
case AV_LOG_INFO:
|
||||
return "info";
|
||||
case AV_LOG_WARNING:
|
||||
return "warning";
|
||||
case AV_LOG_ERROR:
|
||||
return "error";
|
||||
case AV_LOG_FATAL:
|
||||
return "fatal";
|
||||
case AV_LOG_PANIC:
|
||||
return "panic";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
static void format_line(void *avcl, int level, const char *fmt, va_list vl,
|
||||
AVBPrint part[3], int *print_prefix, int type[2])
|
||||
AVBPrint part[4], int *print_prefix, int type[2])
|
||||
{
|
||||
AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
|
||||
av_bprint_init(part+0, 0, 1);
|
||||
av_bprint_init(part+1, 0, 1);
|
||||
av_bprint_init(part+2, 0, 65536);
|
||||
av_bprint_init(part+2, 0, 1);
|
||||
av_bprint_init(part+3, 0, 65536);
|
||||
|
||||
if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
|
||||
if (*print_prefix && avc) {
|
||||
@ -234,12 +259,15 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
|
||||
av_bprintf(part+1, "[%s @ %p] ",
|
||||
avc->item_name(avcl), avcl);
|
||||
if(type) type[1] = get_category(avcl);
|
||||
|
||||
if (flags & AV_LOG_PRINT_LEVEL)
|
||||
av_bprintf(part+2, "[%s] ", get_level_str(level));
|
||||
}
|
||||
|
||||
av_vbprintf(part+2, fmt, vl);
|
||||
av_vbprintf(part+3, fmt, vl);
|
||||
|
||||
if(*part[0].str || *part[1].str || *part[2].str) {
|
||||
char lastc = part[2].len && part[2].len <= part[2].size ? part[2].str[part[2].len - 1] : 0;
|
||||
if(*part[0].str || *part[1].str || *part[2].str || *part[3].str) {
|
||||
char lastc = part[3].len && part[3].len <= part[3].size ? part[3].str[part[3].len - 1] : 0;
|
||||
*print_prefix = lastc == '\n' || lastc == '\r';
|
||||
}
|
||||
}
|
||||
@ -247,10 +275,10 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl,
|
||||
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
|
||||
char *line, int line_size, int *print_prefix)
|
||||
{
|
||||
AVBPrint part[3];
|
||||
AVBPrint part[4];
|
||||
format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
|
||||
snprintf(line, line_size, "%s%s%s", part[0].str, part[1].str, part[2].str);
|
||||
av_bprint_finalize(part+2, NULL);
|
||||
snprintf(line, line_size, "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
|
||||
av_bprint_finalize(part+3, NULL);
|
||||
}
|
||||
|
||||
void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
||||
@ -258,7 +286,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
||||
static int print_prefix = 1;
|
||||
static int count;
|
||||
static char prev[LINE_SZ];
|
||||
AVBPrint part[3];
|
||||
AVBPrint part[4];
|
||||
char line[LINE_SZ];
|
||||
static int is_atty;
|
||||
int type[2];
|
||||
@ -276,7 +304,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
||||
#endif
|
||||
|
||||
format_line(ptr, level, fmt, vl, part, &print_prefix, type);
|
||||
snprintf(line, sizeof(line), "%s%s%s", part[0].str, part[1].str, part[2].str);
|
||||
snprintf(line, sizeof(line), "%s%s%s%s", part[0].str, part[1].str, part[2].str, part[3].str);
|
||||
|
||||
#if HAVE_ISATTY
|
||||
if (!is_atty)
|
||||
@ -301,6 +329,8 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
||||
colored_fputs(type[1], 0, part[1].str);
|
||||
sanitize(part[2].str);
|
||||
colored_fputs(av_clip(level >> 3, 0, 6), tint >> 8, part[2].str);
|
||||
sanitize(part[3].str);
|
||||
colored_fputs(av_clip(level >> 3, 0, 6), tint >> 8, part[3].str);
|
||||
end:
|
||||
av_bprint_finalize(part+2, NULL);
|
||||
#if HAVE_PTHREADS
|
||||
|
@ -321,6 +321,15 @@ void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
|
||||
* call av_log(NULL, AV_LOG_QUIET, "%s", ""); at the end
|
||||
*/
|
||||
#define AV_LOG_SKIP_REPEATED 1
|
||||
|
||||
/**
|
||||
* Include the log severity in messages originating from codecs.
|
||||
*
|
||||
* Results in messages such as:
|
||||
* [rawvideo @ 0xDEADBEEF] [error] encode did not produce valid pts
|
||||
*/
|
||||
#define AV_LOG_PRINT_LEVEL 2
|
||||
|
||||
void av_log_set_flags(int arg);
|
||||
int av_log_get_flags(void);
|
||||
|
||||
|
@ -56,7 +56,7 @@
|
||||
*/
|
||||
|
||||
#define LIBAVUTIL_VERSION_MAJOR 52
|
||||
#define LIBAVUTIL_VERSION_MINOR 78
|
||||
#define LIBAVUTIL_VERSION_MINOR 79
|
||||
#define LIBAVUTIL_VERSION_MICRO 100
|
||||
|
||||
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
|
||||
|
Loading…
x
Reference in New Issue
Block a user