File: grl-log.h

package info (click to toggle)
grilo 0.3.13-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 2,136 kB
  • sloc: ansic: 18,643; xml: 2,260; python: 701; makefile: 18
file content (285 lines) | stat: -rw-r--r-- 7,707 bytes parent folder | download | duplicates (8)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
/*
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wtay@chello.be>
 *                    2003 Benjamin Otte <in7y118@public.uni-hamburg.de>
 *                    2010 Igalia S.L.
 *                    2010 Intel Corporation
 *
 * Contact: Iago Toral Quiroga <itoral@igalia.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation; version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This library 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 *
 * Part of this code has been adapted from GStreamer gst/gstinfo.h
 */

#if !defined (_GRILO_H_INSIDE_) && !defined (GRILO_COMPILATION)
#error "Only <grilo.h> can be included directly."
#endif

#ifndef _GRL_LOG_H_
#define _GRL_LOG_H_

#include <glib.h>

G_BEGIN_DECLS

/**
 * GrlLogLevel:
 * @GRL_LOG_LEVEL_NONE: Log level none
 * @GRL_LOG_LEVEL_ERROR: Log on error
 * @GRL_LOG_LEVEL_WARNING: Log on warning
 * @GRL_LOG_LEVEL_MESSAGE: Log on message
 * @GRL_LOG_LEVEL_INFO: Log on info
 * @GRL_LOG_LEVEL_DEBUG: Log on debug
 * @GRL_LOG_LEVEL_LAST: Last level of log
 *
 * Grilo log levels. Defines the level of verbosity selected in Grilo.
 */
typedef enum {
  GRL_LOG_LEVEL_NONE,
  GRL_LOG_LEVEL_ERROR,
  GRL_LOG_LEVEL_WARNING,
  GRL_LOG_LEVEL_MESSAGE,
  GRL_LOG_LEVEL_INFO,
  GRL_LOG_LEVEL_DEBUG,

  GRL_LOG_LEVEL_LAST
} GrlLogLevel;

/* Opaque type */
typedef struct _GrlLogDomain GrlLogDomain;

extern GrlLogDomain *GRL_LOG_DOMAIN_DEFAULT;

/**
 * GRL_LOG_DOMAIN:
 * @domain: the log domain
 *
 * Defines a GrlLogDomain variable.
 */
#define GRL_LOG_DOMAIN(domain) GrlLogDomain *domain = NULL

/**
 * GRL_LOG_DOMAIN_EXTERN:
 * @domain: the log domain
 *
 * Declares a GrlLogDomain variable as extern. Use in header files.
 */
#define GRL_LOG_DOMAIN_EXTERN(domain) extern GrlLogDomain *domain

/**
 * GRL_LOG_DOMAIN_STATIC:
 * @domain: the log domain
 *
 * Defines a static GrlLogDomain variable.
 */
#define GRL_LOG_DOMAIN_STATIC(domain) static GrlLogDomain *domain = NULL

/**
 * GRL_LOG_DOMAIN_INIT:
 * @domain: the log domain to initialize.
 * @name: the name of the log domain.
 *
 * Creates a new #GrlLogDomain with the given name.
 */
#define GRL_LOG_DOMAIN_INIT(domain, name) G_STMT_START { \
  if (domain == NULL)                                    \
    domain = grl_log_domain_new (name);                  \
} G_STMT_END

/**
 * GRL_LOG_DOMAIN_FREE:
 * @domain: the log domain to free.
 *
 * Free a previously allocated #GrlLogDomain.
 */
#define GRL_LOG_DOMAIN_FREE(domain) G_STMT_START {  \
  grl_log_domain_free (domain);                     \
  domain = NULL;                                    \
} G_STMT_END

/**
 * GRL_LOG:
 * @domain: the log domain to use
 * @level: the severity of the message
 * @...: A printf-style message to output
 *
 * Outputs a debugging message. This is the most general macro for outputting
 * debugging messages. You will probably want to use one of the ones described
 * below.
 */
#ifdef G_HAVE_ISO_VARARGS

#define GRL_LOG(domain, level, ...) G_STMT_START{       \
    grl_log ((domain), (level), G_STRLOC, __VA_ARGS__); \
}G_STMT_END

#elif G_HAVE_GNUC_VARARGS

