2
$Id: logging.c,v 1.1 2004/12/18 17:29:32 rocky Exp $
4
Copyright (C) 2000 Herbert Valerio Riedel <hvr@gnu.org>
5
Copyright (C) 2003, 2004 Rocky Bernstein <rocky@panix.com>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
#include <cdio/logging.h>
31
#include "cdio_assert.h"
34
static const char _rcsid[] = "$Id: logging.c,v 1.1 2004/12/18 17:29:32 rocky Exp $";
36
cdio_log_level_t cdio_loglevel_default = CDIO_LOG_WARN;
39
default_cdio_log_handler (cdio_log_level_t level, const char message[])
44
if (level >= cdio_loglevel_default) {
45
fprintf (stderr, "**ERROR: %s\n", message);
51
if (level >= cdio_loglevel_default) {
52
fprintf (stdout, "--DEBUG: %s\n", message);
56
if (level >= cdio_loglevel_default) {
57
fprintf (stdout, "++ WARN: %s\n", message);
61
if (level >= cdio_loglevel_default) {
62
fprintf (stdout, " INFO: %s\n", message);
66
if (level >= cdio_loglevel_default) {
67
fprintf (stderr, "!ASSERT: %s\n", message);
73
cdio_assert_not_reached ();
80
static cdio_log_handler_t _handler = default_cdio_log_handler;
83
cdio_log_set_handler (cdio_log_handler_t new_handler)
85
cdio_log_handler_t old_handler = _handler;
87
_handler = new_handler;
93
cdio_logv (cdio_log_level_t level, const char format[], va_list args)
95
char buf[1024] = { 0, };
96
static int in_recursion = 0;
99
cdio_assert_not_reached ();
103
vsnprintf(buf, sizeof(buf)-1, format, args);
105
_handler(level, buf);
111
cdio_log (cdio_log_level_t level, const char format[], ...)
114
va_start (args, format);
115
cdio_logv (level, format, args);
119
#define CDIO_LOG_TEMPLATE(level, LEVEL) \
121
cdio_ ## level (const char format[], ...) \
124
va_start (args, format); \
125
cdio_logv (CDIO_LOG_ ## LEVEL, format, args); \
129
CDIO_LOG_TEMPLATE(debug, DEBUG)
130
CDIO_LOG_TEMPLATE(info, INFO)
131
CDIO_LOG_TEMPLATE(warn, WARN)
132
CDIO_LOG_TEMPLATE(error, ERROR)
134
#undef CDIO_LOG_TEMPLATE
139
* c-file-style: "gnu"
141
* indent-tabs-mode: nil