[BACK]Return to Log.h CVS log [TXT][DIR] Up to [Development] / fam / fam

Annotation of fam/fam/Log.h, Revision 1.1.1.1

1.1       trev        1: //  Copyright (C) 1999 Silicon Graphics, Inc.  All Rights Reserved.
                      2: //
                      3: //  This program is free software; you can redistribute it and/or modify it
                      4: //  under the terms of version 2 of the GNU General Public License as
                      5: //  published by the Free Software Foundation.
                      6: //
                      7: //  This program is distributed in the hope that it would be useful, but
                      8: //  WITHOUT ANY WARRANTY; without even the implied warranty of
                      9: //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  Further, any
                     10: //  license provided herein, whether implied or otherwise, is limited to
                     11: //  this program in accordance with the express provisions of the GNU
                     12: //  General Public License.  Patent licenses, if any, provided herein do not
                     13: //  apply to combinations of this program with other product or programs, or
                     14: //  any other product whatsoever.  This program is distributed without any
                     15: //  warranty that the program is delivered free of the rightful claim of any
                     16: //  third person by way of infringement or the like.  See the GNU General
                     17: //  Public License for more details.
                     18: //
                     19: //  You should have received a copy of the GNU General Public License along
                     20: //  with this program; if not, write the Free Software Foundation, Inc., 59
                     21: //  Temple Place - Suite 330, Boston MA 02111-1307, USA.
                     22:
                     23: #ifndef Log_included
                     24: #define Log_included
                     25:
                     26: #include "Boolean.h"
                     27: #include <stdarg.h>
                     28:
                     29: //  Log is an augmented syslog(3C).  There are three log levels, DEBUG
                     30: //  INFO and LOG.  Logging can be done to the foreground (stderr) or
                     31: //  to the background (syslog).
                     32: //
                     33: //  Control interface:
                     34: //
                     35: //	debug(), info(), error()	control the log level.
                     36: //	foreground(), background()	control where log messages go.
                     37: //	name()				sets the program's name (i.e., fam)
                     38: //
                     39: //  Log interface:
                     40: //
                     41: //	debug(fmt, ...)		log at LOG_DEBUG level
                     42: //	info(fmt, ...)		log at LOG_INFO level
                     43: //	error(fmt, ...)		log at LOG_ERR level
                     44: //	critical(fmt, ...)	log at LOG_CRITICAL level
                     45: //	perror(fmt, ...)	log at LOG_ERR, append system error string
                     46: //	audit(bool, fmt, ...)   write message to security audit trail
                     47: //
                     48: //  All the log interface routines take printf-like arguments.  In
                     49: //  addition, all but audit() recognize "%m", which substitutes the system
                     50: //  error string.  "%m" works even when logging to foreground.
                     51: //
                     52: //  When NDEBUG is not defined, Log.C also implements a replacement
                     53: //  for the libc function __assert().  The replacement function writes
                     54: //  the failed assertion message to the current log (i.e., stderr or
                     55: //  syslog), then sets its uid to 0, creates a directory in /usr/tmp,
                     56: //  logs the name of the directory, and chdir() to it so the core file
                     57: //  can be found.
                     58:
                     59: class Log {
                     60:
                     61: public:
                     62:
                     63:     enum LogLevel { CRITICAL = 0, ERROR = 1, INFO = 2, DEBUG = 3 };
                     64:
                     65: #ifdef HAPPY_PURIFY
                     66:     Log();
                     67:     ~Log();
                     68: #endif
                     69:
                     70:     // Message logging functions.  Four different priorities.
                     71:
                     72:     static void debug(const char *fmt, ...);
                     73:     static void info(const char *fmt, ...);
                     74:     static void error(const char *fmt, ...);
                     75:     static void critical(const char *fmt, ...);
                     76:
                     77:     //  logs regardless of log level
                     78:     static void log(LogLevel l, const char *fmt, ...);
                     79:
                     80:     // perror() is like error() but appends system error string.
                     81:
                     82:     static void perror(const char *format, ...);
                     83:
                     84:     // Security audit trail messages.
                     85:
                     86:     static void audit(bool success, const char *fmt, ...);
                     87:
                     88:     // Control functions
                     89:
                     90:     static void debug();
                     91:     static void info();
                     92:     static void error();
                     93:     static void disable_audit();
                     94:
                     95:     static void foreground();
                     96:     static void background();
                     97:
                     98:     static void name(const char *);
                     99:     static const char * getName() {return program_name;}
                    100:
                    101:     static LogLevel get_level() { return level; }
                    102:
                    103: private:
                    104:
                    105:     static void vlog(LogLevel, const char *format, va_list);
                    106:     static void vfglog(const char *format, va_list args);
                    107:
                    108:     static LogLevel level;
                    109:     static bool log_to_stderr;
                    110:     static const char *program_name;
                    111:     static bool syslog_open;
                    112:     static unsigned count;
                    113: #ifdef HAVE_AUDIT
                    114:     static bool audit_enabled;
                    115: #endif
                    116:
                    117: };
                    118:
                    119: #ifdef HAPPY_PURIFY
                    120: static Log Log_instance;
                    121: #endif
                    122:
                    123: #endif /* !Log_included */

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>