libaaruformat
1.0
Aaru Data Preservation Suite - Format Library
Toggle main menu visibility
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1
/*
2
* This file is part of the Aaru Data Preservation Suite.
3
* Copyright (c) 2019-2026 Natalia Portillo.
4
*
5
* This library is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU Lesser General Public License as
7
* published by the Free Software Foundation; either version 2.1 of the
8
* License, or (at your option) any later version.
9
*
10
* This library is distributed in the hope that it will be useful, but
11
* WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
* Lesser General Public License for more details.
14
*
15
* You should have received a copy of the GNU Lesser General Public
16
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
17
*/
18
19
#ifndef LIBAARUFORMAT_LOG_H
20
#define LIBAARUFORMAT_LOG_H
21
22
/*
23
* Internal debug logging.
24
*
25
* TRACE and FATAL compile to nothing unless ENABLE_TRACE / ENABLE_FATAL are defined
26
* (CMake: -DAARU_ENABLE_LOGGING=ON). When enabled, output goes to stderr unless the
27
* AARUFORMAT_LOG_FILE environment variable names a file to append to, and the
28
* AARUFORMAT_LOG_LEVEL environment variable (trace, fatal, none) filters it at runtime.
29
*
30
* Never log key material.
31
*/
32
33
#include <inttypes.h>
// PRIu64 and friends, used throughout log format strings
34
#include <stdarg.h>
35
#include <stdio.h>
36
37
#define AARU_LOG_FATAL 0
38
#define AARU_LOG_TRACE 1
39
40
#if defined(__GNUC__) || defined(__clang__)
41
#define AARU_LOG_PRINTF_ATTR __attribute__((format(printf, 5, 6)))
42
#if !defined(_WIN32) && !defined(__CYGWIN__)
43
#define AARU_LOG_VISIBILITY_ATTR __attribute__((visibility("hidden")))
44
#else
45
#define AARU_LOG_VISIBILITY_ATTR
46
#endif
47
#else
48
#define AARU_LOG_PRINTF_ATTR
49
#define AARU_LOG_VISIBILITY_ATTR
50
#endif
51
52
#ifdef __cplusplus
53
extern
"C"
{
54
#endif
55
56
void
aaru_log_write
(
int
level,
const
char
*file,
int
line,
const
char
*func,
const
char
*fmt,
57
...)
AARU_LOG_PRINTF_ATTR
AARU_LOG_VISIBILITY_ATTR
;
58
59
/* Closes any log file and forgets the configuration so the environment is read again. Used by tests. */
60
void
aaru_log_reset
(
void
)
AARU_LOG_VISIBILITY_ATTR
;
61
62
#ifdef __cplusplus
63
}
64
#endif
65
66
#ifdef ENABLE_TRACE
67
#define TRACE(fmt, ...) aaru_log_write(AARU_LOG_TRACE, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__)
68
#else
69
#define TRACE(fmt, ...) ((void)0)
70
#endif
71
72
#ifdef ENABLE_FATAL
73
#define FATAL(fmt, ...) aaru_log_write(AARU_LOG_FATAL, __FILE__, __LINE__, __func__, fmt, ##__VA_ARGS__)
74
#else
75
#define FATAL(fmt, ...) ((void)0)
76
#endif
77
78
#endif
// LIBAARUFORMAT_LOG_H
AARU_LOG_PRINTF_ATTR
#define AARU_LOG_PRINTF_ATTR
Definition
log.h:48
AARU_LOG_VISIBILITY_ATTR
#define AARU_LOG_VISIBILITY_ATTR
Definition
log.h:49
aaru_log_reset
void aaru_log_reset(void)
Definition
log.c:229
aaru_log_write
void aaru_log_write(int level, const char *file, int line, const char *func, const char *fmt,...)
Writes one log line.
Definition
log.c:173
include
log.h
Generated by
1.18.0