Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Logger Class Reference

#include <Logger.h>

List of all members.

Public Types

enum  {
  Emergency = 0, Alert = 1, Critical = 2, Error = 3,
  Warning = 4, Notice = 5, Info = 6, Debug = 7
}

Public Member Functions

 Logger (char *fn=NULL, int option=0)
void open (char *fn)
 ~Logger ()
void close ()
Loggerpriority (int p)
Loggerp (int p)
Loggerwrite (const char *s)
Loggerwrite (char ch)

Private Member Functions

int bufresize (int sz)
void append (const char *s)
void print ()

Private Attributes

std::ofstream log
int _priority
char * buf
int buflen
int bufsz

Friends

Loggeroperator<< (Logger &l, const char *s)
Loggeroperator<< (Logger &l, const string &s)
Loggeroperator<< (Logger &l, char ch)
Loggeroperator<< (Logger &l, unsigned int i)
Loggeroperator<< (Logger &l, int i)


Detailed Description

Author:
Thomas Gschwind Levels:

Definition at line 33 of file Logger.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
Emergency 
Alert 
Critical 
Error 
Warning 
Notice 
Info 
Debug 

Definition at line 74 of file Logger.h.

00074              { Emergency = 0,
00075                 Alert = 1,
00076                 Critical = 2,
00077                 Error = 3,
00078                 Warning = 4,
00079                 Notice = 5,
00080                 Info = 6,
00081                 Debug = 7
00082         };


Constructor & Destructor Documentation

Logger::Logger char *  fn = NULL,
int  option = 0
 

Definition at line 103 of file Logger.cc.

References _priority, buflen, bufresize(), bufsz, Debug, and open().

00104 {
00105         buf = NULL;
00106         bufsz = 0;
00107         if (bufresize(1) == 0)
00108                 exit(26);
00109         buf[0] = '\0';
00110         buflen = 0;
00111         _priority = Debug;
00112 
00113         open(fn);
00114 }

Logger::~Logger  ) 
 

Definition at line 116 of file Logger.cc.

References close().

00117 {
00118         close();
00119 }


Member Function Documentation

void Logger::append const char *  s  )  [private]
 

Definition at line 36 of file Logger.cc.

References buflen, and bufresize().

Referenced by write().

00037 {
00038         int slen = strlen(s);
00039         if (bufresize(buflen + slen + 1) == 0)
00040                 exit(26);
00041         strcat(buf, s);
00042         buflen += slen;
00043 }

int Logger::bufresize int  sz  )  [private]
 

Definition at line 15 of file Logger.cc.

References bufsz.

Referenced by append(), and Logger().

00016 {
00017         int nsz;
00018 
00019         /* Round up to the next 4k boundary */
00020         nsz = (sz + 0x1000) & ~0xfff;
00021         if (nsz != bufsz) {
00022                 /* Add Space */
00023                 if (buf)
00024                         buf = (char *) realloc(buf, nsz);
00025                 else
00026                         buf = (char *) malloc(nsz);
00027                 if (!buf) {
00028                         bufsz = 0;
00029                         return 0;
00030                 }
00031                 bufsz = nsz;
00032         }
00033         return bufsz;
00034 }

void Logger::close  ) 
 

Definition at line 129 of file Logger.cc.

References log.

Referenced by ~Logger().

00130 {
00131         log.close();
00132 }

void Logger::open char *  fn  ) 
 

Definition at line 121 of file Logger.cc.

References log.

Referenced by Logger(), and main().

00122 {
00123         if (fn) {
00124                 log.open(fn, ios::app);
00125                 log.setf(ios::unitbuf);
00126         }
00127 }

Logger& Logger::p int  p  )  [inline]
 

Definition at line 97 of file Logger.h.

References priority().

Referenced by CServer::active(), RServer::active(), NVActiveDB::add(), CServer::article(), RServer::article(), ArtSpooler::ArtSpooler(), catchsigalarm(), catchsighup(), catchsignal(), check_auth_file(), check_auth_unix(), clean(), RServer::connect(), sstream::disconnect(), RServer::disconnect(), doprefetch(), Error::Error(), fillHostStruct(), NServer::freegroup(), ArtSpooler::getSpooledArt(), CServer::groupinfo(), RServer::init(), RServer::issue(), CNewsgroup::listgroup(), main(), AccessEntry::modifyAccessFlags(), NVActiveDB_Iter::next(), nlreadline(), nnrpd(), nntpd(), ns_date(), ns_group(), ns_help(), ns_post(), NServer::NServer(), nsh_particle(), NVcontainer::nvalloc(), NVcontainer::nvfree(), CServer::overviewdb(), RServer::overviewdb(), CServer::post(), RServer::post(), CServer::postspooled(), CNewsgroup::prefetchGroup(), print(), NVNewsgroup::printoverdb(), Article::read(), NVNewsgroup::readoverdb(), remove_elements(), ResponseError::ResponseError(), RServer::RServer(), RServer::selectgroup(), selectgroup(), NVNewsgroup::setarticle(), Article::setfield(), RServer::setserver(), RServer::setserverlist(), RNewsgroup::setsize(), sigchld(), CServer::spoolarticle(), CNewsgroup::sUpdateGroupInfo(), CNewsgroup::sUpdateOverview(), SyntaxError::SyntaxError(), update(), ArtSpooler::~ArtSpooler(), CServer::~CServer(), LServer::~LServer(), NServer::~NServer(), and RServer::~RServer().

