| @@ -42,6 +42,8 @@ · 41 unmodified lines |
| 42 | 42 | #include "internal.h" |
| 43 | 43 | #include "log.h" |
| 44 | 44 | #include "thread.h" |
| 45 | +#include "time.h" |
| 46 | +#include "time_internal.h" |
| 45 | 47 | |
| 46 | 48 | static 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 | 298 | return (cls->item_name ? cls->item_name : av_default_item_name)(obj); |
| 297 | 299 | } |
| 298 | 300 | |
| 301 | +static 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 | + |
| 299 | 318 | static 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 | 321 | AVClass* avc = avcl ? *(AVClass **) avcl : NULL; |
| 303 | 322 | av_bprint_init(part+0, 0, AV_BPRINT_SIZE_AUTOMATIC); |
| 304 | 323 | av_bprint_init(part+1, 0, AV_BPRINT_SIZE_AUTOMATIC); |
| 305 | 324 | av_bprint_init(part+2, 0, AV_BPRINT_SIZE_AUTOMATIC); |
| 306 | 325 | av_bprint_init(part+3, 0, 65536); |
| 326 | + av_bprint_init(part+4, 0, AV_BPRINT_SIZE_AUTOMATIC); |
| 307 | 327 | |
| 308 | 328 | if(type) type[0] = type[1] = AV_CLASS_CATEGORY_NA + 16; |
| 309 | 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 | 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 | 347 | if (*print_prefix && (level > AV_LOG_QUIET) && (flags & AV_LOG_PRINT_LEVEL)) |
| 325 | 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 |
| 341 | 364 | int av_log_format_line2(void *ptr, int level, const char *fmt, va_list vl, |
| 342 | 365 | char *line, int line_size, int *print_prefix) |
| 343 | 366 | { |
| 344 | | − AVBPrint part[4]; |
| 367 | + AVBPrint part[5]; |
| 345 | 368 | int ret; |
| 346 | 369 | |
| 347 | 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 | 378 | static int print_prefix = 1; |
| 356 | 379 | static int count; |
| 357 | 380 | static char prev[LINE_SZ]; |
| 358 | | − AVBPrint part[4]; |
| 381 | + AVBPrint part[5]; |
| 359 | 382 | char line[LINE_SZ]; |
| 360 | 383 | static int is_atty; |
| 361 | 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 | 413 | count = 0; |
| 391 | 414 | } |
| 392 | 415 | strcpy(prev, line); |
| 416 | + |
| 417 | + sanitize(part[4].str); |
| 418 | + colored_fputs(7, 0, part[4].str); |
| 393 | 419 | sanitize(part[0].str); |
| 394 | 420 | colored_fputs(type[0], 0, part[0].str); |
| 395 | 421 | sanitize(part[1].str); |