log.h 23.7 KB
Newer Older
1 2 3 4 5
/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
6
 * the OAI Public License, Version 1.1  (the "License"); you may not use this file
7 8 9 10 11 12 13 14 15 16 17 18 19 20
 * except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
21 22 23 24

/*! \file log.h
* \brief openair log generator (OLG) for
* \author Navid Nikaein
25
* \date 2009 - 2014
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
* \version 0.5
* @ingroup util
*/

#ifndef __LOG_H__
#    define __LOG_H__

/*--- INCLUDES ---------------------------------------------------------------*/
#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>
laurent's avatar
laurent committed
44 45
#include <time.h>
#include <stdint.h>
46
#ifndef __STDC_FORMAT_MACROS
laurent's avatar
fixes  
laurent committed
47
  #define __STDC_FORMAT_MACROS
48
#endif
laurent's avatar
laurent committed
49
#include <inttypes.h>
laurent's avatar
laurent committed
50
#ifndef _GNU_SOURCE
laurent's avatar
fixes  
laurent committed
51
  #define _GNU_SOURCE
laurent's avatar
laurent committed
52
#endif
53
#include <pthread.h>
laurent's avatar
fixes  
laurent committed
54
#include <common/utils/utils.h>
55
/*----------------------------------------------------------------------------*/
56 57 58 59 60 61
#include <assert.h>
#ifdef NDEBUG
#warning assert is disabled
#endif
#define NUM_ELEMENTS(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
#define CHECK_INDEX(ARRAY, INDEX) assert((INDEX) < NUM_ELEMENTS(ARRAY))
62 63 64 65 66 67 68 69 70

#ifdef __cplusplus
extern "C" {
#endif

/** @defgroup _max_length Maximum Length of LOG
 *  @ingroup _macro
 *  @brief the macros that describe the maximum length of LOG
 * @{*/
71

72
#define MAX_LOG_TOTAL 16384 /*!< \brief the maximum length of a log */
73
/** @}*/
74 75 76 77 78

/** @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
 * @{*/
79
# define  OAILOG_DISABLE -1 /*!< \brief disable all LOG messages, cannot be used in LOG macros, use only in LOG module */
80
# define  OAILOG_ERR      0 /*!< \brief critical error conditions, impact on "must have" functionalities */
81
# define  OAILOG_WARNING  1 /*!< \brief warning conditions, shouldn't happen but doesn't impact "must have" functionalities */
82 83 84 85
# define  OAILOG_ANALYSIS 2 /*!< \brief informational messages most people don't need, shouldn't impact real-time behavior */
# define  OAILOG_INFO     3 /*!< \brief informational messages most people don't need, shouldn't impact real-time behavior */
# define  OAILOG_DEBUG    4 /*!< \brief first level debug-level messages, for developers, may impact real-time behavior */
# define  OAILOG_TRACE    5 /*!< \brief second level debug-level messages, for developers, likely impact real-time behavior*/
86

87
#define NUM_LOG_LEVEL 6 /*!< \brief the number of message levels users have with LOG (OAILOG_DISABLE is not available to user as a level, so it is not included)*/
88
/** @}*/
89

laurent's avatar
laurent committed
90 91 92 93 94 95 96
/** @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 */
97
/* keep white space in first position; switching it to 0 allows colors to be disabled*/
laurent's avatar
laurent committed
98 99 100 101 102 103
#define LOG_RED "\033[1;31m"  /*!< \brief VT100 sequence for bold red foreground */
#define LOG_GREEN "\033[32m"  /*!< \brief VT100 sequence for green foreground */
#define LOG_ORANGE "\033[93m"   /*!< \brief VT100 sequence for orange foreground */
#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 */
104 105 106
#define FLAG_NOCOLOR     0x0001  /*!< \brief use colors in log messages, depending on level */
#define FLAG_THREAD      0x0008  /*!< \brief display thread name in log messages */
#define FLAG_LEVEL       0x0010  /*!< \brief display log level in log messages */
107 108
#define FLAG_FUNCT       0x0020
#define FLAG_FILE_LINE   0x0040
109
#define FLAG_TIME        0x0100
110
#define FLAG_THREAD_ID   0x0200
111
#define FLAG_REAL_TIME   0x0400
112
#define FLAG_INITIALIZED 0x8000
113
/** @}*/
114 115 116 117 118 119

#define SET_LOG_OPTION(O)   g_log->flag = (g_log->flag | O)
#define CLEAR_LOG_OPTION(O) g_log->flag = (g_log->flag & (~O))

/** @defgroup macros to identify a debug entity
 *  @ingroup each macro is a bit mask where the unique bit set identifies an entity to be debugged
laurent's avatar
fixes  
laurent committed
120
 *            it allows to dynamically activate or not blocks of code. The  LOG_MASKMAP_INIT macro
121 122 123
 *            is used to map a character string name to each debug bit, it allows to set or clear
 *            the corresponding bit via the defined name, from the configuration or from the telnet
 *            server.
laurent's avatar
fixes  
laurent committed
124
 *  @brief
125
 * @{*/
126 127 128
#define DEBUG_PRACH        (1<<0)
#define DEBUG_RU           (1<<1)
#define DEBUG_UE_PHYPROC   (1<<2)
129
#define DEBUG_LTEESTIM     (1<<3)
130 131 132 133 134
#define DEBUG_DLCELLSPEC   (1<<4)
#define DEBUG_ULSCH        (1<<5)
#define DEBUG_RRC          (1<<6)
#define DEBUG_PDCP         (1<<7)
#define DEBUG_DFT          (1<<8)
135
#define DEBUG_ASN1         (1<<9)
136
#define DEBUG_CTRLSOCKET   (1<<10)
137 138
#define DEBUG_SECURITY     (1<<11)
#define DEBUG_NAS          (1<<12)
139
#define DEBUG_RLC          (1<<13)
140
#define DEBUG_DLSCH_DECOD  (1<<14)
141
#define UE_TIMING          (1<<20)
142 143


144
#define LOG_MASKMAP_INIT {\
laurent's avatar
fixes  
laurent committed
145 146 147 148 149 150 151 152 153 154 155 156 157
    {"PRACH",       DEBUG_PRACH},\
    {"RU",          DEBUG_RU},\
    {"UE_PHYPROC",  DEBUG_UE_PHYPROC},\
    {"LTEESTIM",    DEBUG_LTEESTIM},\
    {"DLCELLSPEC",  DEBUG_DLCELLSPEC},\
    {"ULSCH",       DEBUG_ULSCH},\
    {"RRC",         DEBUG_RRC},\
    {"PDCP",        DEBUG_PDCP},\
    {"DFT",         DEBUG_DFT},\
    {"ASN1",        DEBUG_ASN1},\
    {"CTRLSOCKET",  DEBUG_CTRLSOCKET},\
    {"SECURITY",    DEBUG_SECURITY},\
    {"NAS",         DEBUG_NAS},\
158
    {"RLC",         DEBUG_RLC},\
159
    {"DLSCH_DECOD", DEBUG_DLSCH_DECOD},\
laurent's avatar
fixes  
laurent committed
160 161 162
    {"UE_TIMING",   UE_TIMING},\
    {NULL,-1}\
  }
