1 //**********************************************************************;
2 // Copyright (c) 2017, Intel Corporation
3 // All rights reserved.
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
15 // 3. Neither the name of Intel Corporation nor the names of its contributors
16 // may be used to endorse or promote products derived from this software without
17 // specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29 // THE POSSIBILITY OF SUCH DAMAGE.
30 //**********************************************************************;
37 #include <tss2/tss2_sys.h>
39 #include "tpm2_error.h"
40 #include "tpm2_util.h"
42 typedef enum log_level log_level;
49 void _log (log_level level, const char *file, unsigned lineno, const char *fmt, ...)
50 COMPILER_ATTR(format (printf, 4, 5));
53 * Prints an error message. The fmt and variadic arguments mirror printf.
55 * Use this to log all error conditions.
57 #define LOG_ERR(fmt, ...) _log(log_level_error, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
60 * Prints an error message for a TSS2_Sys call to the TPM.
61 * The format is <function-name>(0x<rc>) - <error string>
63 * The function that caused the error
65 * The return code to print.
67 #define LOG_PERR(func, rc) _LOG_PERR(xstr(func), rc)
72 * Handles the expanded LOG_PERR call checking argument values
73 * and handing them off to LOG_ERR.
79 static inline void _LOG_PERR(const char *func, TSS2_RC rc) {
81 LOG_ERR("%s(0x%X) - %s", func, rc, tpm2_error_str(rc));
85 * Prints an warning message. The fmt and variadic arguments mirror printf.
87 * Use this to log a warning. A warning is when something is wrong, but it is not a fatal
90 #define LOG_WARN(fmt, ...) _log(log_level_warning, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
93 * Prints an informational message. The fmt and variadic arguments mirror printf.
95 * Informational messages are only shown when verboseness is increased. Valid messages
96 * would be debugging type messages where additional, extraneous information is printed.
98 #define LOG_INFO(fmt, ...) _log(log_level_verbose, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
101 * Sets the log level so only messages <= to it print.
103 * The logging level to set.
105 void log_set_level (log_level level);
107 #endif /* SRC_LOG_H_ */