Skip to content

Commit

Permalink
Add AV_LOG_PRINT_LEVEL flag to include log severity in default log fo…
Browse files Browse the repository at this point in the history
…rmatting.

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
  • Loading branch information
tue46wsdgxfjrt authored and michaelni committed Apr 26, 2014
1 parent 262ea96 commit 669a09f
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 11 deletions.
50 changes: 40 additions & 10 deletions libavutil/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -234,31 +259,34 @@ 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';
}
}

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)
{
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];
Expand All @@ -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)
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions libavutil/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion libavutil/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down

0 comments on commit 669a09f

Please sign in to comment.