libxcoder  5.2.0
ni_log.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (C) 2022 NETINT Technologies
4  *
5  * Permission is hereby granted, free of charge, to any person obtaining a copy
6  * of this software and associated documentation files (the "Software"), to deal
7  * in the Software without restriction, including without limitation the rights
8  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9  * copies of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18  * SOFTWARE.
19  *
20  ******************************************************************************/
21 
22 /*!*****************************************************************************
23  * \file ni_log.h
24  *
25  * \brief Logging definitions
26  ******************************************************************************/
27 
28 #pragma once
29 
30 #include <stdarg.h>
31 #include <stdint.h>
32 
33 #ifdef LIBXCODER_OBJS_BUILD
34 #include "../build/xcoder_auto_headers.h"
35 #endif
36 
37 #ifdef _WIN32
38  #ifdef XCODER_DLL
39  #ifdef LIB_EXPORTS
40  #define LIB_API_LOG __declspec(dllexport)
41  #else
42  #define LIB_API_LOG __declspec(dllimport)
43  #endif
44  #else
45  #define LIB_API_LOG
46  #endif
47 #elif __linux__ || __APPLE__
48  #define LIB_API_LOG
49 #endif
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 typedef enum
56 {
57  NI_LOG_INVALID = -1, // invalid selection
58  NI_LOG_NONE = 0, // display no logging
59  NI_LOG_FATAL = 1, // log messages immediately prior to program exit
60  NI_LOG_ERROR = 2, // error messages
61  NI_LOG_INFO = 3, // info and warning messages
62  NI_LOG_DEBUG = 4, // very verbose messages about program execution
63  NI_LOG_TRACE = 5 // most verbose messages (eg. function enter/exit, NVMe
64  // transactions, read/write polling retries)
66 
67 /*!*************************************/
68 // libxcoder logging utility
69 /*!*****************************************************************************
70  * \brief Default ni_log() callback
71  *
72  * \param[in] level log level
73  * \param[in] fmt printf format specifier
74  * \param[in] vl variadric args list
75  *
76  * \return
77  ******************************************************************************/
78 LIB_API_LOG void ni_log_default_callback(int level, const char* fmt,
79  va_list vl);
80 
81 /*!*****************************************************************************
82  * \brief Set ni_log() callback
83  *
84  * \param[in] callback
85  *
86  * \return
87  ******************************************************************************/
88 LIB_API_LOG void ni_log_set_callback(void (*log_callback)(int, const char*,
89  va_list));
90 
91 /*!*****************************************************************************
92  * \brief print log message using ni_log_callback
93  *
94  * \param[in] level log level
95  * \param[in] format printf format specifier
96  * \param[in] ... additional arguments
97  *
98  * \return
99  ******************************************************************************/
100 LIB_API_LOG void ni_log(ni_log_level_t level, const char *fmt, ...);
101 
102 /*!*****************************************************************************
103  * \brief Set ni_log_level
104  *
105  * \param level log level
106  *
107  * \return
108  ******************************************************************************/
109 LIB_API_LOG void ni_log_set_level(ni_log_level_t level);
110 
111 /*!*****************************************************************************
112  * \brief Get ni_log_level
113  *
114  * \return ni_log_level
115  ******************************************************************************/
116 LIB_API_LOG ni_log_level_t ni_log_get_level(void);
117 
118 /*!*****************************************************************************
119  * \brief Convert ffmpeg log level integer to appropriate ni_log_level_t
120  *
121  * \param fflog_level integer representation of FFmpeg log level
122  *
123  * \return ni_log_level
124  ******************************************************************************/
125 LIB_API_LOG ni_log_level_t ff_to_ni_log_level(int fflog_level);
126 
127 /*!*****************************************************************************
128  * \brief Convert terminal arg string to ni_log_level_t
129  *
130  * \param log_str character pointer of log level arg in terminal
131  *
132  * \return ni_log_level
133  ******************************************************************************/
134 LIB_API_LOG ni_log_level_t arg_to_ni_log_level(const char *fflog_level);
135 
136 /*!*****************************************************************************
137  * \brief Get time for logs with microsecond timestamps
138  *
139  *
140  * \return microsecond timestamp
141  ******************************************************************************/
142 LIB_API_LOG uint64_t ni_log_get_utime();
143 
144 /*!*****************************************************************************
145  * \brief print log message and additional information using ni_log_callback,
146  * \param[in] p_context a pointer to ni_session_context_t if p_context != NULL
147  * session_id/E2EID will be printed as extra information
148  * \param[in] level log level, if log_level == NI_LOG_ERROR timastamp will be
149  * printed as extra information
150  * \param[in] format printf format specifier
151  * \param[in] ... additional arguments
152  *
153  * \return
154  ******************************************************************************/
155 LIB_API_LOG void ni_log2(const void *p_context, ni_log_level_t level, const char *fmt, ...);
156 
157 /*!*****************************************************************************
158  * \brief set whether to use a lock or not in ni_log2
159  *
160  * \param[in] on whether to use a lock,
161  * 1-->use a lock,
162  * 0-->use extra buf(no lock)
163  * \return
164  ******************************************************************************/
165 void ni_log2_with_mutex(int on);
166 
167 #ifdef _ANDROID
168 /*!******************************************************************************
169  * \brief Set ni_log_tag
170  *
171  * \param log tag
172  *
173  * \return
174  *******************************************************************************/
175 LIB_API_LOG void ni_log_set_log_tag(const char *log_tag);
176 #endif
177 
178 #ifdef __cplusplus
179 }
180 #endif
NI_LOG_FATAL
@ NI_LOG_FATAL
Definition: ni_log.h:59
ni_log_level_t
ni_log_level_t
Definition: ni_log.h:55
ni_log_set_level
LIB_API_LOG void ni_log_set_level(ni_log_level_t level)
Set ni_log_level.
Definition: ni_log.c:202
ff_to_ni_log_level
LIB_API_LOG ni_log_level_t ff_to_ni_log_level(int fflog_level)
Convert ffmpeg log level integer to appropriate ni_log_level_t.
Definition: ni_log.c:224
ni_log2_with_mutex
void ni_log2_with_mutex(int on)
set whether to use a lock or not in ni_log2
Definition: ni_log.c:326
ni_log_default_callback
LIB_API_LOG void ni_log_default_callback(int level, const char *fmt, va_list vl)
Default ni_log() callback.
Definition: ni_log.c:134
ni_log2
LIB_API_LOG void ni_log2(const void *p_context, ni_log_level_t level, const char *fmt,...)
print log message and additional information using ni_log_callback,
Definition: ni_log.c:337
ni_log_get_utime
LIB_API_LOG uint64_t ni_log_get_utime()
Get time for logs with microsecond timestamps.
Definition: ni_log.c:308
NI_LOG_INFO
@ NI_LOG_INFO
Definition: ni_log.h:61
NI_LOG_ERROR
@ NI_LOG_ERROR
Definition: ni_log.h:60
NI_LOG_TRACE
@ NI_LOG_TRACE
Definition: ni_log.h:63
NI_LOG_INVALID
@ NI_LOG_INVALID
Definition: ni_log.h:57
ni_log_get_level
LIB_API_LOG ni_log_level_t ni_log_get_level(void)
Get ni_log_level.
Definition: ni_log.c:212
ni_log_set_callback
LIB_API_LOG void ni_log_set_callback(void(*log_callback)(int, const char *, va_list))
Set ni_log() callback.
Definition: ni_log.c:169
arg_to_ni_log_level
LIB_API_LOG ni_log_level_t arg_to_ni_log_level(const char *fflog_level)
Convert terminal arg string to ni_log_level_t.
Definition: ni_log.c:262
ni_log
LIB_API_LOG void ni_log(ni_log_level_t level, const char *fmt,...)
print log message using ni_log_callback
Definition: ni_log.c:183
NI_LOG_NONE
@ NI_LOG_NONE
Definition: ni_log.h:58
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:62