On 01/08/14 17:20, Luca Barbato wrote:
> It support syslog(3) and android-specific logging.
> ---
> configure | 5 ++
> libavutil/log.c | 152
> +++++++++++++++++++++++++++++++++++++++++++++++---------
> libavutil/log.h | 14 ++++++
> 3 files changed, 147 insertions(+), 24 deletions(-)
>
> diff --git a/configure b/configure
> index 03742f0..a74b4b2 100755
> --- a/configure
> +++ b/configure
> @@ -1365,6 +1365,7 @@ HAVE_LIST_PUB="
> HEADERS_LIST="
> alsa_asoundlib_h
> altivec_h
> + android_log_h
> arpa_inet_h
> cdio_paranoia_h
> cdio_paranoia_paranoia_h
> @@ -1393,6 +1394,7 @@ HEADERS_LIST="
> sys_time_h
> sys_un_h
> sys_videoio_h
> + syslog_h
> unistd_h
> windows_h
> winsock2_h
> @@ -4042,6 +4044,7 @@ check_header sys/resource.h
> check_header sys/select.h
> check_header sys/time.h
> check_header sys/un.h
> +check_header syslog.h
> check_header unistd.h
> check_header vdpau/vdpau.h
> check_header vdpau/vdpau_x11.h
> @@ -4049,6 +4052,8 @@ check_header VideoDecodeAcceleration/VDADecoder.h
> check_header windows.h
> check_header X11/extensions/XvMClib.h
>
> +check_lib2 "android/log.h" __android_log_print -llog
> +
> check_lib2 "windows.h shellapi.h" CommandLineToArgvW -lshell32
> check_lib2 "windows.h wincrypt.h" CryptGenRandom -ladvapi32
> check_lib2 "windows.h psapi.h" GetProcessMemoryInfo -lpsapi
> diff --git a/libavutil/log.c b/libavutil/log.c
> index 5a8f293..2d15e50 100644
> --- a/libavutil/log.c
> +++ b/libavutil/log.c
> @@ -26,6 +26,14 @@
>
> #include "config.h"
>
> +#if HAVE_ANDROID_LOG_H
> +#include <android/log.h>
> +#endif
> +
> +#if HAVE_SYSLOG_H
> +#include <syslog.h>
> +#endif
> +
> #if HAVE_UNISTD_H
> #include <unistd.h>
> #endif
> @@ -110,16 +118,118 @@ const char *av_default_item_name(void *ptr)
> return (*(AVClass **) ptr)->class_name;
> }
>
> -void av_log_default_callback(void *avcl, int level, const char *fmt, va_list
> vl)
> +/*
> +void av_log_syslog_callback(void *avcl, int level, const char *fmt, va_list
> vl)
> +{
> +
> +
> +}
> +*/
Stray aleady removed.
> +
> +#define LINE_SIZE 1024
> +static int print_prefix = 1;
> +static int count;
> +static char prev[LINE_SIZE];
> +static int is_atty;
> +
> +static void default_print(int level, const char *line)
> {
> - static int print_prefix = 1;
> - static int count;
> - static char prev[1024];
> - char line[1024];
> - static int is_atty;
> - AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
> unsigned tint = level & 0xff00;
>
> +#if HAVE_ISATTY
> + if (!is_atty)
> + is_atty = isatty(2) ? 1 : -1;
> +#endif
> +
> + if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) &&
> + !strncmp(line, prev, LINE_SIZE)) {
> + count++;
> + if (is_atty == 1)
> + fprintf(stderr, " Last message repeated %d times\r", count);
> + return;
> + }
> + if (count > 0) {
> + fprintf(stderr, " Last message repeated %d times\n", count);
> + count = 0;
> + }
> + colored_fputs(av_clip(level >> 3, 0, 6), tint >> 8, line);
> + av_strlcpy(prev, line, LINE_SIZE);
> +}
> +
> +#if HAVE_ANDROID_LOG_H
> +
> +static void syslog_print(int level, const char *line)
> +{
> + switch(level) {
> + case AV_LOG_PANIC:
> + case AV_LOG_FATAL:
> + level = ANDROID_LOG_FATAL;
> + break;
> + case AV_LOG_ERROR:
> + level = ANDROID_LOG_ERROR;
> + break;
> + case AV_LOG_WARNING:
> + level = ANDROID_LOG_WARN;
> + break;
> + case AV_LOG_INFO:
> + level = ANDROID_LOG_INFO;
> + break;
> + case AV_LOG_VERBOSE:
> + level = ANDROID_LOG_VERBOSE;
> + break;
> + case AV_LOG_DEBUG:
> + level = ANDROID_LOG_DEBUG;
> + break;
> + default:
> + level = ANDROID_LOG_INFO;
> + }
> +
> + return __android_log_print(level, "libav", "%s", line);
> +}
> +
> +#elif HAVE_SYSLOG_H
> +
> +static void syslog_print(int level, const char *line)
> +{
> + switch(level) {
> + case AV_LOG_PANIC:
> + level = LOG_EMERG;
> + break;
> + case AV_LOG_FATAL:
> + level = LOG_CRIT;
> + break;
> + case AV_LOG_ERROR:
> + level = LOG_ERR;
> + break;
> + case AV_LOG_WARNING:
> + level = LOG_WARNING;
> + break;
> + case AV_LOG_INFO:
> + level = LOG_NOTICE;
> + break;
> + case AV_LOG_VERBOSE:
> + level = LOG_INFO;
> + break;
> + case AV_LOG_DEBUG:
> + level = LOG_DEBUG;
> + break;
> + default:
> + level = LOG_INFO;
> + }
> +
> + syslog(level, "%s", line);
> +}
> +
> +#else
> +static void (*syslog_print)(int, const char *) = default_print;
> +#endif
> +
> +static void log_format(void *avcl, int level, const char *fmt, va_list vl,
> + void (*print)(int level, const char *line))
> +{
> + char line[LINE_SIZE];
> + AVClass* avc = avcl ? *(AVClass **) avcl : NULL;
> +
> level &= 0xff;
>
> if (level > av_log_level)
> @@ -142,26 +252,20 @@ void av_log_default_callback(void *avcl, int level,
> const char *fmt, va_list vl)
>
> print_prefix = strlen(line) && line[strlen(line) - 1] == '\n';
>
> -#if HAVE_ISATTY
> - if (!is_atty)
> - is_atty = isatty(2) ? 1 : -1;
> -#endif
> + print(level, line);
> +}
>
> - if (print_prefix && (flags & AV_LOG_SKIP_REPEATED) &&
> - !strncmp(line, prev, sizeof line)) {
> - count++;
> - if (is_atty == 1)
> - fprintf(stderr, " Last message repeated %d times\r", count);
> - return;
> - }
> - if (count > 0) {
> - fprintf(stderr, " Last message repeated %d times\n", count);
> - count = 0;
> - }
> - colored_fputs(av_clip(level >> 3, 0, 6), tint >> 8, line);
> - av_strlcpy(prev, line, sizeof line);
> +void av_log_default_callback(void *avcl, int level, const char *fmt, va_list
> vl)
> +{
> + log_format(avcl, level, fmt, vl, default_print);
> }
>
> +void av_log_syslog_callback(void *avcl, int level, const char *fmt, va_list
> vl)
> +{
> + log_format(avcl, level, fmt, vl, syslog_print);
> +}
> +
> +
> static void (*av_log_callback)(void*, int, const char*, va_list) =
> av_log_default_callback;
>
> diff --git a/libavutil/log.h b/libavutil/log.h
> index 4e4424a..4bab6a0 100644
> --- a/libavutil/log.h
> +++ b/libavutil/log.h
> @@ -235,6 +235,20 @@ void av_log_default_callback(void *avcl, int level,
> const char *fmt,
> va_list vl);
>
> /**
> + * Syslog logging callback
> + *
> + * @param avcl A pointer to an arbitrary struct of which the first field is a
> + * pointer to an AVClass struct.
> + * @param level The importance level of the message expressed using a @ref
> + * lavu_log_constants "Logging Constant".
> + * @param fmt The format string (printf-compatible) that specifies how
> + * subsequent arguments are converted to output.
> + * @param vl The arguments referenced by the format string.
> + */
> +void av_log_syslog_callback(void *avcl, int level, const char *fmt,
> + va_list vl);
> +
> +/**
> * Return the context name
> *
> * @param ctx The AVClass context
>
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel