Wire Sysio
Wire Sysion 1.0.0
Loading...
Searching...
No Matches
debug.h
Go to the documentation of this file.
1
/*
2
* Copyright 2015-2018 Yubico AB
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*/
16
17
#ifndef DEBUG_H
18
#define DEBUG_H
19
20
#include <sys/time.h>
21
#include <time.h>
22
23
#ifdef __linux__
24
#define ANSI_RED "\x1b[31m"
25
#define ANSI_GREEN "\x1b[32m"
26
#define ANSI_YELLOW "\x1b[33m"
27
#define ANSI_BLUE "\x1b[34m"
28
#define ANSI_MAGENTA "\x1b[35m"
29
#define ANSI_CYAN "\x1b[36m"
30
#define ANSI_RESET "\x1b[0m"
31
#else
32
#define ANSI_RED ""
33
#define ANSI_GREEN ""
34
#define ANSI_YELLOW ""
35
#define ANSI_BLUE ""
36
#define ANSI_MAGENTA ""
37
#define ANSI_CYAN ""
38
#define ANSI_RESET ""
39
#endif
40
41
#define __FILENAME__ \
42
(strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__)
43
44
#define D(var, file, col, who, lev, ...) \
45
if (var) { \
46
struct timeval _tv; \
47
struct tm _tm; \
48
char _tbuf[20]; \
49
time_t _tsecs; \
50
gettimeofday(&_tv, NULL); \
51
_tsecs = _tv.tv_sec; \
52
localtime_r(&_tsecs, &_tm); \
53
strftime(_tbuf, 20, "%H:%M:%S", &_tm); \
54
fprintf(file, "[" col who " - " lev ANSI_RESET " %s.%06ld] ", _tbuf, \
55
(long) _tv.tv_usec); \
56
fprintf(file, "%s:%d (%s): ", __FILENAME__, __LINE__, __func__); \
57
fprintf(file, __VA_ARGS__); \
58
}
59
60
#define DLN(var, file, col, who, lev, ...) \
61
if (var) { \
62
D(var, file, col, who, lev, __VA_ARGS__); \
63
fprintf(file, "\n"); \
64
}
65
66
#endif
libraries
yubihsm
common
debug.h
Generated by
1.12.0