Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-17 08:35:04

0001 /*
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements. See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership. The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License. You may obtain a copy of the License at
0009  *
0010  *   http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing,
0013  * software distributed under the License is distributed on an
0014  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
0015  * KIND, either express or implied. See the License for the
0016  * specific language governing permissions and limitations
0017  * under the License.
0018  */
0019 
0020 #ifndef _THRIFT_TLOGGING_H_
0021 #define _THRIFT_TLOGGING_H_ 1
0022 
0023 #include <thrift/thrift-config.h>
0024 
0025 /**
0026  * Contains utility macros for debugging and logging.
0027  *
0028  */
0029 
0030 #include <time.h>
0031 
0032 #ifdef HAVE_STDINT_H
0033 #include <stdint.h>
0034 #endif
0035 
0036 /**
0037  * T_GLOBAL_DEBUGGING_LEVEL = 0: all debugging turned off, debug macros undefined
0038  * T_GLOBAL_DEBUGGING_LEVEL = 1: all debugging turned on
0039  */
0040 #define T_GLOBAL_DEBUGGING_LEVEL 0
0041 
0042 /**
0043  * T_GLOBAL_LOGGING_LEVEL = 0: all logging turned off, logging macros undefined
0044  * T_GLOBAL_LOGGING_LEVEL = 1: all logging turned on
0045  */
0046 #define T_GLOBAL_LOGGING_LEVEL 1
0047 
0048 /**
0049  * Standard wrapper around fprintf what will prefix the file name and line
0050  * number to the line. Uses T_GLOBAL_DEBUGGING_LEVEL to control whether it is
0051  * turned on or off.
0052  *
0053  * @param format_string
0054  */
0055 #if T_GLOBAL_DEBUGGING_LEVEL > 0
0056 #define T_DEBUG(format_string, ...)                                                                \
0057   if (T_GLOBAL_DEBUGGING_LEVEL > 0) {                                                              \
0058     fprintf(stderr, "[%s,%d] " format_string " \n", __FILE__, __LINE__, ##__VA_ARGS__);            \
0059   }
0060 #else
0061 #define T_DEBUG(format_string, ...)
0062 #endif
0063 
0064 /**
0065  * analogous to T_DEBUG but also prints the time
0066  *
0067  * @param string  format_string input: printf style format string
0068  */
0069 #if T_GLOBAL_DEBUGGING_LEVEL > 0
0070 #define T_DEBUG_T(format_string, ...)                                                              \
0071   {                                                                                                \
0072     if (T_GLOBAL_DEBUGGING_LEVEL > 0) {                                                            \
0073       time_t now;                                                                                  \
0074       char dbgtime[26];                                                                            \
0075       time(&now);                                                                                  \
0076       THRIFT_CTIME_R(&now, dbgtime);                                                               \
0077       dbgtime[24] = '\0';                                                                          \
0078       fprintf(stderr,                                                                              \
0079               "[%s,%d] [%s] " format_string " \n",                                                 \
0080               __FILE__,                                                                            \
0081               __LINE__,                                                                            \
0082               dbgtime,                                                                             \
0083               ##__VA_ARGS__);                                                                      \
0084     }                                                                                              \
0085   }
0086 #else
0087 #define T_DEBUG_T(format_string, ...)
0088 #endif
0089 
0090 /**
0091  * analogous to T_DEBUG but uses input level to determine whether or not the string
0092  * should be logged.
0093  *
0094  * @param int     level: specified debug level
0095  * @param string  format_string input: format string
0096  */
0097 #define T_DEBUG_L(level, format_string, ...)                                                       \
0098   if ((level) > 0) {                                                                               \
0099     fprintf(stderr, "[%s,%d] " format_string " \n", __FILE__, __LINE__, ##__VA_ARGS__);            \
0100   }
0101 
0102 /**
0103  * Explicit error logging. Prints time, file name and line number
0104  *
0105  * @param string  format_string input: printf style format string
0106  */
0107 #define T_ERROR(format_string, ...)                                                                \
0108   {                                                                                                \
0109     time_t now;                                                                                    \
0110     char dbgtime[26];                                                                              \
0111     time(&now);                                                                                    \
0112     THRIFT_CTIME_R(&now, dbgtime);                                                                 \
0113     dbgtime[24] = '\0';                                                                            \
0114     fprintf(stderr,                                                                                \
0115             "[%s,%d] [%s] ERROR: " format_string " \n",                                            \
0116             __FILE__,                                                                              \
0117             __LINE__,                                                                              \
0118             dbgtime,                                                                               \
0119             ##__VA_ARGS__);                                                                        \
0120   }
0121 
0122 /**
0123  * Analogous to T_ERROR, additionally aborting the process.
0124  * WARNING: macro calls abort(), ending program execution
0125  *
0126  * @param string  format_string input: printf style format string
0127  */
0128 #define T_ERROR_ABORT(format_string, ...)                                                          \
0129   {                                                                                                \
0130     time_t now;                                                                                    \
0131     char dbgtime[26];                                                                              \
0132     time(&now);                                                                                    \
0133     THRIFT_CTIME_R(&now, dbgtime);                                                                 \
0134     dbgtime[24] = '\0';                                                                            \
0135     fprintf(stderr,                                                                                \
0136             "[%s,%d] [%s] ERROR: Going to abort " format_string " \n",                             \
0137             __FILE__,                                                                              \
0138             __LINE__,                                                                              \
0139             dbgtime,                                                                               \
0140             ##__VA_ARGS__);                                                                        \
0141     exit(1);                                                                                       \
0142   }
0143 
0144 /**
0145  * Log input message
0146  *
0147  * @param string  format_string input: printf style format string
0148  */
0149 #if T_GLOBAL_LOGGING_LEVEL > 0
0150 #define T_LOG_OPER(format_string, ...)                                                             \
0151   {                                                                                                \
0152     if (T_GLOBAL_LOGGING_LEVEL > 0) {                                                              \
0153       time_t now;                                                                                  \
0154       char dbgtime[26];                                                                            \
0155       time(&now);                                                                                  \
0156       THRIFT_CTIME_R(&now, dbgtime);                                                               \
0157       dbgtime[24] = '\0';                                                                          \
0158       fprintf(stderr, "[%s] " format_string " \n", dbgtime, ##__VA_ARGS__);                        \
0159     }                                                                                              \
0160   }
0161 #else
0162 #define T_LOG_OPER(format_string, ...)
0163 #endif
0164 
0165 /**
0166  * T_GLOBAL_DEBUG_VIRTUAL = 0 or unset: normal operation,
0167  *                                      virtual call debug messages disabled
0168  * T_GLOBAL_DEBUG_VIRTUAL = 1:          log a debug messages whenever an
0169  *                                      avoidable virtual call is made
0170  * T_GLOBAL_DEBUG_VIRTUAL = 2:          record detailed info that can be
0171  *                                      printed by calling
0172  *                                      apache::thrift::profile_print_info()
0173  */
0174 #if T_GLOBAL_DEBUG_VIRTUAL > 1
0175 #define T_VIRTUAL_CALL() ::apache::thrift::profile_virtual_call(typeid(*this))
0176 #define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot)                            \
0177   do {                                                                                             \
0178     if (!(specific_prot)) {                                                                        \
0179       ::apache::thrift::profile_generic_protocol(typeid(*template_class), typeid(*generic_prot));  \
0180     }                                                                                              \
0181   } while (0)
0182 #elif T_GLOBAL_DEBUG_VIRTUAL == 1
0183 #define T_VIRTUAL_CALL() fprintf(stderr, "[%s,%d] virtual call\n", __FILE__, __LINE__)
0184 #define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot)                            \
0185   do {                                                                                             \
0186     if (!(specific_prot)) {                                                                        \
0187       fprintf(stderr, "[%s,%d] failed to cast to specific protocol type\n", __FILE__, __LINE__);   \
0188     }                                                                                              \
0189   } while (0)
0190 #else
0191 #define T_VIRTUAL_CALL()
0192 #define T_GENERIC_PROTOCOL(template_class, generic_prot, specific_prot)
0193 #endif
0194 
0195 #endif // #ifndef _THRIFT_TLOGGING_H_