link_log.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*----------------------------------------------------------------------------
  2. * Copyright (c) <2018>, <Huawei Technologies Co., Ltd>
  3. * All rights reserved.
  4. * Redistribution and use in source and binary forms, with or without modification,
  5. * are permitted provided that the following conditions are met:
  6. * 1. Redistributions of source code must retain the above copyright notice, this list of
  7. * conditions and the following disclaimer.
  8. * 2. Redistributions in binary form must reproduce the above copyright notice, this list
  9. * of conditions and the following disclaimer in the documentation and/or other materials
  10. * provided with the distribution.
  11. * 3. Neither the name of the copyright holder nor the names of its contributors may be used
  12. * to endorse or promote products derived from this software without specific prior written
  13. * permission.
  14. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  15. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  16. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  21. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  22. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  23. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  24. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. *---------------------------------------------------------------------------*/
  26. /*----------------------------------------------------------------------------
  27. * Notice of Export Control Law
  28. * ===============================================
  29. * Huawei LiteOS may be subject to applicable export control laws and regulations, which might
  30. * include those applicable to Huawei LiteOS of U.S. and the country in which you are located.
  31. * Import, export and usage of Huawei LiteOS in any manner by you shall be in compliance with such
  32. * applicable export control laws and regulations.
  33. *---------------------------------------------------------------------------*/
  34. /**
  35. * DATE AUTHOR INSTRUCTION
  36. * 2019-12-19 14:34 zhangqianfu The first version
  37. *
  38. */
  39. #include <string.h>
  40. #include <stdio.h>
  41. #include <link_log.h>
  42. static en_link_log_level_t s_link_log_level = EN_LINK_LOG_LEVEL_TRACE;
  43. static const char *s_link_log_names[] =
  44. {
  45. "TRACE",
  46. "DEBUG",
  47. "INFO ",
  48. "WARN ",
  49. "ERROR",
  50. "FATAL"
  51. };
  52. int link_log_level_set(en_link_log_level_t level)
  53. {
  54. int ret = -1;
  55. if(level < EN_LINK_LOG_LEVEL_MAX )
  56. {
  57. s_link_log_level = level;
  58. ret = 0;
  59. }
  60. return ret;
  61. }
  62. en_link_log_level_t link_log_level_get(void)
  63. {
  64. return s_link_log_level;
  65. }
  66. const char *link_log_level_name(en_link_log_level_t log_level)
  67. {
  68. if (log_level >= EN_LINK_LOG_LEVEL_MAX)
  69. {
  70. return "NULL ";
  71. }
  72. else
  73. {
  74. return s_link_log_names[log_level];
  75. }
  76. }
  77. /*
  78. #ifndef CONFIG_LINK_LOGBUF_LEN
  79. #define CONFIG_LINK_LOGBUF_LEN 256 ///< you could modify it
  80. #endif
  81. __attribute__((weak)) void link_printf(const char *format, ...)
  82. {
  83. char str_buf[CONFIG_LINK_LOGBUF_LEN] = {0};
  84. va_list list;
  85. (void) (void) memset(str_buf, 0, CONFIG_LINK_LOGBUF_LEN);
  86. va_start(list, format);
  87. (void) vsnprintf(str_buf, sizeof(str_buf), format, list);
  88. va_end(list);
  89. (void) printf("%s", str_buf);
  90. return;
  91. }
  92. */