1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2008 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 * ---------------------------------------------------
17 /** Debug levels for use with InspIRCd::Log()
29 /* Forward declaration -- required */
32 /** This class implements a nonblocking log-writer.
33 * Most people writing an ircd give little thought to their disk
34 * i/o. On a congested system, disk writes can block for long
35 * periods of time (e.g. if the system is busy and/or swapping
36 * a lot). If we just use a blocking fprintf() call, this could
37 * block for undesirable amounts of time (half of a second through
38 * to whole seconds). We DO NOT want this, so we make our logfile
39 * nonblocking and hook it into the SocketEngine.
40 * NB: If the operating system does not support nonblocking file
41 * I/O (linux seems to, as does freebsd) this will default to
44 class CoreExport FileLogger : public EventHandler
47 /** The creator/owner of this object
49 InspIRCd* ServerInstance;
50 /** The log file (fd is inside this somewhere,
51 * we get it out with fileno())
54 /** Buffer of pending log lines to be written
57 /** Number of write operations that have occured
61 /** The constructor takes an already opened logfile.
63 FileLogger(InspIRCd* Instance, FILE* logfile);
64 /** This returns false, logfiles are writeable.
66 virtual bool Readable();
67 /** Handle pending write events.
68 * This will flush any waiting data to disk.
69 * If any data remains after the fprintf call,
70 * another write event is scheduled to write
71 * the rest of the data when possible.
73 virtual void HandleEvent(EventType et, int errornum = 0);
74 /** Write one or more preformatted log lines.
75 * If the data cannot be written immediately,
76 * this class will insert itself into the
77 * SocketEngine, and register a write event,
78 * and when the write event occurs it will
79 * attempt again to write the data.
81 void WriteLogLine(const std::string &line);
82 /** Close the log file and cancel any events.
85 /** Close the log file and cancel any events.
86 * (indirectly call Close()
88 virtual ~FileLogger();
91 class CoreExport FileLogStream : public LogStream
96 FileLogStream(InspIRCd *Instance, FILE *f) : LogStream(Instance)
98 this->f = new FileLogger(Instance, f);
106 virtual void OnLog(int loglevel, const std::string &type, const std::string &msg);