00097                           {
00098                 return priority(p);
00099         } Logger & write(const char *s);

void Logger::print  )  [private]
 

Definition at line 45 of file Logger.cc.

References _priority, buflen, log, and p().

Referenced by CServer::active(), RServer::active(), nnrpd(), nntpd(), ns_article(), ns_stat(), and write().

00046 {
00047         char *nl, *p;
00048 
00049         while ((nl = strchr(buf, '\n')) != NULL) {
00050                 // Print first line
00051                 *nl = '\0';
00052 #ifdef WITH_SYSLOG
00053                 syslog(_priority, "%s", buf);
00054 #else
00055                 time_t ts;
00056                 struct tm *t;
00057                 char tbuf[32];
00058                 time(&ts);
00059                 t = localtime(&ts);
00060                 sprintf(tbuf, "%d %04d/%02d/%02d %02d:%02d:%02d ",
00061                         _priority, 1900 + t->tm_year, t->tm_mon,
00062                         t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
00063                 log << tbuf << buf << endl;
00064 #endif
00065 
00066                 // Move remaining string to the beginning
00067                 nl++;
00068                 p = buf;
00069                 while ((*p++ = *nl++) != '\0');
00070         }
00071         buflen = strlen(buf);
00072 }

Logger & Logger::priority int  p  ) 
 

Definition at line 135 of file Logger.cc.

References _priority, buflen, and write().

Referenced by p().

00136 {
00137         _priority = p;
00138         if (buflen && buf[buflen - 1] != '\n')
00139                 write("\n");
00140         return *this;
00141 }

Logger& Logger::write char  ch  )  [inline]
 

Definition at line 100 of file Logger.h.

References write().

00100                                 {
00101                 char buf[2];
00102                 buf[0] = ch;
00103                 buf[1] = '\0';
00104                 return write(buf);
00105         }

Logger & Logger::write const char *  s  ) 
 

Definition at line 143 of file Logger.cc.

References append(), and print().

Referenced by operator<<(), priority(), and write().

00144 {
00145         append(s);
00146         print();
00147         return *this;
00148 }


Friends And Related Function Documentation

Logger& operator<< Logger l,
int  i
[friend]
 

Definition at line 174 of file Logger.cc.

00175 {
00176         char s[256];
00177         sprintf(s, "%d", i);
00178         return l.write(s);
00179 }

Logger& operator<< Logger l,
unsigned int  i
[friend]
 

Definition at line 167 of file Logger.cc.

00168 {
00169         char s[256];
00170         sprintf(s, "%u", i);
00171         return l.write(s);
00172 }

Logger& operator<< Logger l,
char  ch
[friend]
 

Definition at line 162 of file Logger.cc.

00163 {
00164         return l.write(ch);
00165 }

Logger& operator<< Logger l,
const string &  s
[friend]
 

Definition at line 156 of file Logger.cc.

00157 {
00158         string s2(s);
00159         return l.write(s2.c_str());
00160 }

Logger& operator<< Logger l,
const char *  s
[friend]
 

Definition at line 151 of file Logger.cc.

00152 {
00153         return l.write(s);
00154 }


Member Data Documentation

int Logger::_priority [private]
 

Definition at line 39 of file Logger.h.

Referenced by Logger(), print(), and priority().

char* Logger::buf [private]
 

Definition at line 41 of file Logger.h.

int Logger::buflen [private]
 

Definition at line 42 of file Logger.h.

Referenced by append(), Logger(), print(), and priority().

int Logger::bufsz [private]
 

Definition at line 42 of file Logger.h.

Referenced by bufresize(), and Logger().

std::ofstream Logger::log [private]
 

Definition at line 36 of file Logger.h.

Referenced by close(), open(), and print().


The documentation for this class was generated from the following files:
Generated on Fri Aug 20 10:58:10 2004 for NewsCache by doxygen 1.3.6-20040222