log.h 10.1 KB
Newer Older
1
/*******************************************************************************
nikaeinn's avatar
nikaeinn committed
2
3
    OpenAirInterface
    Copyright(c) 1999 - 2014 Eurecom
4

nikaeinn's avatar
nikaeinn committed
5
6
7
8
    OpenAirInterface is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
9
10


nikaeinn's avatar
nikaeinn committed
11
12
13
14
    OpenAirInterface is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
15

nikaeinn's avatar
nikaeinn committed
16
17
18
19
    You should have received a copy of the GNU General Public License
    along with OpenAirInterface.The full GNU General Public License is
    included in this distribution in the file called "COPYING". If not,
    see <http://www.gnu.org/licenses/>.
20
21

  Contact Information
nikaeinn's avatar
nikaeinn committed
22
23
24
25
  OpenAirInterface Admin: openair_admin@eurecom.fr
  OpenAirInterface Tech : openair_tech@eurecom.fr
  OpenAirInterface Dev  : openair4g-devel@eurecom.fr

ghaddab's avatar
ghaddab committed
26
  Address      : Eurecom, Campus SophiaTech, 450 Route des Chappes, CS 50193 - 06904 Biot Sophia Antipolis cedex, FRANCE
27
28
29
30
31
32

*******************************************************************************/

/*! \file log.h
* \brief openair log generator (OLG) for
* \author Navid Nikaein
nikaeinn's avatar
nikaeinn committed
33
* \date 2009 - 2014
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
* \version 0.5
* @ingroup util

*/

#ifndef __LOG_H__
#    define __LOG_H__

/*--- INCLUDES ---------------------------------------------------------------*/
#ifdef USER_MODE
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdarg.h>
#else
#include "rtai_fifos.h"
#endif

/*----------------------------------------------------------------------------*/

