History

avutil/log: support logging of date and time information

softworkz committed 1 year ago

Commit c79cdae1 parent e417f934 files · +43 −4Browse files

Unified · Split

4 files
  1. doc/APIchanges +3 −0
  2. libavutil/log.c +29 −3
  3. libavutil/log.h +10 −0
  4. libavutil/version.h +1 −1
doc/APIchanges+3−0
@@ -2,6 +2,9 @@ The last version increases of all libraries were on 2024-03-07 · 1 unmodified line
2 2
3API changes, most recent first:3API changes, most recent first:
4 4
52025-02-xx - xxxxxxxxxx - lavu 59.57.100 - log.h
6 Add flags AV_LOG_PRINT_TIME and AV_LOG_PRINT_DATETIME.
7
52025-02-09 - xxxxxxxxxx - lavc 61.32.100 - codec_id.h82025-02-09 - xxxxxxxxxx - lavc 61.32.100 - codec_id.h
6 Add AV_CODEC_ID_IVTV_VBI.9 Add AV_CODEC_ID_IVTV_VBI.
7 10
libavutil/log.c+29−3
@@ -42,6 +42,8 @@ · 41 unmodified lines
42#include "internal.h"42#include "internal.h"
43#include "log.h"43#include "log.h"
44#include "thread.h"44#include "thread.h"
45#include "time.h"
46#include "time_internal.h"
45 47
46static AVMutex mutex = AV_MUTEX_INITIALIZER;48static AVMutex mutex = AV_MUTEX_INITIALIZER;
47 49
@@ -296,14 +298,32 @@ static const char *item_name(void *obj, const AVClass *cls) · 248 unmodified lines
296 return (cls->item_name ? cls->item_name : av_default_item_name)(obj);298 return (cls->item_name ? cls->item_name : av_default_item_name)(obj);
297}299}
298 300
301static void format_date_now(AVBPrint* bp_time, int include_date)
302{
303 struct tm *ptm, tmbuf;
304 const int64_t time_us = av_gettime();
305 const int64_t time_ms = time_us / 1000;
306 const time_t time_s = time_ms / 1000;
307 const int millisec = time_ms - (time_s * 1000);
308 ptm = localtime_r(&time_s, &tmbuf);
309 if (ptm) {
310 if (include_date)
311 av_bprint_strftime(bp_time, "%Y-%m-%d ", ptm);
312
313 av_bprint_strftime(bp_time, "%H:%M:%S", ptm);
314 av_bprintf(bp_time, ".%03d ", millisec);
315 }
316}
317
299static void format_line(void *avcl, int level, const char *fmt, va_list vl,318static void format_line(void *avcl, int level, const char *fmt, va_list vl,
300 AVBPrint part[4], int *print_prefix, int type[2])319 AVBPrint part[5], int *print_prefix, int type[2])
301{320{
302 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;321 AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
303 av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC);322 av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC);
304 av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC);323 av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC);
305 av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC);324 av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC);
306 av_bprint_init(part+3, 0, 65536);325 av_bprint_init(part+3, 0, 65536);
326 av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC);
307 327
308 if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;328 if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16;
309 if (*print_prefix && avc) {329 if (*print_prefix && avc) {
@@ -321,6 +341,9 @@ static void format_line(void *avcl, int level, const char *fmt, va_list vl, · 11 unmodified lines
321 if(type) type[1] = get_category(avcl);341 if(type) type[1] = get_category(avcl);
322 }342 }
323 343
344 if (*print_prefix && (level > AV_LOG_QUIET) && (flags & (AV_LOG_PRINT_TIME | AV_LOG_PRINT_DATETIME)))
345 format_date_now(&part[4], flags & AV_LOG_PRINT_DATETIME);
346
324 if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL))347 if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL))
325 av_bprintf(part+2, "[%s] ", get_level_str(level));348 av_bprintf(part+2, "[%s] ", get_level_str(level));
326 349
@@ -341,7 +364,7 @@ void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl, · 14 unmodified lines
341int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,364int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl,
342 char *line, int line_size, int *print_prefix)365 char *line, int line_size, int *print_prefix)
343{366{
344 AVBPrint part[4];367 AVBPrint part[5];
345 int ret;368 int ret;
346 369
347 format_line(ptr, level, fmt, vl, part, print_prefix, NULL);370 format_line(ptr, level, fmt, vl, part, print_prefix, NULL);
@@ -355,7 +378,7 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) · 7 unmodified lines
355 static int print_prefix = 1;378 static int print_prefix = 1;
356 static int count;379 static int count;
357 static char prev[LINE_SZ];380 static char prev[LINE_SZ];
358 AVBPrint part[4];381 AVBPrint part[5];
359 char line[LINE_SZ];382 char line[LINE_SZ];
360 static int is_atty;383 static int is_atty;
361 int type[2];384 int type[2];
@@ -390,6 +413,9 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) · 28 unmodified lines
390 count = 0;413 count = 0;
391 }414 }
392 strcpy(prev, line);415 strcpy(prev, line);
416
417 sanitize(part[4].str);
418 colored_fputs(7, 0, part[4].str);
393 sanitize(part[0].str);419 sanitize(part[0].str);
394 colored_fputs(type[0], 0, part[0].str);420 colored_fputs(type[0], 0, part[0].str);
395 sanitize(part[1].str);421 sanitize(part[1].str);
libavutil/log.h+10−0
@@ -406,6 +406,16 @@ int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl, · 405 unmodified lines
406 */406 */
407#define AV_LOG_PRINT_LEVEL 2407#define AV_LOG_PRINT_LEVEL 2
408 408
409/**
410 * Include system time in log output.
411 */
412#define AV_LOG_PRINT_TIME 4
413
414/**
415 * Include system date and time in log output.
416 */
417#define AV_LOG_PRINT_DATETIME 8
418
409void av_log_set_flags(int arg);419void av_log_set_flags(int arg);
410int av_log_get_flags(void);420int av_log_get_flags(void);
411 421
libavutil/version.h+1−1
@@ -79,7 +79,7 @@ · 78 unmodified lines
79 */79 */
80 80
81#define LIBAVUTIL_VERSION_MAJOR 5981#define LIBAVUTIL_VERSION_MAJOR 59
82#define LIBAVUTIL_VERSION_MINOR 5682#define LIBAVUTIL_VERSION_MINOR 57
83#define LIBAVUTIL_VERSION_MICRO 10083#define LIBAVUTIL_VERSION_MICRO 100
84 84
85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \85#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t