| 1 |
/* $Id$ */ |
| 2 |
/* |
| 3 |
* Copyright (c) 1995-1996 Sam Leffler |
| 4 |
* Copyright (c) 1995-1996 Silicon Graphics, Inc. |
| 5 |
* HylaFAX is a trademark of Silicon Graphics |
| 6 |
* |
| 7 |
* Permission to use, copy, modify, distribute, and sell this software and |
| 8 |
* its documentation for any purpose is hereby granted without fee, provided |
| 9 |
* that (i) the above copyright notices and this permission notice appear in |
| 10 |
* all copies of the software and related documentation, and (ii) the names of |
| 11 |
* Sam Leffler and Silicon Graphics may not be used in any advertising or |
| 12 |
* publicity relating to the software without the specific, prior written |
| 13 |
* permission of Sam Leffler and Silicon Graphics. |
| 14 |
* |
| 15 |
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, |
| 16 |
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY |
| 17 |
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. |
| 18 |
* |
| 19 |
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR |
| 20 |
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, |
| 21 |
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, |
| 22 |
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF |
| 23 |
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE |
| 24 |
* OF THIS SOFTWARE. |
| 25 |
*/ |
| 26 |
#include "port.h" |
| 27 |
#include "config.h" |
| 28 |
#include "SystemLog.h" |
| 29 |
|
| 30 |
/* |
| 31 |
* Logging and error routines. |
| 32 |
*/ |
| 33 |
|
| 34 |
extern "C" int cvtFacility(const char*, int*); |
| 35 |
|
| 36 |
int SystemLog::facility = LOG_DAEMON; |
| 37 |
const char* SystemLog::appName = "FaxApp"; // generic, override |
| 38 |
|
| 39 |
void |
| 40 |
SystemLog::setupLogging(const char* name) |
| 41 |
{ |
| 42 |
appName = name; |
| 43 |
openlog(name, LOG_PID|LOG_ODELAY, facility); |
| 44 |
} |
| 45 |
void |
| 46 |
SystemLog::setupLogging(void) |
| 47 |
{ |
| 48 |
// NB: LOG_NDELAY 'cuz of chroot done by hfaxd |
| 49 |
openlog(appName, LOG_PID|LOG_NDELAY, facility); |
| 50 |
} |
| 51 |
void SystemLog::closeLogging(void) { closelog(); } |
| 52 |
|
| 53 |
void |
| 54 |
SystemLog::setLogFacility(const char* fac) |
| 55 |
{ |
| 56 |
if (!cvtFacility(fac, &facility)) |
| 57 |
logError("Unknown syslog facility name \"%s\"", fac); |
| 58 |
} |
| 59 |
|
| 60 |
void vlogInfo(const char* fmt, va_list ap) |
| 61 |
{ vsyslog(LOG_INFO|SystemLog::getLogFacility(), fmt, ap); } |
| 62 |
void |
| 63 |
logInfo(const char* fmt ...) |
| 64 |
{ |
| 65 |
va_list ap; |
| 66 |
va_start(ap, fmt); |
| 67 |
vlogInfo(fmt, ap); |
| 68 |
va_end(ap); |
| 69 |
} |
| 70 |
|
| 71 |
void vlogError(const char* fmt, va_list ap) |
| 72 |
{ vsyslog(LOG_ERR|SystemLog::getLogFacility(), fmt, ap); } |
| 73 |
void |
| 74 |
logError(const char* fmt ...) |
| 75 |
{ |
| 76 |
va_list ap; |
| 77 |
va_start(ap, fmt); |
| 78 |
vlogError(fmt, ap); |
| 79 |
va_end(ap); |
| 80 |
} |
| 81 |
|
| 82 |
void vlogNotice(const char* fmt, va_list ap) |
| 83 |
{ vsyslog(LOG_NOTICE|SystemLog::getLogFacility(), fmt, ap); } |
| 84 |
void |
| 85 |
logNotice(const char* fmt ...) |
| 86 |
{ |
| 87 |
va_list ap; |
| 88 |
va_start(ap, fmt); |
| 89 |
vlogNotice(fmt, ap); |
| 90 |
va_end(ap); |
| 91 |
} |
| 92 |
|
| 93 |
void vlogDebug(const char* fmt, va_list ap) |
| 94 |
{ vsyslog(LOG_DEBUG|SystemLog::getLogFacility(), fmt, ap); } |
| 95 |
void |
| 96 |
logDebug(const char* fmt ...) |
| 97 |
{ |
| 98 |
va_list ap; |
| 99 |
va_start(ap, fmt); |
| 100 |
vlogDebug(fmt, ap); |
| 101 |
va_end(ap); |
| 102 |
} |
| 103 |
|
| 104 |
void vlogWarning(const char* fmt, va_list ap) |
| 105 |
{ vsyslog(LOG_WARNING|SystemLog::getLogFacility(), fmt, ap); } |
| 106 |
void |
| 107 |
logWarning(const char* fmt ...) |
| 108 |
{ |
| 109 |
va_list ap; |
| 110 |
va_start(ap, fmt); |
| 111 |
vlogWarning(fmt, ap); |
| 112 |
va_end(ap); |
| 113 |
} |