#ifdef __cplusplus
extern "C" {
#endif

/** @defgroup _LOG LOG Generator
 * @{*/
/* @}*/

/** @defgroup _macro Macro Definition
 *  @ingroup _LOG
 *  @brief these macros are used in the code of LOG
 * @{*/
/* @}*/

/** @defgroup _max_length Maximum Length of LOG
 *  @ingroup _macro
 *  @brief the macros that describe the maximum length of LOG
 * @{*/
78
#define MAX_LOG_ITEM 100 /*!< \brief the maximum length of a LOG item, what is LOG_ITEM ??? */
79
80
81
82
83
84
85
86
87
#define MAX_LOG_INFO 1000 /*!< \brief the maximum length of a log */
#define MAX_LOG_TOTAL 1500 /*!< \brief the maximum length of a log */
/* @}*/

/** @defgroup _log_level Message levels defined by LOG
 *  @ingroup _macro
 *  @brief LOG defines 9 levels of messages for users. Importance of these levels decrease gradually from 0 to 8
 * @{*/
#ifndef LOG_EMERG
88
# define  LOG_EMERG 0 /*!< \brief system is unusable */
89
90
#endif
#ifndef LOG_ALERT
91
# define  LOG_ALERT 1 /*!< \brief action must be taken immediately */
92
93
#endif
#ifndef LOG_CRIT
94
# define  LOG_CRIT  2 /*!< \brief critical conditions */
95
96
#endif
#ifndef LOG_ERR
97
# define  LOG_ERR   3 /*!< \brief error conditions */
98
99
#endif
#ifndef LOG_WARNING
100
# define  LOG_WARNING 4 /*!< \brief warning conditions */
101
102
#endif
#ifndef LOG_NOTICE
103
# define  LOG_NOTICE  5 /*!< \brief normal but significant condition */
104
105
#endif
#ifndef LOG_INFO
106
# define  LOG_INFO  6 /*!< \brief informational */
107
108
#endif
#ifndef LOG_DEBUG
109
# define  LOG_DEBUG 7 /*!< \brief debug-level messages */
110
111
#endif
#ifndef LOG_FILE
112
# define  LOG_FILE        8 /*!< \brief message sequence chart -level  */
113
114
#endif
#ifndef LOG_TRACE
115
# define  LOG_TRACE 9 /*!< \brief trace-level messages */
116
117
#endif

118
#define NUM_LOG_LEVEL  10 /*!< \brief the number of message levels users have with LOG */
119
120
121
122
123
124
125
126
/* @}*/


/** @defgroup _logIt logIt function
 *  @ingroup _macro
 *  @brief Macro used to call tr_log_full_ex with file, function and line information
 * @{*/
#ifdef USER_MODE
127
//#define logIt(component, level, format, args...) do {logRecord(__FILE__, __FUNCTION__, __LINE__, component, level, format, ##args);} while(0);
128
129
130
131
#ifdef LOG_NO_THREAD
#define logIt(component, level, format, args...) logRecord_mt(__FILE__, __FUNCTION__, __LINE__, component, level, format, ##args)
#else //default
#define logIt(component, level, format, args...) logRecord(__FILE__, __FUNCTION__, __LINE__, component, level, format, ##args)
132
#endif
133
134
135
#else
#ifdef LOG_NO_THREAD
#define logIt(component, level, format, args...) logRecord_mt(NULL, __FUNCTION__, __LINE__, component, level, format, ##args)
136
#else // default
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#define logIt(component, level, format, args...) logRecord(NULL, __FUNCTION__, __LINE__, component, level, format, ##args)
#endif
#endif
/* @}*/


/** @defgroup _debugging debugging macros
 *  @ingroup _macro
 *  @brief Macro used to call logIt function with different message levels
 * @{*/

// debugging macros
#ifdef USER_MODE
#define LOG_G(c, x...) logIt(c, LOG_EMERG, x)
#define LOG_A(c, x...) logIt(c, LOG_ALERT, x)
#define LOG_C(c, x...) logIt(c, LOG_CRIT,  x)
#define LOG_E(c, x...) logIt(c, LOG_ERR, x)
#define LOG_W(c, x...) logIt(c, LOG_WARNING, x)
#define LOG_N(c, x...) logIt(c, LOG_NOTICE, x)
#define LOG_I(c, x...) logIt(c, LOG_INFO, x)
#define LOG_D(c, x...) logIt(c, LOG_DEBUG, x)
#define LOG_F(c, x...) logIt(c, LOG_FILE, x)  // log to a file, useful for the MSC chart generation
#define LOG_T(c, x...) logIt(c, LOG_TRACE, x)
#else
#define LOG_G(c, x...) printk(x)
#define LOG_A(c, x...) printk(x)
#define LOG_C(c, x...) printk(x)
#define LOG_E(c, x...) printk(x)
#define LOG_W(c, x...) printk(x)
#define LOG_N(c, x...) printk(x)
#define LOG_I(c, x...) printk(x)
#define LOG_D(c, x...) printk(x)
#define LOG_T(c, x...) printk(x)
#endif
/* @}*/


/** @defgroup _useful_functions useful functions in LOG
 *  @ingroup _macro
 *  @brief Macro of some useful functions defined by LOG
 * @{*/
178
179
180
#define LOG_ENTER(c) do {LOG_T(c, "Entering\n");}while(0) /*!< \brief Macro to log a message with severity DEBUG when entering a function */
#define LOG_EXIT(c) do {LOG_T(c,"Exiting\n"); return;}while(0)  /*!< \brief Macro to log a message with severity TRACE when exiting a function */
#define LOG_RETURN(c,x) do {uint32_t __rv;__rv=(unsigned int)(x);LOG_T(c,"Returning %08x\n", __rv);return((typeof(x))__rv);}while(0)  /*!< \brief Macro to log a function exit, including integer value, then to return a value to the calling function */
181
182
183
184
185
186
187
188
189
190
191
/* @}*/


/** @defgroup _log_format Defined log format
 *  @ingroup _macro
 *  @brief Macro of log formats defined by LOG
 * @{*/

/* .log_format = 0x13 uncolored standard messages
 * .log_format = 0x93 colored standard messages */

192
193
#define LOG_RED "\033[1;31m"  /*!< \brief VT100 sequence for bold red foreground */
#define LOG_GREEN "\033[32m"  /*!< \brief VT100 sequence for green foreground */
194
#define LOG_ORANGE "\033[93m"   /*!< \brief VT100 sequence for orange foreground */
195
196
197
#define LOG_BLUE "\033[34m" /*!< \brief VT100 sequence for blue foreground */
#define LOG_CYBL "\033[40;36m"  /*!< \brief VT100 sequence for cyan foreground on black background */
#define LOG_RESET "\033[0m" /*!< \brief VT100 sequence for reset (black) foreground */
198
199
200
201
202
203
204
205
206
207
/* @}*/


/** @defgroup _syslog_conf Macros for write in syslog.conf
 *  @ingroup _macro
 *  @brief Macros used to write lines (local/remote) in syslog.conf
 * @{*/
#define LOG_LOCAL      0x01
#define LOG_REMOTE     0x02

208
209
#define FLAG_COLOR     0x001  /*!< \brief defaults */
#define FLAG_PID       0x002  /*!< \brief defaults */
210
#define FLAG_COMP      0x004
211
#define FLAG_THREAD    0x008  /*!< \brief all : 255/511 */
212
213
214
215
216
217
218
219
220
221
222
#define FLAG_LEVEL     0x010
#define FLAG_FUNCT     0x020
#define FLAG_FILE_LINE 0x040
#define FLAG_TIME      0x100

#define LOG_NONE        0x00
#define LOG_LOW         0x5
#define LOG_MED         0x15
#define LOG_HIGH        0x35
#define LOG_FULL        0x75

223
224
225
226
#define OAI_OK 0    /*!< \brief all ok */
#define OAI_ERR 1   /*!< \brief generic error */
#define OAI_ERR_READ_ONLY 2 /*!< \brief tried to write to read-only item */
#define OAI_ERR_NOTFOUND 3  /*!< \brief something wasn't found */
227
228
229
/* @}*/


230
//static char *log_level_highlight_start[] = {LOG_RED, LOG_RED, LOG_RED, LOG_RED, LOG_BLUE, "", "", "", LOG_GREEN}; /*!< \brief Optional start-format strings for highlighting */
231

232
//static char *log_level_highlight_end[]   = {LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET, LOG_RESET, "", "", "", LOG_RESET};  /*!< \brief Optional end-format strings for highlighting */
233

234
typedef enum {
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
  MIN_LOG_COMPONENTS = 0,
  PHY = MIN_LOG_COMPONENTS,
  MAC,
  EMU,
  OCG,
  OMG,
  OPT,
  OTG,
  OTG_LATENCY,
  OTG_LATENCY_BG,
  OTG_GP,
  OTG_GP_BG,
  OTG_JITTER,
  RLC,
  PDCP,
  RRC,
  NAS,
  PERF,
  OIP,
  CLI,
  MSC,
  OCM,
  UDP_,
  GTPU,
  SPGW,
  S1AP,
  SCTP,
  HW,
  OSA,
  RAL_ENB,
  RAL_UE,
  ENB_APP,
  TMR,
  USIM,
  LOCALIZE,
  MAX_LOG_COMPONENTS,
}
comp_name_t;

//#define msg printf
275
276

typedef struct {
277
278
  char *name; /*!< \brief string name of item */
  int value;  /*!< \brief integer value of mapping */
279
280
281
282
} mapping;


typedef struct  {
283
284
285
286
287
288
289
290
291
292
293
  const char *name;
  int         level;
  int         flag;
  int         interval;
  int         fd;
  int         filelog;
  char       *filelog_name;

  /* SR: make the log buffer component relative */
  char        log_buffer[MAX_LOG_TOTAL];
} log_component_t;
294
295

typedef struct  {
296
297
298
299
300
301
  unsigned int remote_ip;
  unsigned int audit_ip;
  int  remote_level;
  int  facility;
  int  audit_facility;
  int  format;
302
} log_config_t;
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317


typedef struct {
  log_component_t         log_component[MAX_LOG_COMPONENTS];
  log_config_t            config;
  char*                   level2string[NUM_LOG_LEVEL];
  int                     level;
  int                     onlinelog;
  int                     flag;
  int                     syslog;
  int                     filelog;
  char*                   filelog_name;
} log_t;

typedef struct LOG_params {
318
319
  const char *file;
  const char *func;
320
321
322
  int line;
  int comp;
  int level;
323
  const char *format;
324
325
326
327
328
  char l_buff_info [MAX_LOG_INFO];
  int len;
} LOG_params;


329
330
331
332
333
334
335
336
337
#if defined(ENABLE_ITTI)
typedef enum log_instance_type_e {
  LOG_INSTANCE_UNKNOWN,
  LOG_INSTANCE_ENB,
  LOG_INSTANCE_UE,
} log_instance_type_t;

void log_set_instance_type (log_instance_type_t instance);
#endif
338
int logInit (void);
339

340
341
342
343
344
345
346
347
348
349
/*--- INCLUDES ---------------------------------------------------------------*/
#    include "log_if.h"
/*----------------------------------------------------------------------------*/
#ifdef __cplusplus
}
#endif

#endif