#define GRL_LOG(domain, level, args...) G_STMT_START{ \
    grl_log ((domain), (level), G_STRLOC, ##args);    \
}G_STMT_END

#else /* no variadic macros, use inline */

static inline void
GRL_LOG_valist (GrlLogDomain *domain,
                GrlLogLevel   level,
                const char   *format,
                va_list       varargs)
{
  grl_log (domain, level, "", format, varargs);
}

static inline void
GRL_LOG (GrlLogDomain *domain,
         GrlLogLevel   level,
         const char   *format,
         ...)
{
  va_list varargs;

  va_start (varargs, format);
  GRL_LOG_DOMAIN_LOG_valist (domain, level, format, varargs);
  va_end (varargs);
}

#endif /* G_HAVE_ISO_VARARGS */

/**
 * GRL_ERROR:
 * @...: printf-style message to output
 *
 * Output an error message in the default log domain.
 */
/**
 * GRL_WARNING:
 * @...: printf-style message to output
 *
 * Output a warning message in the default log domain.
 */
/**
 * GRL_MESSAGE:
 * @...: printf-style message to output
 *
 * Output a logging message in the default log domain.
 */
/**
 * GRL_INFO:
 * @...: printf-style message to output
 *
 * Output an informational message in the default log domain.
 */
/**
 * GRL_DEBUG:
 * @...: printf-style message to output
 *
 * Output a debugging message in the default log domain.
 */

#if G_HAVE_ISO_VARARGS

#define GRL_ERROR(...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_ERROR, __VA_ARGS__)
#define GRL_WARNING(...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_WARNING, __VA_ARGS__)
#define GRL_MESSAGE(...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_MESSAGE, __VA_ARGS__)
#define GRL_INFO(...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_INFO, __VA_ARGS__)
#define GRL_DEBUG(...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_DEBUG, __VA_ARGS__)

#elif G_HAVE_GNUC_VARARGS

#define GRL_ERROR(args...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_ERROR, ##args)
#define GRL_WARNING(args...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_WARNING, ##args)
#define GRL_MESSAGE(args...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_MESSAGE, ##args)
#define GRL_INFO(args...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_INFO, ##args)
#define GRL_DEBUG(args...) \
  GRL_LOG (GRL_LOG_DOMAIN_DEFAULT, GRL_LOG_LEVEL_DEBUG, ##args)

#else /* no variadic macros, use inline */

static inline void
GRL_ERROR (GrlLogDomain *domain, const char *format, ...)
{
  va_list varargs;

  va_start (varargs, format);
  GRL_LOG_valist (domain, GRL_LOG_LEVEL_ERROR, format, varargs);
  va_end (varargs);
}

static inline void
GRL_WARNING (GrlLogDomain *domain, const char *format, ...)
{
  va_list varargs;

  va_start (varargs, format);
  GRL_LOG_valist (domain, GRL_LOG_LEVEL_WARNING, format, varargs);
  va_end (varargs);
}

static inline void
GRL_MESSAGE (GrlLogDomain *domain, const char *format, ...)
{
  va_list varargs;

  va_start (varargs, format);
  GRL_LOG_valist (domain, GRL_LOG_LEVEL_MESSAGE, format, varargs);
  va_end (varargs);
}

static inline void
GRL_INFO (GrlLogDomain *domain, const char *format, ...)
{
  va_list varargs;

  va_start (varargs, format);
  GRL_LOG_valist (domain, GRL_LOG_LEVEL_INFO, format, varargs);
  va_end (varargs);
}

static inline void
GRL_DEBUG (GrlLogDomain *domain, const char *format, ...)
{
  va_list varargs;

  va_start (varargs, format);
  GRL_LOG_valist (domain, GRL_LOG_LEVEL_DEBUG, format, varargs);
  va_end (varargs);
}

#endif /* G_HAVE_ISO_VARARGS */

GrlLogDomain *  grl_log_domain_new    (const gchar *name);
void            grl_log_domain_free   (GrlLogDomain *domain);

void            grl_log_configure     (const gchar  *config);
void            grl_log               (GrlLogDomain *domain,
                                       GrlLogLevel   level,
                                       const gchar  *strloc,
                                       const gchar  *format,
                                       ...) G_GNUC_PRINTF (4, 5) G_GNUC_NO_INSTRUMENT;

G_END_DECLS

#endif /* _GRL_LOG_H_ */