You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
1.9KB

  1. /*
  2. * log functions
  3. * Copyright (c) 2003 Michel Bardiaux
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. */
  19. /**
  20. * @file log.c
  21. * log.
  22. */
  23. #include "avutil.h"
  24. static int av_log_level = AV_LOG_INFO;
  25. static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
  26. {
  27. static int print_prefix=1;
  28. AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
  29. if(level>av_log_level)
  30. return;
  31. #undef fprintf
  32. if(print_prefix && avc) {
  33. fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);
  34. }
  35. #define fprintf please_use_av_log
  36. print_prefix= strstr(fmt, "\n") != NULL;
  37. vfprintf(stderr, fmt, vl);
  38. }
  39. static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
  40. void av_log(void* avcl, int level, const char *fmt, ...)
  41. {
  42. va_list vl;
  43. va_start(vl, fmt);
  44. av_vlog(avcl, level, fmt, vl);
  45. va_end(vl);
  46. }
  47. void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
  48. {
  49. av_log_callback(avcl, level, fmt, vl);
  50. }
  51. int av_log_get_level(void)
  52. {
  53. return av_log_level;
  54. }
  55. void av_log_set_level(int level)
  56. {
  57. av_log_level = level;
  58. }
  59. void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
  60. {
  61. av_log_callback = callback;
  62. }