Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

wvlogrcv.h

00001 /* -*- Mode: C++ -*-
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 #include "wvfdstream.h"
00022 #include "wvscatterhash.h"
00023 
00028 class WvLogRcv : public WvLogRcvBase
00029 {
00030 protected:  
00031     const WvLog *last_source;
00032     WvLog::LogLevel max_level, last_level;
00033     bool at_newline;
00034     WvString prefix;
00035     size_t prelen;
00036     
00037     class Src_Lvl
00038     {
00039     public:
00040         WvString src;
00041         WvLog::LogLevel lvl;
00042         Src_Lvl(WvString _src, int _lvl) : src(_src),
00043         lvl((WvLog::LogLevel)_lvl) {};
00044     };
00045     
00046     DeclareWvScatterDict(Src_Lvl, WvString, src);
00047     
00048     Src_LvlDict custom_levels;
00049     
00050     virtual void log(const WvLog *source, int loglevel,
00051                      const char *_buf, size_t len);
00052     
00054     virtual void _make_prefix();
00055     
00057     virtual void _begin_line();
00058     
00060     virtual void _end_line();
00061     
00067     virtual void _mid_line(const char *str, size_t len) = 0;
00068     
00069 private:
00070     void begin_line()
00071         { if (!at_newline) return; _begin_line(); at_newline = false; }
00072     void mid_line(const char *str, size_t len)
00073         { _mid_line(str, len); 
00074             if (len>0 && str[len-1] == '\n') at_newline = true; }
00075     
00076 public:
00077     static char *loglevels[WvLog::NUM_LOGLEVELS];
00078     
00079     WvLogRcv(WvLog::LogLevel _max_level = WvLog::NUM_LOGLEVELS);
00080     virtual ~WvLogRcv();
00081     
00082     void end_line()
00083         { if (at_newline) return;
00084             _mid_line("\n", 1); _end_line(); at_newline = true; };
00085     
00086     WvLog::LogLevel level() const
00087         { return max_level; }
00088     void level(WvLog::LogLevel lvl)
00089         { max_level = lvl; }
00090     
00091     /*
00092      * Allows you to override debug levels for specific sources
00093      *  example: mysql=9,Service Manager=9
00094      *  will get all the debug output from all the sources that
00095      *  contain (case insensitively) "mysql" or "Service Manager"
00096      *  in the source name regardless of the current debug level.
00097      */
00098     bool set_custom_levels(WvString descr);
00099 };
00100 
00101 
00106 class WvLogConsole : public WvFDStream, public WvLogRcv
00107 {
00108     public:
00109         WvLogConsole(int _fd,
00110                 WvLog::LogLevel _max_level = WvLog::NUM_LOGLEVELS);
00111         virtual ~WvLogConsole();
00112     protected:
00113         virtual void _mid_line(const char *str, size_t len);
00114 };
00115 
00116 #endif // __WVLOGRCV_H

Generated on Fri May 20 11:17:45 2005 for WvStreams by  doxygen 1.4.2