root/tags/0.10.0/debug.c

Revision 547, 3.5 kB (checked in by reinelt, 4 years ago)

[lcd4linux @ 2005-05-08 04:32:43 by reinelt]
CodingStyle? added and applied

Line 
1/* $Id: debug.c,v 1.13 2005/05/08 04:32:43 reinelt Exp $
2 *
3 * debug() and error() functions
4 *
5 * Copyright (C) 1999, 2000 Michael Reinelt <reinelt@eunet.at>
6 * Copyright (C) 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
7 *
8 * This file is part of LCD4Linux.
9 *
10 * LCD4Linux is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2, or (at your option)
13 * any later version.
14 *
15 * LCD4Linux is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 *
24 *
25 * $Log: debug.c,v $
26 * Revision 1.13  2005/05/08 04:32:43  reinelt
27 * CodingStyle added and applied
28 *
29 * Revision 1.12  2005/01/18 06:30:22  reinelt
30 * added (C) to all copyright statements
31 *
32 * Revision 1.11  2004/06/26 12:04:59  reinelt
33 *
34 * uh-oh... the last CVS log message messed up things a lot...
35 *
36 * Revision 1.10  2004/06/26 09:27:20  reinelt
37 *
38 * added '-W' to CFLAGS
39 * changed all C++ comments to C ones
40 * cleaned up a lot of signed/unsigned mistakes
41 *
42 * Revision 1.9  2004/06/20 10:09:54  reinelt
43 *
44 * 'const'ified the whole source
45 *
46 * Revision 1.8  2004/05/26 11:37:36  reinelt
47 *
48 * Curses driver ported.
49 *
50 * Revision 1.7  2004/02/10 07:42:35  reinelt
51 * cut off all old-style files which are no longer used with NextGeneration
52 *
53 * Revision 1.6  2003/10/05 17:58:50  reinelt
54 * libtool junk; copyright messages cleaned up
55 *
56 * Revision 1.5  2003/08/24 05:17:58  reinelt
57 * liblcd4linux patch from Patrick Schemitz
58 *
59 * Revision 1.4  2003/08/08 06:58:06  reinelt
60 * improved forking
61 *
62 * Revision 1.3  2001/03/12 12:39:36  reinelt
63 *
64 * reworked autoconf a lot: drivers may be excluded, #define's went to config.h
65 *
66 * Revision 1.2  2001/03/09 13:08:11  ltoetsch
67 * Added Text driver
68 *
69 * Revision 1.1  2000/11/28 20:20:38  reinelt
70 *
71 * added debug.c
72 * things like that should not hapen. debug.c exists for a few months now, but was never added to CVS. Shit happens....
73 *
74 */
75
76/*
77 * exported functions:
78 *
79 * message (level, format, ...)
80 *   passes the arguments to vsprintf() and
81 *   writes the resulting string either to stdout
82 *   or syslog.
83 *   this function should not be called directly,
84 *   but the macros info(), debug() and error()
85 *
86 */
87
88#include "config.h"
89
90#include <stdlib.h>
91#include <stdio.h>
92#include <stdarg.h>
93#include <syslog.h>
94
95#include "debug.h"
96
97int running_foreground = 0;
98int running_background = 0;
99
100int verbose_level = 0;
101
102void message(const int level, const char *format, ...)
103{
104    va_list ap;
105    char buffer[256];
106    static int log_open = 0;
107
108    if (level > verbose_level)
109  return;
110
111    va_start(ap, format);
112    vsnprintf(buffer, sizeof(buffer), format, ap);
113    va_end(ap);
114
115    if (!running_background) {
116
117#ifdef WITH_CURSES
118  extern int curses_error(char *);
119  if (!curses_error(buffer))
120#endif
121      fprintf(level ? stdout : stderr, "%s\n", buffer);
122    }
123
124    if (running_foreground)
125  return;
126
127    if (!log_open) {
128  openlog("LCD4Linux", LOG_PID, LOG_USER);
129  log_open = 1;
130    }
131
132    switch (level) {
133    case 0:
134  syslog(LOG_ERR, "%s", buffer);
135  break;
136    case 1:
137  syslog(LOG_INFO, "%s", buffer);
138  break;
139    default:
140  syslog(LOG_DEBUG, "%s", buffer);
141    }
142}
Note: See TracBrowser for help on using the browser.