163 164 165 166

#define SET_LOG_DEBUG(B)   g_log->debug_mask = (g_log->debug_mask | B)
#define CLEAR_LOG_DEBUG(B) g_log->debug_mask = (g_log->debug_mask & (~B))

167 168
#define SET_LOG_DUMP(B)   g_log->dump_mask = (g_log->dump_mask | B)
#define CLEAR_LOG_DUMP(B) g_log->dump_mask = (g_log->dump_mask & (~B))
169

laurent's avatar
laurent committed
170
typedef enum {
laurent's avatar
fixes  
laurent committed
171 172 173
  MIN_LOG_COMPONENTS = 0,
  PHY = MIN_LOG_COMPONENTS,
  MAC,
174
  EMU,
laurent's avatar
fixes  
laurent committed
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
  SIM,
  OMG,
  OPT,
  OTG,
  OTG_LATENCY,
  OTG_LATENCY_BG,
  OTG_GP,
  OTG_GP_BG,
  OTG_JITTER,
  RLC,
  PDCP,
  RRC,
  NAS,
  PERF,
  OIP,
190
  CLI,
laurent's avatar
fixes  
laurent committed
191 192 193
  OCM,
  UDP_,
  GTPU,
194
  SDAP,
laurent's avatar
fixes  
laurent committed
195 196
  SPGW,
  S1AP,
197
  F1AP,
Robert Schmidt's avatar
Robert Schmidt committed
198
  E1AP,
laurent's avatar
fixes  
laurent committed
199 200 201 202 203 204
  SCTP,
  HW,
  OSA,
  RAL_ENB,
  RAL_UE,
  ENB_APP,
205 206
  MCE_APP,
  MME_APP,
laurent's avatar
fixes  
laurent committed
207 208 209
  TMR,
  USIM,
  LOCALIZE,
210
  F1U,
laurent's avatar
fixes  
laurent committed
211
  X2AP,
212 213
  M2AP,
  M3AP,
zhenghuangkun's avatar
zhenghuangkun committed
214
  NGAP,
215 216 217
  GNB_APP,
  NR_RRC,
  NR_MAC,
218 219
  NR_MAC_DCI,
  NR_PHY_DCI,
220
  NR_PHY,
laurent's avatar
fixes  
laurent committed
221
  LOADER,
222
  ASN1,
223 224
  NFAPI_VNF,
  NFAPI_PNF,
225 226
  ITTI,
  UTIL,
laurent's avatar
fixes  
laurent committed
227
  MAX_LOG_PREDEF_COMPONENTS,
228
} comp_name_t;
laurent's avatar
laurent committed
229

