File: logging.h

package info (click to toggle)
austin 3.7.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,444 kB
  • sloc: ansic: 8,622; python: 2,669; sh: 106; makefile: 54
file content (151 lines) | stat: -rw-r--r-- 3,916 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
// This file is part of "austin" which is released under GPL.
//
// See file LICENCE or go to http://www.gnu.org/licenses/ for full license
// details.
//
// Austin is a Python frame stack sampler for CPython.
//
// Copyright (c) 2018 Gabriele N. Tornetta <phoenix1987@gmail.com>.
// All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

#ifndef LOGGING_H
#define LOGGING_H

#ifdef TRACE
#define DEBUG
#endif

#include "argparse.h"
#include "austin.h"


#define META_HEAD "# "
#define META_SEP  ": "

#define NL {if (!pargs.binary) fputc('\n', pargs.output_file);}

#define meta(key, ...)                     \
  fputs(META_HEAD, pargs.output_file);     \
  fputs(key, pargs.output_file);           \
  fputs(META_SEP, pargs.output_file);      \
  fprintf(pargs.output_file, __VA_ARGS__); \
  NL;

#if defined __clang__
#define COMPILER "clang"
#define COMPILER_MAJOR __clang_major__
#define COMPILER_MINOR __clang_minor__
#define COMPILER_PATCH __clang_patchlevel__
#elif defined __MUSL__
#define COMPILER "musl-gcc"
#define COMPILER_MAJOR __GNUC__
#define COMPILER_MINOR __GNUC_MINOR__
#define COMPILER_PATCH __GNUC_PATCHLEVEL__
#elif defined __GNUC__
#define COMPILER "gcc"
#define COMPILER_MAJOR __GNUC__
#define COMPILER_MINOR __GNUC_MINOR__
#define COMPILER_PATCH __GNUC_PATCHLEVEL__
#elif defined _MSC_VER
#define COMPILER "msvc"
#define COMPILER_MAJOR _MSC_VER / 100
#define COMPILER_MINOR _MSC_VER % 100
#define COMPILER_PATCH _MSC_BUILD
#endif

#ifdef NATIVE
#define log_header() {                   \
  log_m("\033[1m              _   _      \033[0m");    \
  log_m("\033[1m __ _ _  _ __| |_(_)_ _  \033[0m");    \
  log_m("\033[1m/ _` | || (_-<  _| | ' \\ \033[0m");   \
  log_m("\033[1m\\__,_|\\_,_/__/\\__|_|_||_|\033[0m\033[31;1mp\033[0m \033[36;1m" VERSION "\033[0m [" COMPILER " %d.%d.%d]", COMPILER_MAJOR, COMPILER_MINOR, COMPILER_PATCH); \
  log_i("====[ AUSTINP ]===="); \
}
#else
#define log_header() {                   \
  log_m("\033[1m              _   _      \033[0m ");    \
  log_m("\033[1m __ _ _  _ __| |_(_)_ _  \033[0m");    \
  log_m("\033[1m/ _` | || (_-<  _| | ' \\ \033[0m");   \
  log_m("\033[1m\\__,_|\\_,_/__/\\__|_|_||_|\033[0m \033[36;1m" VERSION "\033[0m [" COMPILER " %d.%d.%d]", COMPILER_MAJOR, COMPILER_MINOR, COMPILER_PATCH); \
  log_i("====[ AUSTIN ]===="); \
}
#endif
#define log_footer() {}

/**
 * Initialise logger.
 *
 * This must be called before making any logging requests.
 */
void
logger_init(void);

/**
 * Log an entry at the various supported levels.
 */
void
log_f(const char *, ...);

void
log_e(const char *, ...);

void
log_w(const char *, ...);

void
log_i(const char *, ...);

void
log_m(const char *, ...);  // metrics


/**
 * Log indirect error.
 *
 * Messages logged this way are prepended with a symbol that indicates that
 * they are a consequence of the error right above. A root cause is then an
 * unprefixed error/fatal log entry.
 */
#define log_ie(msg) log_e("> " msg)


#ifdef DEBUG
void
log_d(const char *, ...);
#else
#define log_d(f, args...) {}
#endif

#ifdef TRACE
void
log_t(const char *, ...);
#else
#define log_t(f, args...) {}
#endif


/**
 * Close the logger.
 *
 * This should be called as soon as the logger is no longer required.
 */
void
logger_close(void);


void
log_meta_header(void);

#endif // LOGGING_H