Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members  

wvlogrcv.h

Go to the documentation of this file.
00001 /*
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  * 
00005  * Enhanced "Log Receiver" classes for WvLog.
00006  * 
00007  * WvLogRcv-derived classes support automatic formatting of log lines with
00008  * a prefix, removing control characters, and so on.
00009  * 
00010  * WvLogRcv supports partial- and multiple-line log messages.  For example,
00011  *        log.print("test ");
00012  *        log.print("string\nfoo");
00013  * will print:
00014  *        appname(lvl): test string
00015  *        appname(lvl): foo
00016  */
00017 #ifndef __WVLOGRCV_H
00018 #define __WVLOGRCV_H
00019 
00020 #include "wvlog.h"
00021 
00026 class WvLogRcv : public WvLogRcvBase
00027 {
00028 protected:
00029     const WvLog *last_source;
00030     WvLog::LogLevel max_level, last_level;
00031     bool at_newline;
00032     WvString prefix;
00033     size_t prelen;
00034 
00035     virtual void log(const WvLog *source, int loglevel,
00036                      const char *_buf, size_t len);
00037 
00041     virtual void _make_prefix();
00042     
00046     virtual void _begin_line();
00047     
00051     virtual void _end_line();
00052 
00058     virtual void _mid_line(const char *str, size_t len) = 0;
00059 
00060 private:
00061     void begin_line()
00062         { if (!at_newline) return; _begin_line(); at_newline = false; }
00063     void mid_line(const char *str, size_t len)
00064         { _mid_line(str, len); 
00065           if (len>0 && str[len-1] == '\n') at_newline = true; }
00066 
00067 public:
00068     static char *loglevels[WvLog::NUM_LOGLEVELS];
00069     
00070     WvLogRcv(WvLog::LogLevel _max_level = WvLog::NUM_LOGLEVELS);
00071     virtual ~WvLogRcv();
00072 
00073     void end_line()
00074         { if (at_newline) return;
00075           _mid_line("\n", 1); _end_line(); at_newline = true; }
00076     
00077     WvLog::LogLevel level() const
00078         { return max_level; }
00079     void level(WvLog::LogLevel lvl)
00080         { max_level = lvl; }
00081 };
00082 
00083 
00084 class WvLogConsole : public WvStream, public WvLogRcv
00085 {
00086 public:
00087     WvLogConsole(int _fd,
00088                  WvLog::LogLevel _max_level = WvLog::NUM_LOGLEVELS);
00089     virtual ~WvLogConsole();
00090 protected:
00091     virtual void _mid_line(const char *str, size_t len);
00092 };
00093 
00094 #endif // __WVLOGRCV_H

Generated on Fri Apr 5 15:16:52 2002 for WvStreams by doxygen1.2.15