230 231
#define MAX_LOG_DYNALLOC_COMPONENTS 20
#define MAX_LOG_COMPONENTS (MAX_LOG_PREDEF_COMPONENTS + MAX_LOG_DYNALLOC_COMPONENTS)
232

laurent's avatar
laurent committed
233
typedef struct {
laurent's avatar
fixes  
laurent committed
234 235
  char *name; /*!< \brief string name of item */
  int value;  /*!< \brief integer value of mapping */
laurent's avatar
laurent committed
236 237
} mapping;

238 239
typedef int(*log_vprint_func_t)(FILE *stream, const char *format, va_list ap );
typedef int(*log_print_func_t)(FILE *stream, const char *format, ... );
laurent's avatar
laurent committed
240
typedef struct  {
laurent's avatar
fixes  
laurent committed
241 242 243 244 245 246 247 248 249 250
  const char        *name;
  int               level;
  int               savedlevel;
  int               flag;
  int               filelog;
  char              *filelog_name;
  FILE              *stream;
  log_vprint_func_t vprint;
  log_print_func_t  print;
  /* SR: make the log buffer component relative */
251
  // char             log_buffer[MAX_LOG_TOTAL];
laurent's avatar
laurent committed
252 253 254 255
} log_component_t;


typedef struct {
laurent's avatar
fixes  
laurent committed
256 257 258 259 260 261
  log_component_t         log_component[MAX_LOG_COMPONENTS];
  char                    level2string[NUM_LOG_LEVEL];
  int                     flag;
  char                   *filelog_name;
  uint64_t                debug_mask;
  uint64_t                dump_mask;
laurent's avatar
laurent committed
262 263
} log_t;

264 265 266 267
#ifdef LOG_MAIN
log_t *g_log;
#else
#ifdef __cplusplus
laurent's avatar
fixes  
laurent committed
268
extern "C" {
269
#endif
laurent's avatar
fixes  
laurent committed
270
  extern log_t *g_log;
271 272 273 274
#ifdef __cplusplus
}
#endif
#endif
laurent's avatar
laurent committed
275 276 277 278
/*--- INCLUDES ---------------------------------------------------------------*/
#    include "log_if.h"
/*----------------------------------------------------------------------------*/
int  logInit (void);
279
void logTerm (void);
280
int  isLogInitDone (void);
281
void logRecord_mt(const char *file, const char *func, int line,int comp, int level, const char *format, ...) __attribute__ ((format (printf, 6, 7)));
282
void vlogRecord_mt(const char *file, const char *func, int line, int comp, int level, const char *format, va_list args );
laurent's avatar
fixes  
laurent committed
283
void log_dump(int component, void *buffer, int buffsize,int datatype, const char *format, ... );
284
int  set_log(int component, int level);
285 286
void set_glog(int level);

287 288
void set_glog_onlinelog(int enable);
void set_glog_filelog(int enable);
laurent's avatar
laurent committed
289
void set_component_filelog(int comp);
290 291
void close_component_filelog(int comp);
void set_component_consolelog(int comp);
laurent's avatar
laurent committed
292 293
int map_str_to_int(const mapping *map, const char *str);
char *map_int_to_str(const mapping *map, const int val);
laurent's avatar
laurent committed
294 295
void logClean (void);
int  is_newline( char *str, int size);
296

297
int register_log_component(char *name, char *fext, int compidx);
298

299 300 301 302 303 304 305 306 307 308 309 310
#define LOG_MEM_SIZE 100*1024*1024
#define LOG_MEM_FILE "./logmem.log"
void flush_mem_to_file(void);
int logInit_log_mem(void);
void close_log_mem(void);
  
