logging.h 5.4 KB
Newer Older
1 2 3
/*
 * logging.h: internal logging and debugging
 *
4
 * Copyright (C) 2006-2008, 2011-2012 Red Hat, Inc.
5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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; either
 * 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
17
 * License along with this library.  If not, see
O
Osier Yang 已提交
18
 * <http://www.gnu.org/licenses/>.
19 20 21 22
 *
 */

#ifndef __VIRTLOG_H_
23
# define __VIRTLOG_H_
24

25 26
# include "internal.h"
# include "buf.h"
27 28 29 30

/*
 * If configured with --enable-debug=yes then library calls
 * are printed to stderr for debugging or to an appropriate channel
31
 * defined at runtime from the libvirt daemon configuration file
32
 */
33
# ifdef ENABLE_DEBUG
34 35
#  define VIR_DEBUG_INT(category, f, l, ...)                            \
    virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, __VA_ARGS__)
36
# else
37 38 39 40 41 42 43 44 45 46
/**
 * virLogEatParams:
 *
 * Do nothing but eat parameters.
 */
static inline void virLogEatParams(const char *unused, ...)
{
    /* Silence gcc */
    unused = unused;
}
47
#  define VIR_DEBUG_INT(category, f, l, ...)    \
48
    virLogEatParams(category, f, l, __VA_ARGS__)
49
# endif /* !ENABLE_DEBUG */
50

51 52 53 54 55 56
# define VIR_INFO_INT(category, f, l, ...)                              \
    virLogMessage(category, VIR_LOG_INFO, f, l, 0, __VA_ARGS__)
# define VIR_WARN_INT(category, f, l, ...)                              \
    virLogMessage(category, VIR_LOG_WARN, f, l, 0, __VA_ARGS__)
# define VIR_ERROR_INT(category, f, l, ...)                             \
    virLogMessage(category, VIR_LOG_ERROR, f, l, 0, __VA_ARGS__)
57

58 59 60 61 62 63 64 65
# define VIR_DEBUG(...)                                                 \
        VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
# define VIR_INFO(...)                                                  \
        VIR_INFO_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
# define VIR_WARN(...)                                                  \
        VIR_WARN_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
# define VIR_ERROR(...)                                                 \
        VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, __VA_ARGS__)
66

D
Daniel Veillard 已提交
67 68 69 70 71 72 73 74 75 76
/*
 * To be made public
 */
typedef enum {
    VIR_LOG_DEBUG = 1,
    VIR_LOG_INFO,
    VIR_LOG_WARN,
    VIR_LOG_ERROR,
} virLogPriority;

77
# define VIR_LOG_DEFAULT VIR_LOG_WARN
78

79 80 81 82 83 84
typedef enum {
    VIR_LOG_TO_STDERR = 1,
    VIR_LOG_TO_SYSLOG,
    VIR_LOG_TO_FILE,
} virLogDestination;

D
Daniel Veillard 已提交
85 86 87 88
/**
 * virLogOutputFunc:
 * @category: the category for the message
 * @priority: the priority for the message
89 90
 * @funcname: the function emitting the message
 * @linenr: line where the message was emitted
91
 * @timestamp: zero terminated string with timestamp of the message
92
 * @flags: flags associated with the message
93
 * @rawstr: the unformatted message to log, zero terminated
94
 * @str: the message to log, preformatted and zero terminated
95
 * @data: extra output logging data
D
Daniel Veillard 已提交
96 97 98
 *
 * Callback function used to output messages
 */
99
typedef void (*virLogOutputFunc) (const char *category, virLogPriority priority,
100
                                  const char *funcname, int linenr,
101 102
                                  const char *timestamp,
                                  unsigned int flags,
103
                                  const char *rawstr, const char *str,
104
                                  void *data);
D
Daniel Veillard 已提交
105 106 107 108 109 110 111 112 113

/**
 * virLogCloseFunc:
 * @data: extra output logging data
 *
 * Callback function used to close a log output
 */
typedef void (*virLogCloseFunc) (void *data);

114 115 116 117
typedef enum {
    VIR_LOG_STACK_TRACE = (1 << 0),
} virLogFlags;

118 119
extern int virLogGetNbFilters(void);
extern int virLogGetNbOutputs(void);
120 121
extern char *virLogGetFilters(void);
extern char *virLogGetOutputs(void);
122 123
extern virLogPriority virLogGetDefaultPriority(void);
extern int virLogSetDefaultPriority(virLogPriority priority);
124
extern void virLogSetFromEnv(void);
125
extern int virLogDefineFilter(const char *match, virLogPriority priority,
126
                              unsigned int flags);
127
extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c, void *data,
128
                              virLogPriority priority, virLogDestination dest, const char *name,
129
                              unsigned int flags);
D
Daniel Veillard 已提交
130 131 132 133

/*
 * Internal logging API
 */
134

135 136
extern void virLogLock(void);
extern void virLogUnlock(void);
D
Daniel Veillard 已提交
137
extern int virLogReset(void);
138
extern int virLogParseDefaultPriority(const char *priority);
D
Daniel Veillard 已提交
139 140
extern int virLogParseFilters(const char *filters);
extern int virLogParseOutputs(const char *output);
141
extern void virLogMessage(const char *category, virLogPriority priority,
142
                          const char *funcname, int linenr,
143
                          unsigned int flags,
144
                          const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7);
145
extern void virLogVMessage(const char *category, virLogPriority priority,
146
                           const char *funcname, int linenr,
147 148 149
                           unsigned int flags,
                           const char *fmt,
                           va_list vargs) ATTRIBUTE_FMT_PRINTF(6, 0);
150
extern int virLogSetBufferSize(int size);
151
extern void virLogEmergencyDumpAll(int signum);
152
#endif