[FFmpeg-devel] [PATCH] Add log severity level to default log formatting
hjiodjf 97xgw46
jfbvxt at gmail.com
Fri Feb 28 00:59:11 CET 2014
On Tue, Feb 18, 2014 at 3:14 AM, Carl Eugen Hoyos <cehoyos at ag.or.at> wrote:
> hjiodjf 97xgw46 <jfbvxt <at> gmail.com> writes:
>
>> Here is an updated patch
>
> The patch does not apply here.
> Please checkout current git head and please either
> use git commit and git format-patch or git diff
> from the main directory.
>
>> that fixes the issue with the format_line
>> declaration and adds messages for PANIC and QUIET.
>
> Does it add these messages unconditionally?
> Please add an option that is disabled by default.
>
> Carl Eugen
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
Here is a patch against git HEAD. It does add these messages
unconditionally. I am not opposed to making it optional, but I don't
see where to add this option. av_log_format_line is part of the public
API and its signature is:
void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
char *line, int line_size, int *print_prefix)
I don't want to add an option or API specifically for the CLI application.
-------------- next part --------------
diff --git a/libavutil/log.c b/libavutil/log.c
index 38ce1e8..386c4fc 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -185,13 +185,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) {
@@ -207,12 +232,14 @@ 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);
+
+ 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';
}
}
@@ -220,10 +247,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)
@@ -231,7 +258,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];
@@ -268,6 +295,8 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
colored_fputs(type[1], part[1].str);
sanitize(part[2].str);
colored_fputs(av_clip(level >> 3, 0, 6), part[2].str);
+ sanitize(part[3].str);
+ colored_fputs(av_clip(level >> 3, 0, 6), part[3].str);
end:
av_bprint_finalize(part+2, NULL);
#if HAVE_PTHREADS
More information about the ffmpeg-devel
mailing list