From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 3CA8144041 for ; Wed, 24 Aug 2022 19:38:10 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 45ED968BA50; Wed, 24 Aug 2022 22:38:00 +0300 (EEST) Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A3DD68B993 for ; Wed, 24 Aug 2022 22:37:53 +0300 (EEST) Received: by mail-pl1-f169.google.com with SMTP id 2so16582466pll.0 for ; Wed, 24 Aug 2022 12:37:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:from:to:cc; bh=hbGPba1AgsjNqn7sKZLEahOt6xoCtJ9Tc1CDIBPAwdE=; b=f8rPcN1XWsAWUbG5vg7LizZza+6nMX9FiW0DqHTZ9E7NTrIfgbsZ2zOLtSEHXsBCZM 8UNlApImGoPYbQQHL8fKoWGP0apt4aU/KX44vuQ+/rgybNCFiZXz0CVsRghgnWxiHduK dC8qDguxqJx7RFn/S094H510VjbVlOVqizRTAFDgWlktUT6biR58KrPnJx6fy/5NDvLL c3fg/FitI7h/1FLwYlFnqeTJim5BQSEgNsDn43uLSxEdeU8aYJ3oBxsF7msopdnveWZj jT276nlvox/tyql3EuYg8PCbSwW+2jf60Z8bpXCGp+Dt1rKfpctAE6WrZsNTUm8a46z8 hxBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date :references:in-reply-to:message-id:from:x-gm-message-state:from:to :cc; bh=hbGPba1AgsjNqn7sKZLEahOt6xoCtJ9Tc1CDIBPAwdE=; b=c0DTaCyeqhVQfGoWsiM4t+xzwc0Xs4uBSurl7xs6mr9NOVu0VRZrUNI6azErIyG+f3 eJRjD6LUDrBTiJ2JKY0iFWKlhF1xixieTEHT5A+tQnpC7b+if11QPaZpXr07ebqD3H5K f4rE99LTB0Dip5WqEPDka0r+Ua30vg0VtN//9W09Z6Mv+h3/OReXtFEbkg+4mpEO2BAF g+g9GVcwUPI5H8Nuwk1xRvBXvjQHOGN7C9GGAPn6NwK1ech7+2FBE4qP7+1F7JjH4Vw0 hzkV31I9GPIzY3csuhl5mCa8SEWvgLqUNBrDSvLTOEmjWkZGYSCyIL3/qGznlmn1FMsi RegA== X-Gm-Message-State: ACgBeo2815rWGtzyYW9zLlPlFjCE5+5ro8I0iSkHBULURlC7DFb32JnY E5BSsV+qJhU96qGkLpoXqz6TYVuBGrg= X-Google-Smtp-Source: AA6agR5ltxOPx1reNU5p3ArT1b9mMhry1gpweTadW8rvZSOl3AOUHV3766FLhKJSt5YL1QYrnUv+2A== X-Received: by 2002:a17:90b:4b0c:b0:1f4:ffac:699a with SMTP id lx12-20020a17090b4b0c00b001f4ffac699amr9694761pjb.145.1661369871274; Wed, 24 Aug 2022 12:37:51 -0700 (PDT) Received: from [127.0.0.1] (master.gitmailbox.com. [34.83.118.50]) by smtp.gmail.com with ESMTPSA id l4-20020a17090a850400b001eff36b1f2asm1842935pjn.0.2022.08.24.12.37.50 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Aug 2022 12:37:50 -0700 (PDT) From: softworkz X-Google-Original-From: softworkz Message-Id: <5dc718cfd5f8a3a9b9df0bee3fc8a5050b9a62e9.1661369869.git.ffmpegagent@gmail.com> In-Reply-To: References: Date: Wed, 24 Aug 2022 19:37:47 +0000 Fcc: Sent MIME-Version: 1.0 To: ffmpeg-devel@ffmpeg.org Subject: [FFmpeg-devel] [PATCH 1/3] avutil/log: support logging of date and timing information X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: softworkz Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: softworkz Signed-off-by: softworkz --- doc/APIchanges | 3 +++ libavutil/log.c | 32 +++++++++++++++++++++++++++++--- libavutil/log.h | 10 ++++++++++ libavutil/version.h | 4 ++-- 4 files changed, 44 insertions(+), 5 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 4c0c9db628..eae5ba0525 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -14,6 +14,9 @@ libavutil: 2021-04-27 API changes, most recent first: +2022-08-xx - xxxxxxxxxx - lavu 57.34.100 - log.h + Add flags AV_LOG_PRINT_TIME and AV_LOG_PRINT_DATETIME. + 2022-08-xx - xxxxxxxxxx - lavf 59 - avformat.h Deprecate av_stream_get_end_pts() without replacement. diff --git a/libavutil/log.c b/libavutil/log.c index 5948e50467..15a43c1631 100644 --- a/libavutil/log.c +++ b/libavutil/log.c @@ -42,6 +42,8 @@ #include "internal.h" #include "log.h" #include "thread.h" +#include "time.h" +#include "time_internal.h" static AVMutex mutex = AV_MUTEX_INITIALIZER; @@ -291,14 +293,32 @@ 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_us = av_gettime(); + const int64_t time_ms = time_us / 1000; + const time_t time_s = time_ms / 1000; + const int millisec = time_ms - (time_s * 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; 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) { @@ -316,6 +336,9 @@ 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)); @@ -336,7 +359,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); @@ -350,7 +373,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]; @@ -385,6 +408,9 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) count = 0; } strcpy(prev, line); + + sanitize(part[4].str); + 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 ab7ceabe22..8336f65b16 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 system time in log output. + */ +#define AV_LOG_PRINT_TIME 4 + +/** + * Include system 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 05661922b3..5d0df781cc 100644 --- a/libavutil/version.h +++ b/libavutil/version.h @@ -79,8 +79,8 @@ */ #define LIBAVUTIL_VERSION_MAJOR 57 -#define LIBAVUTIL_VERSION_MINOR 33 -#define LIBAVUTIL_VERSION_MICRO 101 +#define LIBAVUTIL_VERSION_MINOR 34 +#define LIBAVUTIL_VERSION_MICRO 100 #define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \ LIBAVUTIL_VERSION_MINOR, \ -- ffmpeg-codebot _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".