[PATCH] Add log severity level to default log formatting
This patch adds the severity of log events to the default format string. Currently, it is not possible to distinguish info/warning/error/fatal messages if coloring is not enabled.
On 02/14/2014 02:54 PM, hjiodjf 97xgw46 wrote:
This patch adds the severity of log events to the default format string. Currently, it is not possible to distinguish info/warning/error/fatal messages if coloring is not enabled.
Did you make sure this does the right thing for _PANIC and _QUIET? -- Reynaldo H. Verdejo Pinochet Sr. Multimedia Engineer, Open Source Group Samsung Research America - Silicon Valley
On 14.02.2014 18:54, hjiodjf 97xgw46 wrote:
static void format_line(void *ptr, int level, const char *fmt, va_list vl, AVBPrint part[3], int *print_prefix, int type[2]) { AVClass* avc = ptr ? *(AVClass **) ptr : 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);
argument is still part[3]. Should be part[4] now. -- Best Regards, Lukasz Marek Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
Here is an updated patch that fixes the issue with the format_line declaration and adds messages for PANIC and QUIET. On Fri, Feb 14, 2014 at 11:10 AM, Lukasz Marek <lukasz.m.luki@gmail.com> wrote:
On 14.02.2014 18:54, hjiodjf 97xgw46 wrote:
static void format_line(void *ptr, int level, const char *fmt, va_list vl, AVBPrint part[3], int *print_prefix, int type[2]) { AVClass* avc = ptr ? *(AVClass **) ptr : 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);
argument is still part[3]. Should be part[4] now.
-- Best Regards, Lukasz Marek
Insanity: doing the same thing over and over again and expecting different results. - Albert Einstein
_______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
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
On Tue, Feb 18, 2014 at 3:14 AM, Carl Eugen Hoyos <cehoyos@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@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.
On Thu, Feb 27, 2014 at 03:59:11PM -0800, hjiodjf 97xgw46 wrote:
On Tue, Feb 18, 2014 at 3:14 AM, Carl Eugen Hoyos <cehoyos@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@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)
you can add a flag similar to the existing #define AV_LOG_SKIP_REPEATED 1 [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Everything should be made as simple as possible, but not simpler. -- Albert Einstein
On Sat, Mar 29, 2014 at 5:07 AM, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Feb 27, 2014 at 03:59:11PM -0800, hjiodjf 97xgw46 wrote:
On Tue, Feb 18, 2014 at 3:14 AM, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Does it add these messages unconditionally? Please add an option that is disabled by default.
Carl Eugen
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)
you can add a flag similar to the existing
#define AV_LOG_SKIP_REPEATED 1
I've taken michaelni's advice and implemented an AV_LOG flag and corresponding CLI option for this feature. I hope the latest incarnation of this patch can be reviewed, and more importantly, a decision made on if this feature is wanted.
On Thu, Apr 24, 2014 at 10:31:00AM -0700, hjiodjf 97xgw46 wrote:
On Sat, Mar 29, 2014 at 5:07 AM, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Feb 27, 2014 at 03:59:11PM -0800, hjiodjf 97xgw46 wrote:
On Tue, Feb 18, 2014 at 3:14 AM, Carl Eugen Hoyos <cehoyos@ag.or.at> wrote:
Does it add these messages unconditionally? Please add an option that is disabled by default.
Carl Eugen
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)
you can add a flag similar to the existing
#define AV_LOG_SKIP_REPEATED 1
I've taken michaelni's advice and implemented an AV_LOG flag and corresponding CLI option for this feature. I hope the latest incarnation of this patch can be reviewed, and more importantly, a decision made on if this feature is wanted.
cmdutils.c | 16 +++++++++++++++- cmdutils.h | 2 ++ cmdutils_common_opts.h | 1 + libavutil/log.c | 48 +++++++++++++++++++++++++++++++++++++++--------- libavutil/log.h | 9 +++++++++ 5 files changed, 66 insertions(+), 10 deletions(-) e1e8f5ae3dbea74caff52f8c391369407f4a452f 0001-Add-AV_LOG_PRINT_LEVEL-flag-to-include-log-severity-.patch From 9e1cfef64832a205616d82302410f1c3474a2978 Mon Sep 17 00:00:00 2001 From: tue46wsdgxfjrt <jfbvxt@gmail.com> Date: Thu, 27 Feb 2014 16:36:09 -0800 Subject: [PATCH 1/2] Add AV_LOG_PRINT_LEVEL flag to include log severity in default log formatting.
--- cmdutils.c | 16 +++++++++++++++- cmdutils.h | 2 ++ cmdutils_common_opts.h | 1 + libavutil/log.c | 48 +++++++++++++++++++++++++++++++++++++++--------- libavutil/log.h | 9 +++++++++ 5 files changed, 66 insertions(+), 10 deletions(-)
diff --git a/cmdutils.c b/cmdutils.c index ebbbe7f..691836c 100644 --- a/cmdutils.c +++ b/cmdutils.c @@ -67,6 +67,7 @@ AVDictionary *format_opts, *codec_opts, *resample_opts;
static FILE *report_file; int hide_banner = 0; +int print_level = 0;
void init_opts(void) { @@ -834,10 +835,17 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg) }; char *tail; int level; + int flags; int i;
+ flags = av_log_get_flags(); tail = strstr(arg, "repeat"); - av_log_set_flags(tail ? 0 : AV_LOG_SKIP_REPEATED); + if (tail) + flags &= ~AV_LOG_SKIP_REPEATED; + else + flags |= AV_LOG_SKIP_REPEATED; + + av_log_set_flags(flags); if (tail == arg) arg += 6 + (arg[6]=='+'); if(tail && !*arg) @@ -958,6 +966,12 @@ int opt_report(const char *opt) return init_report(NULL); }
+int opt_print_level(const char *opt) +{ + av_log_set_flags(av_log_get_flags() | AV_LOG_PRINT_LEVEL); + return 0; +} + int opt_max_alloc(void *optctx, const char *opt, const char *arg) { char *tail; diff --git a/cmdutils.h b/cmdutils.h index 2b9a825..be855d1 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -95,6 +95,8 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg);
int opt_report(const char *opt);
+int opt_print_level(const char *opt); + int opt_max_alloc(void *optctx, const char *opt, const char *arg);
int opt_codec_debug(void *optctx, const char *opt, const char *arg);
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index 190dba6..4dde4fc 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -22,6 +22,7 @@ { "max_alloc" , HAS_ARG, {.func_arg = opt_max_alloc}, "set maximum size of a single allocated block", "bytes" }, { "cpuflags" , HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, + { "print_level", 0, {(void*)opt_print_level}, "include log level in console output"},
this will fail with av_log() that are run before the main command line parsing. the log level is special cased so its parsed earlier also it seems this patch breaks the output there seem alot more "Last message repeated" messages than actually repeated messages [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Why not whip the teacher when the pupil misbehaves? -- Diogenes of Sinope
On Thu, Apr 24, 2014 at 2:18 PM, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Apr 24, 2014 at 10:31:00AM -0700, hjiodjf 97xgw46 wrote:
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index 190dba6..4dde4fc 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -22,6 +22,7 @@ { "max_alloc" , HAS_ARG, {.func_arg = opt_max_alloc}, "set maximum size of a single allocated block", "bytes" }, { "cpuflags" , HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, + { "print_level", 0, {(void*)opt_print_level}, "include log level in console output"},
this will fail with av_log() that are run before the main command line parsing. the log level is special cased so its parsed earlier
also it seems this patch breaks the output there seem alot more "Last message repeated" messages than actually repeated messages
I forgot to update the code that stores the last printed line. I have attached a fixed patch that avoids the erroneous "Last message repeated" events and hooks into parse_loglevel to allow initialization before option parsing.
On Thu, Apr 24, 2014 at 03:08:38PM -0700, hjiodjf 97xgw46 wrote:
On Thu, Apr 24, 2014 at 2:18 PM, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Apr 24, 2014 at 10:31:00AM -0700, hjiodjf 97xgw46 wrote:
diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index 190dba6..4dde4fc 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -22,6 +22,7 @@ { "max_alloc" , HAS_ARG, {.func_arg = opt_max_alloc}, "set maximum size of a single allocated block", "bytes" }, { "cpuflags" , HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, + { "print_level", 0, {(void*)opt_print_level}, "include log level in console output"},
this will fail with av_log() that are run before the main command line parsing. the log level is special cased so its parsed earlier
also it seems this patch breaks the output there seem alot more "Last message repeated" messages than actually repeated messages
I forgot to update the code that stores the last printed line. I have attached a fixed patch that avoids the erroneous "Last message repeated" events and hooks into parse_loglevel to allow initialization before option parsing.
cmdutils.c | 19 +++++++++++++++++- cmdutils.h | 2 + cmdutils_common_opts.h | 1 libavutil/log.c | 50 +++++++++++++++++++++++++++++++++++++++---------- libavutil/log.h | 9 ++++++++ 5 files changed, 70 insertions(+), 11 deletions(-) c40bf508780456c1e6eb4c54b542a13431a55d36 0001-Add-AV_LOG_PRINT_LEVEL-flag-to-include-log-severity-.patch From 4ea25a07d6817ead75a503626a1e11da8580ffb7 Mon Sep 17 00:00:00 2001 From: tue46wsdgxfjrt <jfbvxt@gmail.com> Date: Thu, 27 Feb 2014 16:36:09 -0800 Subject: [PATCH 1/2] Add AV_LOG_PRINT_LEVEL flag to include log severity in default log formatting.
partly applied see comments below [...]
@@ -958,6 +969,12 @@ int opt_report(const char *opt) return init_report(NULL); }
+int opt_print_level(const char *opt) +{ + av_log_set_flags(av_log_get_flags() | AV_LOG_PRINT_LEVEL); + return 0; +}
this allows enabling but not disabling the feature
+ int opt_max_alloc(void *optctx, const char *opt, const char *arg) { char *tail; diff --git a/cmdutils.h b/cmdutils.h index 2b9a825..be855d1 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -95,6 +95,8 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg);
int opt_report(const char *opt);
+int opt_print_level(const char *opt); + int opt_max_alloc(void *optctx, const char *opt, const char *arg);
int opt_codec_debug(void *optctx, const char *opt, const char *arg); diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index 190dba6..4dde4fc 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -22,6 +22,7 @@ { "max_alloc" , HAS_ARG, {.func_arg = opt_max_alloc}, "set maximum size of a single allocated block", "bytes" }, { "cpuflags" , HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, + { "print_level", 0, {(void*)opt_print_level}, "include log level in console output"},
why is this not OPT_BOOL? that should allow disabling as well
#if CONFIG_OPENCL { "opencl_bench", OPT_EXIT, {.func_arg = opt_opencl_bench}, "run benchmark on all OpenCL devices and show results" }, { "opencl_options", HAS_ARG, {.func_arg = opt_opencl}, "set OpenCL environment options" }, 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 ""; + } +}
that probably is fine with most or all existing code but there are intermediate log levels too also APIChanges update is missing [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Old school: Use the lowest level language in which you can solve the problem conveniently. New school: Use the highest level language in which the latest supercomputer can solve the problem without the user falling asleep waiting.
On Sat, Apr 26, 2014 at 10:43 AM, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Apr 24, 2014 at 03:08:38PM -0700, hjiodjf 97xgw46 wrote: [...]
@@ -958,6 +969,12 @@ int opt_report(const char *opt) return init_report(NULL); }
+int opt_print_level(const char *opt) +{ + av_log_set_flags(av_log_get_flags() | AV_LOG_PRINT_LEVEL); + return 0; +}
this allows enabling but not disabling the feature
+ int opt_max_alloc(void *optctx, const char *opt, const char *arg) { char *tail; diff --git a/cmdutils.h b/cmdutils.h index 2b9a825..be855d1 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -95,6 +95,8 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg);
int opt_report(const char *opt);
+int opt_print_level(const char *opt); + int opt_max_alloc(void *optctx, const char *opt, const char *arg);
int opt_codec_debug(void *optctx, const char *opt, const char *arg); diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index 190dba6..4dde4fc 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -22,6 +22,7 @@ { "max_alloc" , HAS_ARG, {.func_arg = opt_max_alloc}, "set maximum size of a single allocated block", "bytes" }, { "cpuflags" , HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, + { "print_level", 0, {(void*)opt_print_level}, "include log level in console output"},
why is this not OPT_BOOL? that should allow disabling as well
An OPT_BOOL would let me set a flag somewhere, but something still needs to read the flag and pass it to av_log_set_flags. I couldn't find a good common place in the code to do that.
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 ""; + } +}
that probably is fine with most or all existing code but there are intermediate log levels too
also APIChanges update is missing
[...]
For intermediate log levels, should I print the level with the next-lowest severity?
On Tue, Apr 29, 2014 at 02:22:49PM -0700, hjiodjf 97xgw46 wrote:
On Sat, Apr 26, 2014 at 10:43 AM, Michael Niedermayer <michaelni@gmx.at> wrote:
On Thu, Apr 24, 2014 at 03:08:38PM -0700, hjiodjf 97xgw46 wrote: [...]
@@ -958,6 +969,12 @@ int opt_report(const char *opt) return init_report(NULL); }
+int opt_print_level(const char *opt) +{ + av_log_set_flags(av_log_get_flags() | AV_LOG_PRINT_LEVEL); + return 0; +}
this allows enabling but not disabling the feature
+ int opt_max_alloc(void *optctx, const char *opt, const char *arg) { char *tail; diff --git a/cmdutils.h b/cmdutils.h index 2b9a825..be855d1 100644 --- a/cmdutils.h +++ b/cmdutils.h @@ -95,6 +95,8 @@ int opt_loglevel(void *optctx, const char *opt, const char *arg);
int opt_report(const char *opt);
+int opt_print_level(const char *opt); + int opt_max_alloc(void *optctx, const char *opt, const char *arg);
int opt_codec_debug(void *optctx, const char *opt, const char *arg); diff --git a/cmdutils_common_opts.h b/cmdutils_common_opts.h index 190dba6..4dde4fc 100644 --- a/cmdutils_common_opts.h +++ b/cmdutils_common_opts.h @@ -22,6 +22,7 @@ { "max_alloc" , HAS_ARG, {.func_arg = opt_max_alloc}, "set maximum size of a single allocated block", "bytes" }, { "cpuflags" , HAS_ARG | OPT_EXPERT, { .func_arg = opt_cpuflags }, "force specific cpu flags", "flags" }, { "hide_banner", OPT_BOOL | OPT_EXPERT, {&hide_banner}, "do not show program banner", "hide_banner" }, + { "print_level", 0, {(void*)opt_print_level}, "include log level in console output"},
why is this not OPT_BOOL? that should allow disabling as well
An OPT_BOOL would let me set a flag somewhere, but something still needs to read the flag and pass it to av_log_set_flags. I couldn't find a good common place in the code to do that.
parse_loglevel() might work
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 ""; + } +}
that probably is fine with most or all existing code but there are intermediate log levels too
also APIChanges update is missing
[...]
For intermediate log levels, should I print the level with the next-lowest severity?
i dont know what is the best solution, just wanted to point the problem out [...] -- Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB Rewriting code that is poorly written but fully understood is good. Rewriting code that one doesnt understand is a sign that one is less smart then the original author, trying to rewrite it will not make it better.
participants (5)
-
Carl Eugen Hoyos -
hjiodjf 97xgw46 -
Lukasz Marek -
Michael Niedermayer -
Reynaldo H. Verdejo Pinochet