- Main Page
- Modules
- Namespaces
- Classes
- Files

- Search for |

- File List
- File Members

# include/NvLogging.h

Go to the documentation of this file.

    00001 /*
    00002  * Copyright (c) 2016, NVIDIA CORPORATION. All rights reserved.
    00003  *
    00004  * Redistribution and use in source and binary forms, with or without
    00005  * modification, are permitted provided that the following conditions
    00006  * are met:
    00007  *  * Redistributions of source code must retain the above copyright
    00008  *    notice, this list of conditions and the following disclaimer.
    00009  *  * Redistributions in binary form must reproduce the above copyright
    00010  *    notice, this list of conditions and the following disclaimer in the
    00011  *    documentation and/or other materials provided with the distribution.
    00012  *  * Neither the name of NVIDIA CORPORATION nor the names of its
    00013  *    contributors may be used to endorse or promote products derived
    00014  *    from this software without specific prior written permission.
    00015  *
    00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
    00017  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    00019  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    00020  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    00021  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    00022  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
    00023  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
    00024  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    00026  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00027  */
    00028
    00029 /**
    00030  * @file
    00031  * <b>NVIDIA Eagle Eye API: Logging API</b>
    00032  *
    00033  * @brief Description: This file defines macros for logging messages.
    00034  */
    00035
    00036 #ifndef __NV_LOGGING_H_
    00037 #define __NV_LOGGING_H_
    00038
    00039 #include <iostream>
    00040
    00041 /**
    00042  *
    00043  * @defgroup ee_nvlogging_group Logging API
    00044  *
    00045  * This file defines macros that provide message logging
    00046  * functionality.
    00047  *
    00048  * @{
    00049  */
    00050
    00051
    00052 /**
    00053  * Specifies the log level for Information messages.
    00054  */
    00055 #define LOG_LEVEL_INFO  0
    00056 /**
    00057  * Specifies the log level for Error messages.
    00058  */
    00059 #define LOG_LEVEL_ERROR 1
    00060 /**
    00061  * Specifies the log level for Warning messages.
    00062  */
    00063 #define LOG_LEVEL_WARN  2
    00064 /**
    00065  * Specifies the log level for Debug messages.
    00066  */
    00067 #define LOG_LEVEL_DEBUG 3
    00068
    00069 /**
    00070  * Holds the current log level at runtime by assignment of one of the
    00071  * @c LOG_LEVEL_* values.
    00072  */
    00073 extern int log_level;
    00074
    00075 /**
    00076  * Specifies the default log level.
    00077  */
    00078 #define DEFAULT_LOG_LEVEL LOG_LEVEL_INFO
    00079
    00080 /**
    00081  * @cond
    00082  */
    00083 #define stringify(s) #s
    00084 #define xstringify(s) stringify(s)
    00085 #define __LINE_NUM_STR__ xstringify(__LINE__)
    00086 /**
    00087  * @endcond
    00088  */
    00089
    00090 /**
    00091  *
    00092  * Prints log messages.
    00093  *
    00094  * Prints a log message only if the current @c log_level is greater
    00095  * than or equal to the level of the message.
    00096  *
    00097  * Messages are in the following form:
    00098  * [LEVEL] (FILE: LINE_NUM) Message
    00099  *
    00100  * @param[in] level The Log level of the message.
    00101  * @param[in] str The NULL-terminated char array to print.
    00102  */
    00103 #define PRINT_MSG(level, str) if(level <= log_level) { std::cerr << "[" #level "] (" __FILE__ ":" \
    00104                               __LINE_NUM_STR__ ") " << str << std::endl; }
    00105
    00106 /**
    00107  * Prints a log message of level @c LOG_LEVEL_INFO.
    00108  */
    00109 #define INFO_MSG(str) PRINT_MSG(LOG_LEVEL_INFO, str)
    00110 /**
    00111  * Prints a component-specific log message of level @c LOG_LEVEL_INFO.
    00112  * This is used by the components internally and should not be used by
    00113  * the application.
    00114  *
    00115  * Messages are in the following form:
    00116  * [LEVEL] (FILE: LINE_NUM) <comp_name> <message_content>
    00117  */
    00118 #define COMP_INFO_MSG(str) ERROR_MSG("<" << comp_name << "> " << str)
    00119 /**
    00120  * Prints a category-specific (Component type) system error log
    00121  * message of level @c LOG_LEVEL_INFO. This is used by the components
    00122  * internally and should not be used by the application.
    00123  *
    00124  * Messages are in the following form:
    00125  * [LEVEL] (FILE: LINE_NUM) <cat_name> <message_content>
    00126  */
    00127 #define CAT_INFO_MSG(str) ERROR_MSG("<" CAT_NAME "> " << str)
    00128
    00129 /**
    00130  * Prints a log message of level @c LOG_LEVEL_ERROR.
    00131  */
    00132 #define ERROR_MSG(str) PRINT_MSG(LOG_LEVEL_ERROR, str)
    00133 /**
    00134  * Prints a component-specific log message of level
    00135  * @c LOG_LEVEL_ERROR.  This is used by the components internally
    00136  * and should not be used by the application.
    00137  *
    00138  * Messages are in the following form:
    00139  * [LEVEL] (FILE:LINE_NUM) <comp_name> <message_content>
    00140  */
    00141 #define COMP_ERROR_MSG(str) ERROR_MSG("<" << comp_name << "> " << str)
    00142 /**
    00143  * Prints a category-specific (Component type) log message of level
    00144  * @c LOG_LEVEL_ERROR. This is used by the components internally and
    00145  * should not be used by the application.
    00146  *
    00147  * Messages are in the following form:
    00148  * [LEVEL] (FILE:LINE_NUM) <cat_name> <message_content>
    00149  */
    00150 #define CAT_ERROR_MSG(str) ERROR_MSG("<" CAT_NAME "> " << str)
    00151
    00152 /**
    00153  * Prints a system error log message of level @c LOG_LEVEL_ERROR with
    00154  * the string description of the errno value appended.
    00155  */
    00156 #define SYS_ERROR_MSG(str) ERROR_MSG(str << ": " << strerror(errno))
    00157 /**
    00158  * Prints a component-specific system error log message of level
    00159  * @c LOG_LEVEL_ERROR. This is used by the components internally and
    00160  * should not be used by the application.
    00161  *
    00162  * Messages are in the following form:
    00163  * [LEVEL] (FILE:LINE_NUM) <comp_name> <message_content>
    00164  */
    00165 #define COMP_SYS_ERROR_MSG(str) SYS_ERROR_MSG("<" << comp_name << "> " << str)
    00166 /**
    00167  * Prints a category-specific (Component type) system error log
    00168  * message of level @c LOG_LEVEL_ERROR. This is used by the components
    00169  * internally and should not be used by the application.
    00170  *
    00171  * Messages are in the following form:
    00172  * [LEVEL] (FILE:LINE_NUM) <cat_name> <message_content>
    00173  */
    00174 #define CAT_SYS_ERROR_MSG(str) SYS_ERROR_MSG("<" CAT_NAME "> " << str)
    00175
    00176 /**
    00177  * Prints a log message of level @c LOG_LEVEL_WARN.
    00178  */
    00179 #define WARN_MSG(str) PRINT_MSG(LOG_LEVEL_WARN, str)
    00180 /**
    00181  * Prints a component-specific log message of level @c LOG_LEVEL_WARN.
    00182  * This is used by the components internally and should not be used by
    00183  * the application.
    00184  *
    00185  * Messages are in the following form:
    00186  * [LEVEL] (FILE:LINE_NUM) <comp_name> <message_content>
    00187  */
    00188 #define COMP_WARN_MSG(str) WARN_MSG("<" << comp_name << "> :" << str)
    00189 /**
    00190  * Print a category-specific (Component type) log message of level
    00191  * @c LOG_LEVEL_WARN.
    00192  * This is used by the components internally and should not be used by the
    00193  * application.
    00194  *
    00195  * Messages are in the following form:
    00196  * [LEVEL] (FILE:LINE_NUM) <cat_name> <message_content>
    00197  */
    00198 #define CAT_WARN_MSG(str) WARN_MSG("<" CAT_NAME "> " << str)
    00199
    00200 /**
    00201  * Prints a log message of level @c LOG_LEVEL_DEBUG.
    00202  */
    00203 #define DEBUG_MSG(str) PRINT_MSG(LOG_LEVEL_DEBUG, str)
    00204 /**
    00205  * Prints a component-specific log message of level @c LOG_LEVEL_DEBUG.
    00206  * This is used by the components internally and should not be used by the
    00207  * application.
    00208  *
    00209  * Messages are in the following form:
    00210  * [LEVEL] (FILE:LINE_NUM) <comp_name> <message_content>
    00211  */
    00212 #define COMP_DEBUG_MSG(str) DEBUG_MSG("<" << comp_name << "> :" << str)
    00213 /**
    00214  * Prints a category-specific (Component type) log message of level
    00215  * @c LOG_LEVEL_DEBUG. This is used by the components internally and
    00216  * should not be used by the application.
    00217  *
    00218  * Messages are in the following form:
    00219  * [LEVEL] (FILE:LINE_NUM) <cat_name> <message_content>
    00220  */
    00221 #define CAT_DEBUG_MSG(str) DEBUG_MSG("<" CAT_NAME "> " << str)
    00222
    00223 #endif
    00224 /** @} */