Anklang 0.3.0-460-gc4ef46ba
ASE — Anklang Sound Engine (C++)

« « « Anklang Documentation
Loading...
Searching...
No Matches
logging.hh
Go to the documentation of this file.
1 // This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
2#pragma once
3
4#include <ase/formatter.hh>
5#include <source_location>
6
7namespace Ase {
8
10struct LogFormat {
11 std::source_location location;
12 const char *const cstr = nullptr;
14 location (l),
15 cstr (s)
16 {}
17};
18
21
23template<class... A> void log (const LogFormat &format, const A &...args);
24
26enum LogFlags { LOG_FILE = 1, LOG_STDERR = 2, LOG_LOCATIONS = 4, };
27
29LogFlags log_setup (int *logfd);
30
31// Keep natural logarithmic function available
32#ifdef _MATH_H
33using ::log;
34#endif
35
36// == implementations ==
37void logmsg (const std::string &msg, const char *file, uint64_t columnline, const char *func);
38
39template<class... A> __attribute__ ((__noinline__)) void
40logfmt (const char *file, uint64_t columnline, const char *func, const char *format, const A &...args)
41{
42 logmsg (string_format (format, args...), file, columnline, func);
43}
44
45template<class... A> __attribute__ ((__always_inline__)) inline void
46log (const LogFormat &format, const A &...args)
47{
48 logfmt (format.location.file_name(),
49 uint64_t (format.location.column()) << 32 | uint32_t (format.location.line()),
50 format.location.function_name(),
51 format.cstr, args...);
52}
53
54} // Ase
T current(T... args)
log
The Anklang C++ API namespace.
Definition api.hh:9
std::string string_format(const char *format, const Args &...args) __attribute__((__format__(__printf__
Format a string similar to sprintf(3) with support for std::string and std::ostringstream convertible...
LogFlags
Flags to configure logging behaviour.
Definition logging.hh:26
LogFlags log_setup(int *) __attribute__((__weak__))
Configurable handler to open log files.
Definition main.cc:152
uint64_t timestamp_now()
Current time in µseconds.
Definition logging.cc:14
typedef uint64_t
Wrap a string together with its source code location.
Definition logging.hh:10