libacfutils
A general purpose library of utility functions designed to make it easier to develop addons for the X-Plane flight simulator.
Loading...
Searching...
No Matches
log.h
Go to the documentation of this file.
1/*
2 * CDDL HEADER START
3 *
4 * This file and its contents are supplied under the terms of the
5 * Common Development and Distribution License ("CDDL"), version 1.0.
6 * You may only use this file in accordance with the terms of version
7 * 1.0 of the CDDL.
8 *
9 * A full copy of the text of the CDDL should have accompanied this
10 * source. A copy of the CDDL is also available via the Internet at
11 * http://www.illumos.org/license/CDDL.
12 *
13 * CDDL HEADER END
14 */
15/*
16 * Copyright 2023 Saso Kiselkov. All rights reserved.
17 */
32#ifndef _ACF_UTILS_LOG_H_
33#define _ACF_UTILS_LOG_H_
34
35#include <stdarg.h>
36
37#ifndef _LACF_WITHOUT_XPLM
38#include <XPLMUtilities.h>
39#endif
40
41#include "sysmacros.h"
42
43#ifdef __cplusplus
44extern "C" {
45#endif
46
47/*
48 * Before using any of the log_* functionality, be sure to properly
49 * initialize it and pass it a logging function!
50 */
51typedef void (*logfunc_t)(const char *);
52API_EXPORT void log_init(logfunc_t func, const char *prefix);
53API_EXPORT void log_fini(void);
54API_EXPORT logfunc_t log_get_logfunc(void);
55
56#ifndef _LACF_WITHOUT_XPLM
62UNUSED_ATTR static void
63log_xplm_cb(const char *str)
64{
65 XPLMDebugString(str);
66}
67#endif /* !defined(_LACF_WITHOUT_XPLM) */
68
69#if defined(__GNUC__) || defined(__clang__)
70#define BUILTIN_STRRCHR __builtin_strrchr
71#else /* !defined(__GNUC__) && !defined(__clang__) */
72#define BUILTIN_STRRCHR strrchr
73#endif /* !defined(__GNUC__) && !defined(__clang__) */
74
89#define log_basename(f) \
90 (BUILTIN_STRRCHR(f, '/') ? BUILTIN_STRRCHR(f, '/') + 1 : \
91 (BUILTIN_STRRCHR(f, '\\') ? BUILTIN_STRRCHR(f, '\\') + 1 : (f)))
112#define logMsg(...) \
113 log_impl(log_basename(__FILE__), __LINE__, __VA_ARGS__)
119#define logMsg_v(fmt, ap) \
120 log_impl_v(log_basename(__FILE__), __LINE__, (fmt), (ap))
121API_EXPORT void log_impl(const char *filename, int line,
122 PRINTF_FORMAT(const char *fmt), ...) PRINTF_ATTR(3);
123API_EXPORT void log_impl_v(const char *filename, int line, const char *fmt,
124 va_list ap);
125API_EXPORT void log_backtrace(int skip_frames);
126#if IBM
127API_EXPORT void log_backtrace_sw64(PCONTEXT ctx);
128#endif
129
130#ifdef __cplusplus
131}
132#endif
133
134#endif /* _ACF_UTILS_LOG_H_ */
#define UNUSED_ATTR
Definition core.h:95
static void log_xplm_cb(const char *str)
Definition log.h:63
void log_impl_v(const char *filename, int line, const char *fmt, va_list ap)
Definition log.c:153
void log_impl(const char *filename, int line, const char *fmt,...)
Definition log.c:140
void log_fini(void)
Definition log.c:115
void log_init(logfunc_t func, const char *prefix)
Definition log.c:97
void log_backtrace(int skip_frames)
Definition log.c:516
logfunc_t log_get_logfunc(void)
Definition log.c:130