51e0ab6c8c7b74562fd4b6580be8443fdec86a9e
[o-du/l2.git] / src / rlog / rl_interface.h
1 /*******************************************************************************
2 ################################################################################
3 #   Copyright (c) [2017-2019] [Radisys]                                        #
4 #                                                                              #
5 #   Licensed under the Apache License, Version 2.0 (the "License");            #
6 #   you may not use this file except in compliance with the License.           #
7 #   You may obtain a copy of the License at                                    #
8 #                                                                              #
9 #       http://www.apache.org/licenses/LICENSE-2.0                             #
10 #                                                                              #
11 #   Unless required by applicable law or agreed to in writing, software        #
12 #   distributed under the License is distributed on an "AS IS" BASIS,          #
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
14 #   See the License for the specific language governing permissions and        #
15 #   limitations under the License.                                             #
16 ################################################################################
17 *******************************************************************************/
18
19 /********************************************************************20**
20
21      Name:     Radisys Logging Framework
22      Type:     C include file
23      Desc:     This file contains logging framework include file.
24      File:     rl_interface.h
25 *********************************************************************21*/
26 ///////////////////////////////////////////////////////////////////////////////
27 // @ description: This is header file is used by applications who want to 
28 // define LOG Macros. This file can be refered for integrating log library
29 // into any application. API's defined in the file should be used by the 
30 // program to modify data at runtime.
31 ///////////////////////////////////////////////////////////////////////////////
32
33 #ifndef __RL_INTERFACE_H__
34
35 #include "rl_common.h"
36
37 ///////////////////////////////////////////////////////////////////////////////
38 // This API is used to set logging directory path. If set after the log 
39 // initialization API, next file creation will happen in this directory
40 void rlSetLogPath(const char* logDir);
41
42 ///////////////////////////////////////////////////////////////////////////////
43 // This API needs to be called after configuring all the required parameters 
44 // by using below APIs. This API initializes logging framework.  
45 // Log MACRO's should be used  only after calling this API.
46 void rlInitLog(uint8_t type); 
47
48 ///////////////////////////////////////////////////////////////////////////////
49 // This initializes log file name.  Log file name should be exclusive of 
50 // extension. As framework appends ".bin" in case of binary file and ".txt" in 
51 // case of plain text logging. If file name is "stdout" and TEXT logging is 
52 // enabled, logs will be printed in console. Run time file name can be changed 
53 // and will be applicable when next file is created.
54 void rlSetLogFile(const char* fileName);
55
56 ///////////////////////////////////////////////////////////////////////////////
57 // This API is used to set remote logging port, where post-processor application 
58 // (rlogapp) is used to connect on this port in order to receive live binary logs. 
59 // This API can be used only during initialization time.
60 void rlSetLogPort(uint32_t port);
61
62 ///////////////////////////////////////////////////////////////////////////////
63 // Use this API to set log level. This API supports run time modification of
64 // log level.
65 void rlSetLogLevel(R_LOG_LEVEL logLevel);
66
67 ///////////////////////////////////////////////////////////////////////////////
68 // This API toggles the module mask. If logging for this module is already 
69 // enabled, it will be disabled. If it's not enabled, it will enable. Zero 
70 // input will disable logging mask for all modules.
71 void rlSetModuleMask(uint32_t modMask);
72
73 ///////////////////////////////////////////////////////////////////////////////
74 // This API is used to set log file size limit for single file.
75 void rlSetLogFileSizeLimit(uint32_t maxFileSize);
76
77 ///////////////////////////////////////////////////////////////////////////////
78 // This API sets the limit of number of log files  that can be created by 
79 // logging framework.
80 void rlSetNumOfLogFiles(uint8_t nMaxFiles);
81
82 ///////////////////////////////////////////////////////////////////////////////
83 // This API is used to set circular buffer size for each thread. Based on the 
84 // number of threads in the system this size needs to be chosen. Recommended 
85 // minimum 100Kb buffer size.
86 void rlSetCircularBufferSize(uint32_t bufSize);
87
88 ///////////////////////////////////////////////////////////////////////////////
89 // This API enables or disables remote logging application connection to see 
90 // live binary logs.
91 void rlSetRemoteLoggingFlag(S32 flag);
92
93 ///////////////////////////////////////////////////////////////////////////////
94 // To change or modify logging level using console, console input needs to be 
95 // passed to this function.
96 int rlHandleConInput(char ch);
97
98 ///////////////////////////////////////////////////////////////////////////////
99 // This API enables or disables core file generation based on the input flag 
100 // value. 1 Enables core dump and 0 disables generating core dump.
101 void rlEnableDisableCore(S32 enable_core);
102
103 ///////////////////////////////////////////////////////////////////////////////
104 // This API enables Bufferd IO, to disable frequent file operation
105 void rlEnaBleBufferedIO(void);
106
107 ///////////////////////////////////////////////////////////////////////////////
108 // This API updates the RLOG Tti count baed on this time stamp will be updated 
109 void rlUpdateRlogTti(void);
110
111 ///////////////////////////////////////////////////////////////////////////////
112 // This API reset the RLOG rate control count and enable logging every 10 ms 
113 void rlResetLogRateLmt(void);
114
115 ///////////////////////////////////////////////////////////////////////////////
116 // This API reset the RLOG rate control count and enable logging every 10 ms
117 void rlResetLogRateLmt(void);
118
119 ///////////////////////////////////////////////////////////////////////////////
120 // This API Start the limit the number of logs loggd into circular buffer every
121 // 10ms
122 void rlStartLogCountLimit(void);
123
124 ///////////////////////////////////////////////////////////////////////////////
125 // This API stops restriciton of limiting number of logs every 10 ms
126 void rlStopLogCountLimit(void);
127
128
129 #ifdef WR_DBG_CIRLOG
130
131 #include "rl_redirect.h"
132
133 #else
134
135 #if defined(RLOG_ENABLE_TEXT_LOGGING) 
136
137 #define FMTSTR "[%d-%d-%d %d:%d:%d.%03d][%s]%s:%d\n%s:"
138 #define FMTSTR_S "[%d-%d-%d %d:%d:%d.%03d][%s]%s:%d\n%s:%s:%ld:"
139
140 #define LOG_ARG0(_level, _fmtStr) \
141 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
142 { \
143         logLev0(g_logStr[_level],RLOG_MODULE_NAME, __FILE__,__LINE__, FMTSTR _fmtStr "\n\n", RLOG_FILE_ID); \
144 }
145
146 #define LOG_ARGN(_N, _level, _fmtStr, ...) \
147 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
148 { \
149         logLev##_N(g_logStr[_level],RLOG_MODULE_NAME, __FILE__,__LINE__, FMTSTR _fmtStr "\n\n", ##__VA_ARGS__ , RLOG_FILE_ID); \
150 }
151
152 #define LOG_SPL(_level, _splenum, _splArg, _fmtStr, ...) \
153 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
154 { \
155         logLevE(g_logStr[_level],RLOG_MODULE_NAME, __FILE__,__LINE__, FMTSTR_S _fmtStr "\n\n", _splenum,_splArg, ##__VA_ARGS__, RLOG_FILE_ID); \
156 }
157
158 #define LOG_ARGX(_level, _fmtStr, ...) \
159 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
160 { \
161         logLevN(_level,RLOG_MODULE_NAME, __FILE__,__LINE__, _fmtStr "\n\n", __VA_ARGS__, RLOG_FILE_ID); \
162
163
164 #define RLOG0(_level, _lstr)                            LOG_ARG0(_level, _lstr)
165 #define RLOG1(_level, _lstr, _arg1)                     LOG_ARGN(1, _level, _lstr, _arg1)
166 #define RLOG2(_level, _lstr, _arg1, _arg2)              LOG_ARGN(2, _level, _lstr, _arg1, _arg2)
167 #define RLOG3(_level, _lstr, _arg1, _arg2, _arg3)       LOG_ARGN(3, _level, _lstr, _arg1, _arg2, _arg3)
168 #define RLOG4(_level, _lstr, _arg1, _arg2, _arg3, _arg4)LOG_ARGN(4, _level, _lstr, _arg1, _arg2, _arg3, _arg4)
169
170 #else /* BINARY LOGGING */
171
172 #define LOG_ARG0(_level, _fmtStr) \
173 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
174 { \
175         logLev0(_LOGID, _level, __FILE__,__LINE__, _fmtStr, RLOG_FILE_ID, RLOG_MODULE_NAME); \
176 }
177
178 #define LOG_ARGN(_N, _level, _fmtStr, ...) \
179 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
180 { \
181         logLev##_N(_LOGID, _level, ##__VA_ARGS__, __FILE__,__LINE__, _fmtStr, RLOG_FILE_ID, RLOG_MODULE_NAME); \
182 }
183
184 #define LOG_SPL(_level, _splenum, _splArg, _fmtStr, ...) \
185 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
186 { \
187         logLevE(_LOGID,_level,_splenum, _splArg, ##__VA_ARGS__, __FILE__,__LINE__, _fmtStr, RLOG_FILE_ID, RLOG_MODULE_NAME); \
188 }
189
190 #define RLOG0(_level, _lstr)                            LOG_ARG0(_level, _lstr)
191 #define RLOG1(_level, _lstr, _arg1)                     LOG_ARGN(1, _level, _lstr, _arg1)
192 #define RLOG2(_level, _lstr, _arg1, _arg2)              LOG_ARGN(2, _level, _lstr, _arg1, _arg2)
193 #define RLOG3(_level, _lstr, _arg1, _arg2, _arg3)       LOG_ARGN(3, _level, _lstr, _arg1, _arg2, _arg3)
194 #define RLOG4(_level, _lstr, _arg1, _arg2, _arg3, _arg4)LOG_ARGN(4, _level, _lstr, _arg1, _arg2, _arg3, _arg4)
195
196 #endif /* if defined(RLOG_ENABLE_TEXT_LOGGING) */
197
198 #define RLOG_STR(_level, _lstr, _strarg)                                        LOG_ARGN(S, _level, _lstr, _strarg)
199 #define RLOG_HEX(_level, _lstr, _hexdata, _hexlen)              LOG_ARGN(H, _level, _lstr, _hexdata, _hexlen)
200
201 #define RLOG_ARG0(_level, _splenum, _splArg, _lstr) \
202                 LOG_SPL(_level, _splenum, _splArg, _lstr, 0, 0, 0, 0)
203
204 #define RLOG_ARG1(_level, _splenum, _splArg, _lstr, _arg1) \
205                 LOG_SPL(_level, _splenum, _splArg, _lstr, _arg1, 0, 0, 0)
206
207 #define RLOG_ARG2(_level, _splenum, _splArg, _lstr, _arg1, _arg2) \
208                 LOG_SPL(_level, _splenum, _splArg, _lstr, _arg1, _arg2, 0, 0)
209
210 #define RLOG_ARG3(_level, _splenum, _splArg, _lstr, _arg1, _arg2, _arg3) \
211                 LOG_SPL(_level, _splenum, _splArg, _lstr, _arg1, _arg2, _arg3, 0)
212
213 #define RLOG_ARG4(_level, _splenum, _splArg, _lstr, _arg1, _arg2, _arg3, _arg4) \
214                 LOG_SPL(_level, _splenum, _splArg, _lstr, _arg1, _arg2, _arg3, _arg4)
215
216 #endif /* WR_DBG_CIRLOG */
217 #endif /* __RLOG_INTERFACE_H__*/