| 1 |
/* Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved. |
| 2 |
* |
| 3 |
* Redistribution and use in source and binary forms, with or without |
| 4 |
* modification, are permitted provided that the following conditions |
| 5 |
* are met: |
| 6 |
* * Redistributions of source code must retain the above copyright |
| 7 |
* notice, this list of conditions and the following disclaimer. |
| 8 |
* * Redistributions in binary form must reproduce the above copyright |
| 9 |
* notice, this list of conditions and the following disclaimer in the |
| 10 |
* documentation and/or other materials provided with the distribution. |
| 11 |
* * Neither the name of NVIDIA CORPORATION nor the names of its |
| 12 |
* contributors may be used to endorse or promote products derived |
| 13 |
* from this software without specific prior written permission. |
| 14 |
* |
| 15 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY |
| 16 |
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 17 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 |
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
| 19 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 20 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 22 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 23 |
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 25 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 |
*/ |
| 27 |
|
| 28 |
#ifndef _NVMEDIA_TEST_LOG_UTILS_H_ |
| 29 |
#define _NVMEDIA_TEST_LOG_UTILS_H_ |
| 30 |
|
| 31 |
#ifdef __cplusplus |
| 32 |
extern "C" { |
| 33 |
#endif |
| 34 |
|
| 35 |
#include <stdarg.h> |
| 36 |
#include <stdio.h> |
| 37 |
|
| 38 |
enum LogLevel { |
| 39 |
LEVEL_ERR = 0, |
| 40 |
LEVEL_WARN = 1, |
| 41 |
LEVEL_INFO = 2, |
| 42 |
LEVEL_DBG = 3, |
| 43 |
}; |
| 44 |
|
| 45 |
enum LogStyle { |
| 46 |
LOG_STYLE_NORMAL = 0, |
| 47 |
LOG_STYLE_FUNCTION_LINE |
| 48 |
}; |
| 49 |
|
| 50 |
#define LINE_INFO __FUNCTION__, __LINE__ |
| 51 |
#define LOG_DBG(...) LogLevelMessage(LEVEL_DBG, LINE_INFO, __VA_ARGS__) |
| 52 |
#define LOG_INFO(...) LogLevelMessage(LEVEL_INFO, LINE_INFO, __VA_ARGS__) |
| 53 |
#define LOG_WARN(...) LogLevelMessage(LEVEL_WARN, LINE_INFO, __VA_ARGS__) |
| 54 |
|
| 55 |
// SetLogLevel |
| 56 |
// |
| 57 |
// SetLogLevel() Set logging level |
| 58 |
// |
| 59 |
// Arguments: |
| 60 |
// |
| 61 |
// level |
| 62 |
// (in) Logging level |
| 63 |
|
| 64 |
void |
| 65 |
SetLogLevel( |
| 66 |
enum LogLevel level); |
| 67 |
|
| 68 |
// SetLogStyle |
| 69 |
// |
| 70 |
// SetLogStyle() Set logging print slyle |
| 71 |
// |
| 72 |
// Arguments: |
| 73 |
// |
| 74 |
// level |
| 75 |
// (in) Logging style |
| 76 |
|
| 77 |
void |
| 78 |
SetLogStyle( |
| 79 |
enum LogStyle style); |
| 80 |
|
| 81 |
// SetLogFile |
| 82 |
// |
| 83 |
// SetLogFile() Set logging file handle |
| 84 |
// |
| 85 |
// Arguments: |
| 86 |
// |
| 87 |
// level |
| 88 |
// (in) Logging file handle |
| 89 |
|
| 90 |
void |
| 91 |
SetLogFile( |
| 92 |
FILE *logFileHandle); |
| 93 |
|
| 94 |
// LogLevelMessage |
| 95 |
// |
| 96 |
// LogLevelMessage() Print message if logging level is higher than message level |
| 97 |
// |
| 98 |
// Arguments: |
| 99 |
// |
| 100 |
// LogLevel |
| 101 |
// (in) Message level |
| 102 |
// |
| 103 |
// format |
| 104 |
// (in) Message format |
| 105 |
// |
| 106 |
// ... |
| 107 |
// (in) Parameters list |
| 108 |
|
| 109 |
void |
| 110 |
LogLevelMessage( |
| 111 |
enum LogLevel level, |
| 112 |
const char *functionName, |
| 113 |
int lineNumber, |
| 114 |
const char *format, |
| 115 |
...); |
| 116 |
|
| 117 |
#ifdef __cplusplus |
| 118 |
} |
| 119 |
#endif |
| 120 |
|
| 121 |
#endif /* _NVMEDIA_TEST_LOG_UTILS_H_ */ |