libxcoder  5.4.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 #define NI_ERRNO_LEN 256
52 
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56 
57 typedef enum
58 {
59  NI_LOG_INVALID = -1, // invalid selection
60  NI_LOG_NONE = 0, // display no logging
61  NI_LOG_FATAL = 1, // log messages immediately prior to program exit
62  NI_LOG_ERROR = 2, // error messages
63  NI_LOG_INFO = 3, // info and warning messages
64  NI_LOG_DEBUG = 4, // very verbose messages about program execution
65  NI_LOG_TRACE = 5 // most verbose messages (eg. function enter/exit, NVMe
66  // transactions, read/write polling retries)
68 
69 /*!*************************************/
70 // libxcoder logging utility
71 /*!*****************************************************************************
72  * \brief Default ni_log() callback
73  *
74  * \param[in] level log level
75  * \param[in] fmt printf format specifier
76  * \param[in] vl variadric args list
77  *
78  * \return
79  ******************************************************************************/
80 LIB_API_LOG void ni_log_default_callback(int level, const char* fmt,
81  va_list vl);
82 
83 /*!*****************************************************************************
84  * \brief Set ni_log() callback
85  *
86  * \param[in] callback
87  *
88  * \return
89  ******************************************************************************/
90 LIB_API_LOG void ni_log_set_callback(void (*log_callback)(int, const char*,
91  va_list));
92 
93 /*!*****************************************************************************
94  * \brief print log message using ni_log_callback
95  *
96  * \param[in] level log level
97  * \param[in] format printf format specifier
98  * \param[in] ... additional arguments
99  *
100  * \return
101  ******************************************************************************/
102 LIB_API_LOG void ni_log(ni_log_level_t level, const char *fmt, ...);
103 
104 /*!*****************************************************************************
105  * \brief Set ni_log_level
106  *
107  * \param level log level
108  *
109  * \return
110  ******************************************************************************/
111 LIB_API_LOG void ni_log_set_level(ni_log_level_t level);
112 
113 /*!*****************************************************************************
114  * \brief Get ni_log_level
115  *
116  * \return ni_log_level
117  ******************************************************************************/
118 LIB_API_LOG ni_log_level_t ni_log_get_level(void);
119 
120 /*!*****************************************************************************
121  * \brief Convert ffmpeg log level integer to appropriate ni_log_level_t
122  *
123  * \param fflog_level integer representation of FFmpeg log level
124  *
125  * \return ni_log_level
126  ******************************************************************************/
127 LIB_API_LOG ni_log_level_t ff_to_ni_log_level(int fflog_level);
128 
129 /*!*****************************************************************************
130  * \brief Convert terminal arg string to ni_log_level_t
131  *
132  * \param log_str character pointer of log level arg in terminal
133  *
134  * \return ni_log_level
135  ******************************************************************************/
136 LIB_API_LOG ni_log_level_t arg_to_ni_log_level(const char *fflog_level);
137 
138 /*!*****************************************************************************
139  * \brief Get time for logs with microsecond timestamps
140  *
141  *
142  * \return microsecond timestamp
143  ******************************************************************************/
144 LIB_API_LOG uint64_t ni_log_get_utime();
145 
146 /*!*****************************************************************************
147  * \brief print log message and additional information using ni_log_callback,
148  * \param[in] p_context a pointer to ni_session_context_t if p_context != NULL
149  * session_id/E2EID will be printed as extra information
150  * \param[in] level log level, if log_level == NI_LOG_ERROR timastamp will be
151  * printed as extra information
152  * \param[in] format printf format specifier
153  * \param[in] ... additional arguments
154  *
155  * \return
156  ******************************************************************************/
157 LIB_API_LOG void ni_log2(const void *p_context, ni_log_level_t level, const char *fmt, ...);
158 
159 /*!*****************************************************************************
160  * \brief set whether to use a lock or not in ni_log2
161  *
162  * \param[in] on whether to use a lock,
163  * 1-->use a lock,
164  * 0-->use extra buf(no lock)
165  * \return
166  ******************************************************************************/
167 void ni_log2_with_mutex(int on);
168 
169 #ifdef _ANDROID
170 /*!******************************************************************************
171  * \brief Set ni_log_tag
172  *
173  * \param log tag
174  *
175  * \return
176  *******************************************************************************/
177 LIB_API_LOG void ni_log_set_log_tag(const char *log_tag);
178 #endif
179 
180 #ifdef __cplusplus
181 }
182 #endif
NI_LOG_FATAL
@ NI_LOG_FATAL
Definition: ni_log.h:61
ni_log_level_t
ni_log_level_t
Definition: ni_log.h:57
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:63
NI_LOG_ERROR
@ NI_LOG_ERROR
Definition: ni_log.h:62
NI_LOG_TRACE
@ NI_LOG_TRACE
Definition: ni_log.h:65
NI_LOG_INVALID
@ NI_LOG_INVALID
Definition: ni_log.h:59
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:60
NI_LOG_DEBUG
@ NI_LOG_DEBUG
Definition: ni_log.h:64