root/trunk/debug.c

Revision 840, 2.1 kB (checked in by michael, 15 months ago)

email address changed

  • Property svn:keywords set to Id URL Rev
Line 
1/* $Id$
2 * $URL$
3 *
4 * debug() and error() functions
5 *
6 * Copyright (C) 1999, 2000 Michael Reinelt <michael@reinelt.co.at>
7 * Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
8 *
9 * This file is part of LCD4Linux.
10 *
11 * LCD4Linux is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * LCD4Linux is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 */
26
27/*
28 * exported functions:
29 *
30 * message (level, format, ...)
31 *   passes the arguments to vsprintf() and
32 *   writes the resulting string either to stdout
33 *   or syslog.
34 *   this function should not be called directly,
35 *   but the macros info(), debug() and error()
36 *
37 */
38
39#include "config.h"
40
41#include <stdlib.h>
42#include <stdio.h>
43#include <stdarg.h>
44#include <syslog.h>
45
46#include "debug.h"
47
48int running_foreground = 0;
49int running_background = 0;
50
51int verbose_level = 0;
52
53void message(const int level, const char *format, ...)
54{
55    va_list ap;
56    char buffer[256];
57    static int log_open = 0;
58
59    if (level > verbose_level)
60  return;
61
62    va_start(ap, format);
63    vsnprintf(buffer, sizeof(buffer), format, ap);
64    va_end(ap);
65
66    if (!running_background) {
67
68#ifdef WITH_CURSES
69  extern int curses_error(char *);
70  if (!curses_error(buffer))
71#endif
72      fprintf(level ? stdout : stderr, "%s\n", buffer);
73    }
74
75    if (running_foreground)
76  return;
77
78    if (!log_open) {
79  openlog("LCD4Linux", LOG_PID, LOG_USER);
80  log_open = 1;
81    }
82
83    switch (level) {
84    case 0:
85  syslog(LOG_ERR, "%s", buffer);
86  break;
87    case 1:
88  syslog(LOG_INFO, "%s", buffer);
89  break;
90    default:
91  syslog(LOG_DEBUG, "%s", buffer);
92    }
93}
Note: See TracBrowser for help on using the browser.