1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2007 InspIRCd Development Team
6 * See: http://www.inspircd.org/wiki/index.php/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
20 #include "socketengine.h"
23 /** Debug levels for use with InspIRCd::Log()
35 /* Forward declaration -- required */
38 /** This class implements a nonblocking log-writer.
39 * Most people writing an ircd give little thought to their disk
40 * i/o. On a congested system, disk writes can block for long
41 * periods of time (e.g. if the system is busy and/or swapping
42 * a lot). If we just use a blocking fprintf() call, this could
43 * block for undesirable amounts of time (half of a second through
44 * to whole seconds). We DO NOT want this, so we make our logfile
45 * nonblocking and hook it into the SocketEngine.
46 * NB: If the operating system does not support nonblocking file
47 * I/O (linux seems to, as does freebsd) this will default to
50 class CoreExport FileLogger : public EventHandler
53 /** The creator/owner of this object
55 InspIRCd* ServerInstance;
56 /** The log file (fd is inside this somewhere,
57 * we get it out with fileno())
60 /** Buffer of pending log lines to be written
63 /** Number of write operations that have occured
67 /** The constructor takes an already opened logfile.
69 FileLogger(InspIRCd* Instance, FILE* logfile);
70 /** This returns false, logfiles are writeable.
72 virtual bool Readable();
73 /** Handle pending write events.
74 * This will flush any waiting data to disk.
75 * If any data remains after the fprintf call,
76 * another write event is scheduled to write
77 * the rest of the data when possible.
79 virtual void HandleEvent(EventType et, int errornum = 0);
80 /** Write one or more preformatted log lines.
81 * If the data cannot be written immediately,
82 * this class will insert itself into the
83 * SocketEngine, and register a write event,
84 * and when the write event occurs it will
85 * attempt again to write the data.
87 void WriteLogLine(const std::string &line);
88 /** Close the log file and cancel any events.
91 /** Close the log file and cancel any events.
92 * (indirectly call Close()
94 virtual ~FileLogger();