typedef struct {
  char* buf_p;
  int buf_index;
  int enable_flag;
} log_mem_cnt_t;

311
/** @}*/
312

bruno mongazon's avatar
bruno mongazon committed
313 314 315 316 317 318 319 320
/*!\fn int32_t write_file_matlab(const char *fname, const char *vname, void *data, int length, int dec, char format);
\brief Write output file from signal data
@param fname output file name
@param vname  output vector name (for MATLAB/OCTAVE)
@param data   point to data
@param length length of data vector to output
@param dec    decimation level
@param format data format (0 = real 16-bit, 1 = complex 16-bit,2 real 32-bit, 3 complex 32-bit,4 = real 8-bit, 5 = complex 8-bit)
321
@param multiVec create new file or append to existing (useful for writing multiple vectors to same file. Just call the function multiple times with same file name and with this parameter set to 1)
bruno mongazon's avatar
bruno mongazon committed
322
*/
323
#define MATLAB_RAW (1U<<31)
laurent's avatar
laurent committed
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
#define MATLAB_SHORT 0
#define MATLAB_CSHORT 1
#define MATLAB_INT 2
#define MATLAB_CINT 3
#define MATLAB_INT8 4
#define MATLAB_CINT8 5
#define MATLAB_LLONG 6
#define MATLAB_DOUBLE 7
#define MATLAB_CDOUBLE 8
#define MATLAB_UINT8 9
#define MATLEB_EREN1 10
#define MATLEB_EREN2 11
#define MATLEB_EREN3 12
#define MATLAB_CSHORT_BRACKET1 13
#define MATLAB_CSHORT_BRACKET2 14
#define MATLAB_CSHORT_BRACKET3 15
  
341
int32_t write_file_matlab(const char *fname, const char *vname, void *data, int length, int dec, unsigned int format, int multiVec);
342
#define write_output(a, b, c, d, e, f) write_file_matlab(a, b, c, d, e, f, 0)
bruno mongazon's avatar
bruno mongazon committed
343

344 345 346 347 348 349
/*----------------macro definitions for reading log configuration from the config module */
#define CONFIG_STRING_LOG_PREFIX                           "log_config"

#define LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL                 "global_log_level"
#define LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE                "global_log_online"
#define LOG_CONFIG_STRING_GLOBAL_LOG_INFILE                "global_log_infile"
350
#define LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS               "global_log_options"
351 352 353

#define LOG_CONFIG_LEVEL_FORMAT                            "%s_log_level"
#define LOG_CONFIG_LOGFILE_FORMAT                          "%s_log_infile"
354
#define LOG_CONFIG_DEBUG_FORMAT                            "%s_debug"
355
#define LOG_CONFIG_DUMP_FORMAT                             "%s_dump"
356 357

#define LOG_CONFIG_HELP_OPTIONS      " list of comma separated options to enable log module behavior. Available options: \n"\
laurent's avatar
fixes  
laurent committed
358 359 360 361
  " nocolor:   disable color usage in log messages\n"\
  " level:     add log level indication in log messages\n"\
  " thread:    add threads names in log messages\n"

362
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
363
/*   LOG global configuration parameters                                                                                                                                                */
364 365
/*   optname                               help                                          paramflags         XXXptr               defXXXval                          type        numelt */
/*-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------*/
366
// clang-format off
367
#define LOG_GLOBALPARAMS_DESC { \
368 369 370 371 372
  {LOG_CONFIG_STRING_GLOBAL_LOG_LEVEL,   "Default log level for all componemts\n",              0, .strptr=&gloglevel,         .defstrval=log_level_names[3].name, TYPE_STRING,     0}, \
  {LOG_CONFIG_STRING_GLOBAL_LOG_ONLINE,  "Default console output option, for all components\n", 0, .iptr=&(consolelog),        .defintval=1,                       TYPE_INT,        0}, \
  {LOG_CONFIG_STRING_GLOBAL_LOG_OPTIONS, LOG_CONFIG_HELP_OPTIONS,                               0, .strlistptr=NULL,           .defstrlistval=NULL,                TYPE_STRINGLIST, 0}, \
}
// clang-format on
373 374

#define LOG_OPTIONS_IDX   2
375 376


377
/*----------------------------------------------------------------------------------*/
378 379 380 381
/** @defgroup _debugging debugging macros
 *  @ingroup _macro
 *  @brief Macro used to call logIt function with different message levels
 * @{*/
