logging.h 5.2 KB
Newer Older
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
/*
 * logging.h: internal logging and debugging
 *
 * Copyright (C) 2006-2008 Red Hat, Inc.
 *
 * 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
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
 *
 */

#ifndef __VIRTLOG_H_
#define __VIRTLOG_H_

#include "internal.h"

/*
 * If configured with --enable-debug=yes then library calls
 * are printed to stderr for debugging or to an appropriate channel
 * defined at runtime of from the libvirt daemon configuration file
 */
#ifdef ENABLE_DEBUG
33
#define VIR_DEBUG_INT(category, f, l, fmt,...)                             \
34
    virLogMessage(category, VIR_LOG_DEBUG, f, l, 0, fmt, __VA_ARGS__)
35 36 37 38 39
#else
#define VIR_DEBUG_INT(category, f, l, fmt,...) \
    do { } while (0)
#endif /* !ENABLE_DEBUG */

40
#define VIR_INFO_INT(category, f, l, fmt,...)                              \
41
    virLogMessage(category, VIR_LOG_INFO, f, l, 0, fmt, __VA_ARGS__)
42
#define VIR_WARN_INT(category, f, l, fmt,...)                              \
43
    virLogMessage(category, VIR_LOG_WARN, f, l, 0, fmt, __VA_ARGS__)
44
#define VIR_ERROR_INT(category, f, l, fmt,...)                             \
45
    virLogMessage(category, VIR_LOG_ERROR, f, l, 0, fmt, __VA_ARGS__)
46

47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#define VIR_DEBUG(fmt,...)                                                  \
        VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
#define VIR_DEBUG0(msg)                                                     \
        VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, "%s", msg)
#define VIR_INFO(fmt,...)                                                   \
        VIR_INFO_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
#define VIR_INFO0(msg)                                                      \
        VIR_INFO_INT("file." __FILE__, __func__, __LINE__, "%s", msg)
#define VIR_WARN(fmt,...)                                                   \
        VIR_WARN_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
#define VIR_WARN0(msg)                                                      \
        VIR_WARN_INT("file." __FILE__, __func__, __LINE__, "%s", msg)
#define VIR_ERROR(fmt,...)                                                  \
        VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
#define VIR_ERROR0(msg)                                                     \
        VIR_ERROR_INT("file." __FILE__, __func__, __LINE__, "%s", msg)

/* Legacy compat */
65
#define DEBUG(fmt,...)                                                  \
66
        VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, fmt, __VA_ARGS__)
67
#define DEBUG0(msg)                                                     \
68
        VIR_DEBUG_INT("file." __FILE__, __func__, __LINE__, "%s", msg)
D
Daniel Veillard 已提交
69 70 71 72 73 74 75 76 77 78 79

/*
 * To be made public
 */
typedef enum {
    VIR_LOG_DEBUG = 1,
    VIR_LOG_INFO,
    VIR_LOG_WARN,
    VIR_LOG_ERROR,
} virLogPriority;

80 81
#define VIR_LOG_DEFAULT VIR_LOG_WARN

D
Daniel Veillard 已提交
82 83 84 85
/**
 * virLogOutputFunc:
 * @category: the category for the message
 * @priority: the priority for the message
86 87
 * @funcname: the function emitting the message
 * @linenr: line where the message was emitted
D
Daniel Veillard 已提交
88 89
 * @msg: the message to log, preformatted and zero terminated
 * @len: the lenght of the message in bytes without the terminating zero
90
 * @data: extra output logging data
D
Daniel Veillard 已提交
91 92 93 94 95
 *
 * Callback function used to output messages
 *
 * Returns the number of bytes written or -1 in case of error
 */
96 97 98
typedef int (*virLogOutputFunc) (const char *category, int priority,
                                 const char *funcname, long long lineno,
                                 const char *str, int len, void *data);
D
Daniel Veillard 已提交
99 100 101 102 103 104 105 106 107

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

108 109 110
extern int virLogGetNbFilters(void);
extern int virLogGetNbOutputs(void);
extern int virLogGetDefaultPriority(void);
D
Daniel Veillard 已提交
111
extern int virLogSetDefaultPriority(int priority);
112
extern void virLogSetFromEnv(void);
D
Daniel Veillard 已提交
113 114 115 116 117 118 119
extern int virLogDefineFilter(const char *match, int priority, int flags);
extern int virLogDefineOutput(virLogOutputFunc f, virLogCloseFunc c,
                              void *data, int priority, int flags);

/*
 * Internal logging API
 */
120

D
Daniel Veillard 已提交
121 122 123
extern int virLogStartup(void);
extern int virLogReset(void);
extern void virLogShutdown(void);
124
extern int virLogParseDefaultPriority(const char *priority);
D
Daniel Veillard 已提交
125 126
extern int virLogParseFilters(const char *filters);
extern int virLogParseOutputs(const char *output);
127 128
extern void virLogMessage(const char *category, int priority,
                          const char *funcname, long long linenr, int flags,
129
                          const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(6, 7);
130 131

#endif