[FFmpeg-cvslog] Add AV_LOG_PRINT_LEVEL flag to include log severity in default log formatting.
tue46wsdgxfjrt
git at videolan.org
Sat Apr 26 19:45:41 CEST 2014
ffmpeg | branch: master | tue46wsdgxfjrt <jfbvxt at gmail.com> | Thu Feb 27 16:36:09 2014 -0800| [669a09fb372fa58ff913ebc326cb64bb3e8e7928] | committer: Michael Niedermayer
Add AV_LOG_PRINT_LEVEL flag to include log severity in default log formatting.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=669a09fb372fa58ff913ebc326cb64bb3e8e7928
---
libavutil/log.c | 50 ++++++++++++++++++++++++++++++++++++++++----------
libavutil/log.h | 9 +++++++++
libavutil/version.h | 2 +-
3 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/libavutil/log.c b/libavutil/log.c
index cf4d990..0a8220b 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -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
diff --git a/libavutil/log.h b/libavutil/log.h
index d56d843..a6a07e0 100644
--- a/libavutil/log.h
+++ b/libavutil/log.h
@@ -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);
diff --git a/libavutil/version.h b/libavutil/version.h
index 832892b..edafa30 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -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, \
More information about the ffmpeg-cvslog
mailing list