382 383 384 385
#define LOG_DUMP_CHAR       0
#define LOG_DUMP_DOUBLE     1
// debugging macros
#define LOG_F  LOG_I           /* because  LOG_F was originaly to dump a message or buffer but is also used as a regular level...., to dump use LOG_DUMPMSG */
386

laurent's avatar
fixes  
laurent committed
387
#  if T_TRACER
388
#include "T.h"
389
/* per component, level dependent macros */
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
#define LOG_E(c, x...)                                                    \
  do {                                                                    \
    T(T_LEGACY_##c##_ERROR, T_PRINTF(x));                                 \
    if (T_stdout) {                                                       \
      if (g_log->log_component[c].level >= OAILOG_ERR)                    \
        logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_ERR, x); \
    }                                                                     \
  } while (0)

#define LOG_W(c, x...)                                                        \
  do {                                                                        \
    T(T_LEGACY_##c##_WARNING, T_PRINTF(x));                                   \
    if (T_stdout) {                                                           \
      if (g_log->log_component[c].level >= OAILOG_WARNING)                    \
        logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_WARNING, x); \
    }                                                                         \
  } while (0)

#define LOG_A(c, x...)                                                         \
  do {                                                                         \
    T(T_LEGACY_##c##_INFO, T_PRINTF(x));                                       \
    if (T_stdout) {                                                            \
      if (g_log->log_component[c].level >= OAILOG_ANALYSIS)                    \
        logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_ANALYSIS, x); \
    }                                                                          \
  } while (0)

#define LOG_I(c, x...)                                                     \
  do {                                                                     \
    T(T_LEGACY_##c##_INFO, T_PRINTF(x));                                   \
    if (T_stdout) {                                                        \
      if (g_log->log_component[c].level >= OAILOG_INFO)                    \
        logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_INFO, x); \
    }                                                                      \
  } while (0)

#define LOG_D(c, x...)                                                      \
  do {                                                                      \
    T(T_LEGACY_##c##_DEBUG, T_PRINTF(x));                                   \
    if (T_stdout) {                                                         \
      if (g_log->log_component[c].level >= OAILOG_DEBUG)                    \
        logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_DEBUG, x); \
    }                                                                       \
  } while (0)

#define LOG_DDUMP(c, b, s, f, x...)                      \
  do {                                                   \
    T(T_LEGACY_##c##_DEBUG, T_PRINTF(x));                \
    if (T_stdout) {                                      \
      if (g_log->log_component[c].level >= OAILOG_DEBUG) \
        log_dump(c, b, s, f, x);                         \
    }                                                    \
  } while (0)

#define LOG_T(c, x...)                                                      \
  do {                                                                      \
    T(T_LEGACY_##c##_TRACE, T_PRINTF(x));                                   \
    if (T_stdout) {                                                         \
      if (g_log->log_component[c].level >= OAILOG_TRACE)                    \
        logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_TRACE, x); \
    }                                                                       \
  } while (0)

#define VLOG(c, l, f, args)                                             \
  do {                                                                  \
    if (T_stdout) {                                                     \
      if (g_log->log_component[c].level >= l)                           \
        vlogRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, l, f, args); \
    }                                                                   \
  } while (0)

laurent's avatar
fixes  
laurent committed
461
/* macro used to dump a buffer or a message as in openair2/RRC/LTE/RRC_eNB.c, replaces LOG_F macro */
462 463 464 465 466 467
#define LOG_DUMPMSG(c, f, b, s, x...)      \
  do {                                     \
    if (g_log->dump_mask & f)              \
      log_dump(c, b, s, LOG_DUMP_CHAR, x); \
  } while (0)

468
/* bitmask dependent macros, to isolate debugging code */
469
#define LOG_DEBUGFLAG(D) (g_log->debug_mask & D)
470

471
/* bitmask dependent macros, to generate debug file such as matlab file or message dump */
472 473 474 475 476 477 478
#define LOG_DUMPFLAG(D) (g_log->dump_mask & D)

#define LOG_M(file, vector, data, len, dec, format)             \
  do {                                                          \
    write_file_matlab(file, vector, data, len, dec, format, 0); \
  } while (0)

laurent's avatar
fixes  
laurent committed
479
/* define variable only used in LOG macro's */
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549
#define LOG_VAR(A, B) A B

#else /* no T_TRACER */

