summaryrefslogtreecommitdiffstats
path: root/libavutil/log.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavutil/log.c')
-rw-r--r--libavutil/log.c62
1 files changed, 38 insertions, 24 deletions
diff --git a/libavutil/log.c b/libavutil/log.c
index 2969355..5e2b14b 100644
--- a/libavutil/log.c
+++ b/libavutil/log.c
@@ -2,20 +2,20 @@
* log functions
* Copyright (c) 2003 Michel Bardiaux
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -26,7 +26,6 @@
#include <unistd.h>
#include <stdlib.h>
-#include "avstring.h"
#include "avutil.h"
#include "log.h"
@@ -35,13 +34,13 @@ static int flags;
#if defined(_WIN32) && !defined(__MINGW32CE__)
#include <windows.h>
-static const uint8_t color[] = { 12, 12, 12, 14, 7, 7, 7 };
+static const uint8_t color[] = { 12, 12, 12, 14, 7, 7, 10 };
static int16_t background, attr_orig;
static HANDLE con;
#define set_color(x) SetConsoleTextAttribute(con, background | color[x])
#define reset_color() SetConsoleTextAttribute(con, attr_orig)
#else
-static const uint8_t color[] = { 0x41, 0x41, 0x11, 0x03, 9, 9, 9 };
+static const uint8_t color[] = { 0x41, 0x41, 0x11, 0x03, 9, 9, 2 };
#define set_color(x) fprintf(stderr, "\033[%d;3%dm", color[x] >> 4, color[x]&15)
#define reset_color() fprintf(stderr, "\033[0m")
#endif
@@ -85,42 +84,56 @@ const char *av_default_item_name(void *ptr)
return (*(AVClass **) ptr)->class_name;
}
-void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
+static void sanitize(uint8_t *line){
+ while(*line){
+ if(*line < 0x08 || (*line > 0x0D && *line < 0x20))
+ *line='?';
+ line++;
+ }
+}
+
+void av_log_format_line(void *ptr, int level, const char *fmt, va_list vl,
+ char *line, int line_size, int *print_prefix)
{
- static int print_prefix = 1;
- static int count;
- static char prev[1024];
- char line[1024];
- static int is_atty;
AVClass* avc = ptr ? *(AVClass **) ptr : NULL;
- if (level > av_log_level)
- return;
line[0] = 0;
-#undef fprintf
- if (print_prefix && avc) {
+ if (*print_prefix && avc) {
if (avc->parent_log_context_offset) {
AVClass** parent = *(AVClass ***) (((uint8_t *) ptr) +
avc->parent_log_context_offset);
if (parent && *parent) {
- snprintf(line, sizeof(line), "[%s @ %p] ",
+ snprintf(line, line_size, "[%s @ %p] ",
(*parent)->item_name(parent), parent);
}
}
- snprintf(line + strlen(line), sizeof(line) - strlen(line), "[%s @ %p] ",
+ snprintf(line + strlen(line), line_size - strlen(line), "[%s @ %p] ",
avc->item_name(ptr), ptr);
}
- vsnprintf(line + strlen(line), sizeof(line) - strlen(line), fmt, vl);
+ vsnprintf(line + strlen(line), line_size - strlen(line), fmt, vl);
- print_prefix = strlen(line) && line[strlen(line) - 1] == '\n';
+ *print_prefix = strlen(line) && line[strlen(line) - 1] == '\n';
+}
+
+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[1024];
+ char line[1024];
+ static int is_atty;
+
+ if (level > av_log_level)
+ return;
+ av_log_format_line(ptr, level, fmt, vl, line, sizeof(line), &print_prefix);
#if HAVE_ISATTY
if (!is_atty)
is_atty = isatty(2) ? 1 : -1;
#endif
- if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) &&
- !strncmp(line, prev, sizeof line)) {
+#undef fprintf
+ if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) && !strcmp(line, prev)){
count++;
if (is_atty == 1)
fprintf(stderr, " Last message repeated %d times\r", count);
@@ -130,8 +143,9 @@ void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
fprintf(stderr, " Last message repeated %d times\n", count);
count = 0;
}
+ strcpy(prev, line);
+ sanitize(line);
colored_fputs(av_clip(level >> 3, 0, 6), line);
- av_strlcpy(prev, line, sizeof line);
}
static void (*av_log_callback)(void*, int, const char*, va_list) =
OpenPOWER on IntegriCloud