Initial commit
[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(U8 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(U32 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(U32 modMask);
72
73 ///////////////////////////////////////////////////////////////////////////////
74 // This API is used to set log file size limit for single file.
75 void rlSetLogFileSizeLimit(U32 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(U8 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(U32 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 extern void rlUpdateRlogTti(void);
110
111 ///////////////////////////////////////////////////////////////////////////////
112 // This API reset the RLOG rate control count and enable logging every 10 ms 
113 extern void rlResetLogRateLmt(void);
114
115 ///////////////////////////////////////////////////////////////////////////////
116 // This API reset the RLOG rate control count and enable logging every 10 ms
117 extern void rlResetLogRateLmt(void);
118
119 ///////////////////////////////////////////////////////////////////////////////
120 // This API Start the limit the number of logs loggd into circular buffer every
121 // 10ms
122 extern void rlStartLogCountLimit(void);
123
124 ///////////////////////////////////////////////////////////////////////////////
125 // This API stops restriciton of limiting number of logs every 10 ms
126 extern void rlStopLogCountLimit(void);
127
128
129 #ifdef WR_DBG_CIRLOG
130
131 #include "rl_redirect.h"
132
133 #else
134
135 #define FMTSTR "[%d-%d-%d %d:%d:%d.%03d][%s]%s:%d\n%s:"
136 #define FMTSTR_S "[%d-%d-%d %d:%d:%d.%03d][%s]%s:%d\n%s:%s:%ld:"
137
138 #define LOG_ARG0(_level, _fmtStr) \
139 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
140 { \
141         logLev0(g_logStr[_level],RLOG_MODULE_NAME, __FILE__,__LINE__, FMTSTR _fmtStr "\n\n", RLOG_FILE_ID); \
142 }
143
144 #define LOG_ARGN(_N, _level, _fmtStr, ...) \
145 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
146 { \
147         logLev##_N(g_logStr[_level],RLOG_MODULE_NAME, __FILE__,__LINE__, FMTSTR _fmtStr "\n\n", ##__VA_ARGS__ , RLOG_FILE_ID); \
148 }
149
150 #define LOG_SPL(_level, _splenum, _splArg, _fmtStr, ...) \
151 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
152 { \
153         logLevE(g_logStr[_level],RLOG_MODULE_NAME, __FILE__,__LINE__, FMTSTR_S _fmtStr "\n\n", _splenum,_splArg, ##__VA_ARGS__, RLOG_FILE_ID); \
154 }
155
156 #define LOG_ARGX(_level, _fmtStr, ...) \
157 if( _level < g_logLevel || g_modMask & RLOG_MODULE_ID)\
158 { \
159         logLevN(_level,RLOG_MODULE_NAME, __FILE__,__LINE__, _fmtStr "\n\n", __VA_ARGS__, RLOG_FILE_ID); \
160
161
162 #define RLOG0(_level, _lstr)                            LOG_ARG0(_level, _lstr)
163 #define RLOG1(_level, _lstr, _arg1)                     LOG_ARGN(1, _level, _lstr, _arg1)
164 #define RLOG2(_level, _lstr, _arg1, _arg2)              LOG_ARGN(2, _level, _lstr, _arg1, _arg2)
165 #define RLOG3(_level, _lstr, _arg1, _arg2, _arg3)       LOG_ARGN(3, _level, _lstr, _arg1, _arg2, _arg3)
166 #define RLOG4(_level, _lstr, _arg1, _arg2, _arg3, _arg4)LOG_ARGN(4, _level, _lstr, _arg1, _arg2, _arg3, _arg4)
167
168
169 #define RLOG_STR(_level, _lstr, _strarg)                                        LOG_ARGN(S, _level, _lstr, _strarg)
170 #define RLOG_HEX(_level, _lstr, _hexdata, _hexlen)              LOG_ARGN(H, _level, _lstr, _hexdata, _hexlen)
171
172 #define RLOG_ARG0(_level, _splenum, _splArg, _lstr) \
173                 LOG_SPL(_level, _splenum, _splArg, _lstr, 0, 0, 0, 0)
174
175 #define RLOG_ARG1(_level, _splenum, _splArg, _lstr, _arg1) \
176                 LOG_SPL(_level, _splenum, _splArg, _lstr, _arg1, 0, 0, 0)
177
178 #define RLOG_ARG2(_level, _splenum, _splArg, _lstr, _arg1, _arg2) \
179                 LOG_SPL(_level, _splenum, _splArg, _lstr, _arg1, _arg2, 0, 0)
180
181 #define RLOG_ARG3(_level, _splenum, _splArg, _lstr, _arg1, _arg2, _arg3) \
182                 LOG_SPL(_level, _splenum, _splArg, _lstr, _arg1, _arg2, _arg3, 0)
183
184 #define RLOG_ARG4(_level, _splenum, _splArg, _lstr, _arg1, _arg2, _arg3, _arg4) \
185                 LOG_SPL(_level, _splenum, _splArg, _lstr, _arg1, _arg2, _arg3, _arg4)
186
187 #endif /* WR_DBG_CIRLOG */
188 #endif /* __RLOG_INTERFACE_H__*/