#define LOG_E(c, x...)                                                  \
  do {                                                                  \
    if (g_log->log_component[c].level >= OAILOG_ERR)                    \
      logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_ERR, x); \
  } while (0)

#define LOG_W(c, x...)                                                      \
  do {                                                                      \
    if (g_log->log_component[c].level >= OAILOG_WARNING)                    \
      logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_WARNING, x); \
  } while (0)

#define LOG_A(c, x...)                                                       \
  do {                                                                       \
    if (g_log->log_component[c].level >= OAILOG_ANALYSIS)                    \
      logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_ANALYSIS, x); \
  } while (0)

#define LOG_I(c, x...)                                                   \
  do {                                                                   \
    if (g_log->log_component[c].level >= OAILOG_INFO)                    \
      logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_INFO, x); \
  } while (0)

#define LOG_D(c, x...)                                                    \
  do {                                                                    \
    if (g_log->log_component[c].level >= OAILOG_DEBUG)                    \
      logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_DEBUG, x); \
  } while (0)

#define LOG_DDUMP(c, b, s, f, x...)                    \
  do {                                                 \
    if (g_log->log_component[c].level >= OAILOG_DEBUG) \
      log_dump(c, b, s, f, x);                         \
  } while (0)

#define LOG_T(c, x...)                                                    \
  do {                                                                    \
    if (g_log->log_component[c].level >= OAILOG_TRACE)                    \
      logRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, OAILOG_TRACE, x); \
  } while (0)

#define VLOG(c, l, f, args)                                           \
  do {                                                                \
    if (g_log->log_component[c].level >= l)                           \
      vlogRecord_mt(__FILE__, __FUNCTION__, __LINE__, c, l, f, args); \
  } while (0)

#define nfapi_log(FILE, FNC, LN, COMP, LVL, FMT...)
#define LOG_DEBUGFLAG(D) (g_log->dump_mask & D)
#define LOG_DUMPFLAG(D) (g_log->debug_mask & D)
#define LOG_DUMPMSG(c, f, b, s, x...)      \
  do {                                     \
    if (g_log->dump_mask & f)              \
      log_dump(c, b, s, LOG_DUMP_CHAR, x); \
  } while (0) /* */

#define LOG_M(file, vector, data, len, dec, format)             \
  do {                                                          \
    write_file_matlab(file, vector, data, len, dec, format, 0); \
  } while (0)

#define LOG_VAR(A, B) A B
#define T_ACTIVE(a) (0)

#endif /* T_TRACER */
550

551
/* avoid warnings for variables only used in LOG macro's but set outside debug section */
laurent's avatar
fixes  
laurent committed
552 553
#define GCC_NOTUSED   __attribute__((unused))
#define LOG_USEDINLOG_VAR(A,B) GCC_NOTUSED A B
554

555
/* unfiltered macros, useful for simulators or messages at init time, before log is configured */
556
#define LOG_UM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format, 0);} while(0)
557
#define LOG_UI(c, x...) do {logRecord_mt(__FILE__, __FUNCTION__, __LINE__,c, OAILOG_INFO, x) ; } while(0)
558
#define LOG_UDUMPMSG(c, b, s, f, x...) do { log_dump(c, b, s, f, x)  ;}   while (0)  /* */
559
#    define LOG_MM(file, vector, data, len, dec, format) do { write_file_matlab(file, vector, data, len, dec, format, 1);} while(0)
560
/** @}*/
561 562 563 564 565

/** @defgroup _useful_functions useful functions in LOG
 *  @ingroup _macro
 *  @brief Macro of some useful functions defined by LOG
 * @{*/
566 567 568 569 570
#define LOG_ENTER(c) do {LOG_T(c, "Entering %s\n",__FUNCTION__);}while(0) /*!< \brief Macro to log a message with severity DEBUG when entering a function */
#define LOG_END(c) do {LOG_T(c, "End of  %s\n",__FUNCTION__);}while(0) /*!< \brief Macro to log a message with severity DEBUG when entering a function */
#define LOG_EXIT(c)  do { LOG_END(c); return;}while(0)  /*!< \brief Macro to log a message with severity TRACE when exiting a function */
#define LOG_RETURN(c,r) do {LOG_T(c,"Leaving %s (rc = %08lx)\n", __FUNCTION__ , (unsigned long)(r) );return(r);}while(0)  /*!< \brief Macro to log a function exit, including integer value, then to return a value to the calling function */

571
/** @}*/
572 573 574 575 576 577

#ifdef __cplusplus
}
#endif

#endif