Message ID | MN2PR04MB5981DEF85223E59E0F0F49CEBAF79@MN2PR04MB5981.namprd04.prod.outlook.com |
---|---|
State | Superseded, archived |
Headers | show |
Series | [FFmpeg-devel,v5,1/2] libavutil/log: Add capability to prefix loglines with current time or current date+time | expand |
Context | Check | Description |
---|---|---|
andriy/x86_make | success | Make finished |
andriy/x86_make_fate | success | Make fate finished |
andriy/PPC64_make | success | Make finished |
andriy/PPC64_make_fate | success | Make fate finished |
Soft Works: > Signed-off-by: softworkz <softworkz@hotmail.com> > --- > doc/APIchanges | 3 +++ > libavutil/log.c | 35 ++++++++++++++++++++++++++++++----- > libavutil/log.h | 10 ++++++++++ > libavutil/version.h | 2 +- > 4 files changed, 44 insertions(+), 6 deletions(-) > > diff --git a/doc/APIchanges b/doc/APIchanges > index 6eefc7fc33..be707314f3 100644 > --- a/doc/APIchanges > +++ b/doc/APIchanges > @@ -14,6 +14,9 @@ libavutil: 2021-04-27 > > API changes, most recent first: > > +2021-08-09 - xxxxxxxxxx - lavu 57.4.100 - log.h > + Add new defines: AV_LOG_PRINT_TIME and AV_LOG_PRINT_DATETIME Add new logging flags > + > 2021-08-02 - xxxxxxxxxx - lavc 59.4.100 - packet.h > Add AVPacket.opaque, AVPacket.opaque_ref, AVPacket.time_base. > > diff --git a/libavutil/log.c b/libavutil/log.c > index 66defa9c42..34af1da60c 100644 > --- a/libavutil/log.c > +++ b/libavutil/log.c > static void format_line(void *avcl, int level, const char *fmt, va_list vl, > - AVBPrint part[4], int *print_prefix, int type[2]) > + AVBPrint part[5], int *print_prefix, int type[2]) > { > - AVClass* avc = avcl ? *(AVClass **) avcl : NULL; > + AVClass *avc = avcl ? *(AVClass **) avcl : NULL; > av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC); > av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC); > av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC); > av_bprint_init(part+3, 0, 65536); > + av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC); > > if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; > if (*print_prefix && avc) { > if (avc->parent_log_context_offset) { > - AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) + > + AVClass **parent = *(AVClass ***) (((uint8_t *) avcl) + Nicolas wanted you to not add new code with the * not attached to the variable; he did not ask you to change existing code in the same patch. Spurious changes are frowned upon, as they impair reviewability. > avc->parent_log_context_offset); > if (parent && *parent) { > av_bprintf(part+0, "[%s @ %p] ", - Andreas
> -----Original Message----- > From: ffmpeg-devel <ffmpeg-devel-bounces@ffmpeg.org> On Behalf Of Andreas > Rheinhardt > Sent: Tuesday, 10 August 2021 17:33 > To: ffmpeg-devel@ffmpeg.org > Subject: Re: [FFmpeg-devel] [PATCH v5 1/2] libavutil/log: Add capability > to prefix loglines with current time or current date+time > > Soft Works: > > Signed-off-by: softworkz <softworkz@hotmail.com> > > --- > > doc/APIchanges | 3 +++ > > libavutil/log.c | 35 ++++++++++++++++++++++++++++++----- > > libavutil/log.h | 10 ++++++++++ > > libavutil/version.h | 2 +- > > 4 files changed, 44 insertions(+), 6 deletions(-) > > > > diff --git a/libavutil/log.c b/libavutil/log.c > > index 66defa9c42..34af1da60c 100644 > > --- a/libavutil/log.c > > +++ b/libavutil/log.c > > static void format_line(void *avcl, int level, const char *fmt, va_list > vl, > > - AVBPrint part[4], int *print_prefix, int > type[2]) > > + AVBPrint part[5], int *print_prefix, int > type[2]) > > { > > - AVClass* avc = avcl ? *(AVClass **) avcl : NULL; > > + AVClass *avc = avcl ? *(AVClass **) avcl : NULL; > > av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC); > > av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC); > > av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC); > > av_bprint_init(part+3, 0, 65536); > > + av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC); > > > > if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; > > if (*print_prefix && avc) { > > if (avc->parent_log_context_offset) { > > - AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) + > > + AVClass **parent = *(AVClass ***) (((uint8_t *) avcl) + > > Nicolas wanted you to not add new code with the * not attached to the > variable; he did not ask you to change existing code in the same patch. > Spurious changes are frowned upon, as they impair reviewability. Updated. Time's too precious to start arguing about such things... softworkz
diff --git a/doc/APIchanges b/doc/APIchanges index 6eefc7fc33..be707314f3 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2021-04-27 API changes, most recent first: +2021-08-09 - xxxxxxxxxx - lavu 57.4.100 - log.h + Add new defines: AV_LOG_PRINT_TIME and AV_LOG_PRINT_DATETIME + 2021-08-02 - xxxxxxxxxx - lavc 59.4.100 - packet.h Add AVPacket.opaque, AVPacket.opaque_ref, AVPacket.time_base. diff --git a/libavutil/log.c b/libavutil/log.c index 66defa9c42..34af1da60c 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -40,6 +40,8 @@ #include "internal.h" #include "log.h" #include "thread.h" +#include "time.h" +#include "time_internal.h" static AVMutex mutex = AV_MUTEX_INITIALIZER; @@ -289,19 +291,36 @@ static const char *get_level_str(int level) } } +static void format_date_now(AVBPrint *timeBuf, int include_date) +{ + struct tm *ptm, tmbuf; + const int64_t time_ms = av_gettime() / 1000; + const time_t time_s = time_ms / 1000; + const int millisec = time_ms % 1000; + ptm = localtime_r(&time_s, &tmbuf); + if (ptm) { + if (include_date) + av_bprint_strftime(timeBuf, "%Y-%m-%d ", ptm); + + av_bprint_strftime(timeBuf, "%H:%M:%S", ptm); + av_bprintf(timeBuf, ".%03d ", millisec); + } +} + static void format_line(void *avcl, int level, const char *fmt, va_list vl, - AVBPrint part[4], int *print_prefix, int type[2]) + AVBPrint part[5], int *print_prefix, int type[2]) { - AVClass* avc = avcl ? *(AVClass **) avcl : NULL; + AVClass *avc = avcl ? *(AVClass **) avcl : NULL; av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC); av_bprint_init(part+3, 0, 65536); + av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC); if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; if (*print_prefix && avc) { if (avc->parent_log_context_offset) { - AVClass** parent = *(AVClass ***) (((uint8_t *) avcl) + + AVClass **parent = *(AVClass ***) (((uint8_t *) avcl) + avc->parent_log_context_offset); if (parent && *parent) { av_bprintf(part+0, "[%s @ %p] ", @@ -314,6 +333,10 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl, if(type) type[1] = get_category(avcl); } + if (*print_prefix + && (flags & (AV_LOG_PRINT_TIME | AV_LOG_PRINT_DATETIME))) + format_date_now(&part[4], flags & AV_LOG_PRINT_DATETIME); + if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL)) av_bprintf(part+2, "[%s] ", get_level_str(level)); @@ -334,7 +357,7 @@ void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl, char *line, int line_size, int *print_prefix) { - AVBPrint part[4]; + AVBPrint part[5]; int ret; format_line(ptr, level, fmt, vl, part, print_prefix, NULL); @@ -348,7 +371,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[4]; + AVBPrint part[5]; char line[LINE_SZ]; static int is_atty; int type[2]; @@ -383,6 +406,8 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) count = 0; } strcpy(prev, line); + + colored_fputs(7, 0, part[4].str); sanitize(part[0].str); colored_fputs(type[0], 0, part[0].str); sanitize(part[1].str); diff --git a/libavutil/log.h b/libavutil/log.h index 8727c38afc..b071f0f1eb 100644 --- a/libavutil/log.h +++ b/libavutil/log.h @@ -377,6 +377,16 @@ int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl, */ #define AV_LOG_PRINT_LEVEL 2 +/** + * Include local time in log output. + */ +#define AV_LOG_PRINT_TIME 4 + +/** + * Include local date and time in log output. + */ +#define AV_LOG_PRINT_DATETIME 8 + void av_log_set_flags(int arg); int av_log_get_flags(void); diff --git a/libavutil/version.h b/libavutil/version.h index 6b4a265457..201b012596 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,7 +79,7 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 3 +#define LIBAVUTIL_VERSION_MINOR 4 #define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
Signed-off-by: softworkz <softworkz@hotmail.com> --- doc/APIchanges | 3 +++ libavutil/log.c | 35 ++++++++++++++++++++++++++++++----- libavutil/log.h | 10 ++++++++++ libavutil/version.h | 2 +- 4 files changed, 44 insertions(+), 6 deletions(-)