The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download | Blog | Stats
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

FileLogger Class Reference

This class implements a nonblocking log-writer. More...

#include <inspircd.h>

Collaboration diagram for FileLogger:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FileLogger (InspIRCd *Instance, FILE *logfile)
 The constructor takes an already opened logfile.
void WriteLogLine (const std::string &line)
 Write one or more preformatted log lines.
virtual void Close ()
 Close the log file and cancel any events.
virtual ~FileLogger ()
 Close the log file and cancel any events.

Protected Attributes

InspIRCdServerInstance
 The creator/owner of this object.
FILE * log
 The log file (fd is inside this somewhere, we get it out with fileno()).
int writeops
 Number of write operations that have occured.

Detailed Description

This class implements a nonblocking log-writer.

Most people writing an ircd give little thought to their disk i/o. On a congested system, disk writes can block for long periods of time (e.g. if the system is busy and/or swapping a lot). If we just use a blocking fprintf() call, this could block for undesirable amounts of time (half of a second through to whole seconds). We DO NOT want this, so we make our logfile nonblocking and hook it into the SocketEngine. NB: If the operating system does not support nonblocking file I/O (linux seems to, as does freebsd) this will default to blocking behaviour.

Definition at line 273 of file inspircd.h.


Constructor & Destructor Documentation

FileLogger::FileLogger InspIRCd Instance,
FILE *  logfile
 

The constructor takes an already opened logfile.

Definition at line 1297 of file inspircd.cpp.

01297                                                         : ServerInstance(Instance), log(logfile), writeops(0)
01298 {
01299 }

FileLogger::~FileLogger  )  [virtual]
 

Close the log file and cancel any events.

(indirectly call Close()

Definition at line 1301 of file inspircd.cpp.

References Close().

01302 {
01303         this->Close();
01304 }


Member Function Documentation

void FileLogger::Close  )  [virtual]
 

Close the log file and cancel any events.

Definition at line 1288 of file inspircd.cpp.

References log.

Referenced by InspIRCd::Cleanup(), InspIRCd::CloseLog(), and ~FileLogger().

01289 {
01290         if (log)
01291         {
01292                 fflush(log);
01293                 fclose(log);
01294         }
01295 }

void FileLogger::WriteLogLine const std::string line  ) 
 

Write one or more preformatted log lines.

If the data cannot be written immediately, this class will insert itself into the SocketEngine, and register a write event, and when the write event occurs it will attempt again to write the data.

Definition at line 1275 of file inspircd.cpp.

References log, and writeops.

Referenced by InspIRCd::Log().

01276 {
01277         if (log)
01278         {
01279                 fprintf(log,"%s", line.c_str());
01280 
01281                 if (writeops++ % 20)
01282                 {
01283                         fflush(log);
01284                 }
01285         }
01286 }


Member Data Documentation

FILE* FileLogger::log [protected]
 

The log file (fd is inside this somewhere, we get it out with fileno()).

Definition at line 283 of file inspircd.h.

Referenced by Close(), and WriteLogLine().

InspIRCd* FileLogger::ServerInstance [protected]
 

The creator/owner of this object.

Definition at line 278 of file inspircd.h.

int FileLogger::writeops [protected]
 

Number of write operations that have occured.

Definition at line 287 of file inspircd.h.

Referenced by WriteLogLine().


The documentation for this class was generated from the following files: