2008-11-06 16:36:07 +00:00
|
|
|
/*
|
|
|
|
* logging.h: internal logging and debugging
|
|
|
|
*
|
2012-07-13 07:50:04 +00:00
|
|
|
* Copyright (C) 2006-2008, 2011-2012 Red Hat, Inc.
|
2008-11-06 16:36:07 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2008-11-06 16:36:07 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIRTLOG_H_
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIRTLOG_H_
|
2008-11-06 16:36:07 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include "internal.h"
|
|
|
|
# include "buf.h"
|
2008-11-06 16:36:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If configured with --enable-debug=yes then library calls
|
|
|
|
* are printed to stderr for debugging or to an appropriate channel
|
2011-02-16 23:37:57 +00:00
|
|
|
* defined at runtime from the libvirt daemon configuration file
|
2008-11-06 16:36:07 +00:00
|
|
|
*/
|
2010-03-09 18:22:22 +00:00
|
|
|
# ifdef ENABLE_DEBUG
|
2012-09-27 13:28:44 +00:00
|
|
|
# define VIR_DEBUG_INT(category, filename, linenr, funcname, ...) \
|
|
|
|
virLogMessage(category, VIR_LOG_DEBUG, filename, linenr, funcname, 0, __VA_ARGS__)
|
2010-03-09 18:22:22 +00:00
|
|
|
# else
|
2012-07-13 07:50:04 +00:00
|
|
|
/**
|
|
|
|
* virLogEatParams:
|
|
|
|
*
|
|
|
|
* Do nothing but eat parameters.
|
|
|
|
*/
|
|
|
|
static inline void virLogEatParams(const char *unused, ...)
|
|
|
|
{
|
|
|
|
/* Silence gcc */
|
|
|
|
unused = unused;
|
|
|
|
}
|
2012-09-27 13:28:44 +00:00
|
|
|
# define VIR_DEBUG_INT(category, filename, linenr, funcname, ...) \
|
|
|
|
virLogEatParams(category, filename, linenr, funcname, __VA_ARGS__)
|
2010-03-09 18:22:22 +00:00
|
|
|
# endif /* !ENABLE_DEBUG */
|
2009-06-26 15:08:04 +00:00
|
|
|
|
2012-09-27 13:28:44 +00:00
|
|
|
# define VIR_INFO_INT(category, filename, linenr, funcname, ...) \
|
|
|
|
virLogMessage(category, VIR_LOG_INFO, filename, linenr, funcname, 0, __VA_ARGS__)
|
|
|
|
# define VIR_WARN_INT(category, filename, linenr, funcname, ...) \
|
|
|
|
virLogMessage(category, VIR_LOG_WARN, filename, linenr, funcname, 0, __VA_ARGS__)
|
|
|
|
# define VIR_ERROR_INT(category, filename, linenr, funcname, ...) \
|
|
|
|
virLogMessage(category, VIR_LOG_ERROR, filename, linenr, funcname, 0, __VA_ARGS__)
|
2008-11-06 16:36:07 +00:00
|
|
|
|
2011-05-11 19:24:50 +00:00
|
|
|
# define VIR_DEBUG(...) \
|
2012-09-27 13:28:44 +00:00
|
|
|
VIR_DEBUG_INT("file", __FILE__, __LINE__, __func__, __VA_ARGS__)
|
2011-05-11 19:24:50 +00:00
|
|
|
# define VIR_INFO(...) \
|
2012-09-27 13:28:44 +00:00
|
|
|
VIR_INFO_INT("file", __FILE__, __LINE__, __func__, __VA_ARGS__)
|
2011-05-11 19:24:50 +00:00
|
|
|
# define VIR_WARN(...) \
|
2012-09-27 13:28:44 +00:00
|
|
|
VIR_WARN_INT("file", __FILE__, __LINE__, __func__, __VA_ARGS__)
|
2011-05-11 19:24:50 +00:00
|
|
|
# define VIR_ERROR(...) \
|
2012-09-27 13:28:44 +00:00
|
|
|
VIR_ERROR_INT("file", __FILE__, __LINE__, __func__, __VA_ARGS__)
|
2009-01-06 18:32:03 +00:00
|
|
|
|
2008-12-22 10:36:54 +00:00
|
|
|
/*
|
|
|
|
* To be made public
|
|
|
|
*/
|
|
|
|
typedef enum {
|
|
|
|
VIR_LOG_DEBUG = 1,
|
|
|
|
VIR_LOG_INFO,
|
|
|
|
VIR_LOG_WARN,
|
|
|
|
VIR_LOG_ERROR,
|
|
|
|
} virLogPriority;
|
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# define VIR_LOG_DEFAULT VIR_LOG_WARN
|
2009-07-01 11:21:15 +00:00
|
|
|
|
2009-10-08 15:05:01 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_LOG_TO_STDERR = 1,
|
|
|
|
VIR_LOG_TO_SYSLOG,
|
|
|
|
VIR_LOG_TO_FILE,
|
|
|
|
} virLogDestination;
|
|
|
|
|
2008-12-22 10:36:54 +00:00
|
|
|
/**
|
|
|
|
* virLogOutputFunc:
|
|
|
|
* @category: the category for the message
|
|
|
|
* @priority: the priority for the message
|
2008-12-22 10:44:10 +00:00
|
|
|
* @funcname: the function emitting the message
|
|
|
|
* @linenr: line where the message was emitted
|
2011-09-28 13:20:07 +00:00
|
|
|
* @timestamp: zero terminated string with timestamp of the message
|
2012-05-09 14:18:56 +00:00
|
|
|
* @flags: flags associated with the message
|
2012-09-27 11:45:33 +00:00
|
|
|
* @rawstr: the unformatted message to log, zero terminated
|
2011-09-28 13:20:07 +00:00
|
|
|
* @str: the message to log, preformatted and zero terminated
|
2008-12-22 10:44:10 +00:00
|
|
|
* @data: extra output logging data
|
2008-12-22 10:36:54 +00:00
|
|
|
*
|
|
|
|
* Callback function used to output messages
|
|
|
|
*/
|
2012-09-27 13:14:01 +00:00
|
|
|
typedef void (*virLogOutputFunc) (const char *category,
|
|
|
|
virLogPriority priority,
|
2012-09-27 13:28:44 +00:00
|
|
|
const char *filename,
|
2012-09-27 13:14:01 +00:00
|
|
|
int linenr,
|
2012-09-27 13:28:44 +00:00
|
|
|
const char *funcname,
|
2012-09-20 18:24:00 +00:00
|
|
|
const char *timestamp,
|
|
|
|
unsigned int flags,
|
2012-09-27 13:14:01 +00:00
|
|
|
const char *rawstr,
|
|
|
|
const char *str,
|
2012-09-20 18:24:00 +00:00
|
|
|
void *data);
|
2008-12-22 10:36:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* virLogCloseFunc:
|
|
|
|
* @data: extra output logging data
|
|
|
|
*
|
|
|
|
* Callback function used to close a log output
|
|
|
|
*/
|
|
|
|
typedef void (*virLogCloseFunc) (void *data);
|
|
|
|
|
2012-05-09 14:18:56 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_LOG_STACK_TRACE = (1 << 0),
|
|
|
|
} virLogFlags;
|
|
|
|
|
2009-08-06 13:45:50 +00:00
|
|
|
extern int virLogGetNbFilters(void);
|
|
|
|
extern int virLogGetNbOutputs(void);
|
2009-10-08 15:05:01 +00:00
|
|
|
extern char *virLogGetFilters(void);
|
|
|
|
extern char *virLogGetOutputs(void);
|
2012-09-27 12:58:58 +00:00
|
|
|
extern virLogPriority virLogGetDefaultPriority(void);
|
|
|
|
extern int virLogSetDefaultPriority(virLogPriority priority);
|
2009-08-06 13:55:07 +00:00
|
|
|
extern void virLogSetFromEnv(void);
|
2012-09-27 13:14:01 +00:00
|
|
|
extern int virLogDefineFilter(const char *match,
|
|
|
|
virLogPriority priority,
|
2011-07-06 22:29:02 +00:00
|
|
|
unsigned int flags);
|
2012-09-27 13:14:01 +00:00
|
|
|
extern int virLogDefineOutput(virLogOutputFunc f,
|
|
|
|
virLogCloseFunc c,
|
|
|
|
void *data,
|
|
|
|
virLogPriority priority,
|
|
|
|
virLogDestination dest,
|
|
|
|
const char *name,
|
2011-07-06 22:29:02 +00:00
|
|
|
unsigned int flags);
|
2008-12-22 10:36:54 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Internal logging API
|
|
|
|
*/
|
2008-11-06 16:36:07 +00:00
|
|
|
|
2010-02-03 16:12:57 +00:00
|
|
|
extern void virLogLock(void);
|
|
|
|
extern void virLogUnlock(void);
|
2008-12-22 10:36:54 +00:00
|
|
|
extern int virLogReset(void);
|
2009-08-06 13:55:07 +00:00
|
|
|
extern int virLogParseDefaultPriority(const char *priority);
|
2008-12-22 10:36:54 +00:00
|
|
|
extern int virLogParseFilters(const char *filters);
|
|
|
|
extern int virLogParseOutputs(const char *output);
|
2012-09-27 13:14:01 +00:00
|
|
|
extern void virLogMessage(const char *category,
|
|
|
|
virLogPriority priority,
|
2012-09-27 13:28:44 +00:00
|
|
|
const char *filename,
|
2012-09-27 13:14:01 +00:00
|
|
|
int linenr,
|
2012-09-27 13:28:44 +00:00
|
|
|
const char *funcname,
|
2011-07-06 22:29:02 +00:00
|
|
|
unsigned int flags,
|
2012-09-27 13:28:44 +00:00
|
|
|
const char *fmt, ...) ATTRIBUTE_FMT_PRINTF(7, 8);
|
2012-09-27 13:14:01 +00:00
|
|
|
extern void virLogVMessage(const char *category,
|
|
|
|
virLogPriority priority,
|
2012-09-27 13:28:44 +00:00
|
|
|
const char *filename,
|
2012-09-27 13:14:01 +00:00
|
|
|
int linenr,
|
2012-09-27 13:28:44 +00:00
|
|
|
const char *funcname,
|
2012-01-23 14:57:16 +00:00
|
|
|
unsigned int flags,
|
|
|
|
const char *fmt,
|
2012-09-27 13:28:44 +00:00
|
|
|
va_list vargs) ATTRIBUTE_FMT_PRINTF(7, 0);
|
2011-03-08 10:31:20 +00:00
|
|
|
extern int virLogSetBufferSize(int size);
|
2011-03-03 08:32:18 +00:00
|
|
|
extern void virLogEmergencyDumpAll(int signum);
|
2008-11-06 16:36:07 +00:00
|
|
|
#endif
|