1
0
mirror of https://github.com/anope/anope.git synced 2026-06-28 17:56:38 +02:00

Added a new logging system

This commit is contained in:
Adam
2010-08-27 20:56:28 -04:00
parent 73fb94c553
commit c2ddecc2b1
119 changed files with 1516 additions and 1222 deletions
+2
View File
@@ -23,6 +23,8 @@ enum BotFlag
{
BI_BEGIN,
/* This bot is a core bot. NickServ, ChanServ, etc */
BI_CORE,
/* This bot can only be assigned by IRCops */
BI_PRIVATE,
+3 -1
View File
@@ -57,7 +57,9 @@ enum ChannelFlags
/* Channel still exists when emptied */
CH_PERSIST,
/* If set the channel is syncing users (channel was just created) and it should not be deleted */
CH_SYNCING
CH_SYNCING,
/* Is a services log channel */
CH_LOGCHAN
};
class CoreExport Channel : public Extensible, public Flags<ChannelFlags>
+5 -8
View File
@@ -465,8 +465,6 @@ class ServerConfig
/* The hostname if services clients */
Anope::string ServiceHost;
/* Log channel */
Anope::string LogChannel;
/* Name of the network were on */
Anope::string NetworkName;
/* The max legnth of nicks */
@@ -544,8 +542,6 @@ class ServerConfig
bool UseStrictPrivMsg;
/* Dump a core file if we crash */
bool DumpCore;
/* Log users connecting/existing/changing nicks */
bool LogUsers;
/* Number of seconds between consecutive uses of the REGISTER command
* Not to be confused with NSRegDelay */
unsigned NickRegDelay;
@@ -555,6 +551,8 @@ class ServerConfig
Anope::string MLock;
/* Default botmodes on channels, defaults to ao */
Anope::string BotModes;
/* THe actual modes */
std::vector<ChannelModeStatus *> BotModeList;
/* How many times to try and reconnect to the uplink before giving up */
unsigned MaxRetries;
/* How long to wait between connection attempts */
@@ -562,6 +560,9 @@ class ServerConfig
/* If services should hide unprivileged commands */
bool HidePrivilegedCommands;
/* A vector of our logfile options */
std::vector<LogInfo *> LogInfos;
/* Services can use email */
bool UseMail;
/* Path to the sendmail executable */
@@ -684,10 +685,6 @@ class ServerConfig
Anope::string GlobalOnCycleUP;
/* Super admin is allowed */
bool SuperAdmin;
/* Log things said through ACT/SAY */
bool LogBot;
/* Log when new user max is reached */
bool LogMaxUsers;
/* Default expiry time for akills */
time_t AutokillExpiry;
/* Default expiry time for chan kills */
+3 -12
View File
@@ -153,8 +153,7 @@ E void hostserv_init();
E void introduce_user(const Anope::string &user);
E bool GetCommandLineArgument(const Anope::string &name, char shortname = 0);
E bool GetCommandLineArgument(const Anope::string &name, char shortname, Anope::string &param);
E int init_primary(int ac, char **av);
E int init_secondary(int ac, char **av);
E void Init(int ac, char **av);
E Uplink *uplink_server;
/**** ircd.c ****/
@@ -177,13 +176,8 @@ E const char *getstring(const NickCore *nc, int index);
E const char *getstring(const User *nc, int index);
E const char *getstring(int index);
/**** log.c ****/
E int open_log();
E void close_log();
E void log_perror(const char *fmt, ...) FORMAT(printf, 1, 2);
E void fatal(const char *fmt, ...) FORMAT(printf, 1, 2);
E void fatal_perror(const char *fmt, ...) FORMAT(printf, 1, 2);
/*** logger.cpp ***/
E void InitLogChannels(ServerConfig *);
/**** main.c ****/
@@ -193,7 +187,6 @@ E Anope::string services_dir;
E Anope::string log_filename;
E int debug;
E bool readonly;
E bool LogChan;
E bool nofork;
E bool nothird;
E bool noexpire;
@@ -297,8 +290,6 @@ E unsigned GenericChannelModes, GenericUserModes;
E Flags<ChannelModeName> DefMLockOn;
E Flags<ChannelModeName> DefMLockOff;
E std::map<ChannelModeName, Anope::string> DefMLockParams;
/* Modes to set on bots when they join the channel */
E std::list<ChannelModeStatus *> BotModes;
E void SetDefaultMLock(ServerConfig *config);
/**** nickserv.c ****/
+100
View File
@@ -0,0 +1,100 @@
#ifndef LOGGER_H
#define LOGGER_H
enum LogType
{
LOG_ADMIN,
LOG_OVERRIDE,
LOG_COMMAND,
LOG_SERVER,
LOG_CHANNEL,
LOG_USER,
LOG_NORMAL,
LOG_TERMINAL,
LOG_RAWIO,
LOG_DEBUG,
LOG_DEBUG_2,
LOG_DEBUG_3,
LOG_DEBUG_4
};
struct LogFile
{
Anope::string filename;
public:
std::ofstream stream;
LogFile(const Anope::string &name);
Anope::string GetName() const;
};
class CoreExport Log
{
public:
BotInfo *bi;
LogType Type;
Anope::string Category;
std::list<Anope::string> Sources;
std::stringstream buf;
Log(LogType type = LOG_NORMAL, const Anope::string &category = "", BotInfo *bi = Global);
/* LOG_COMMAND/OVERRIDE/ADMIN */
Log(LogType type, User *u, Command *c, ChannelInfo *ci = NULL);
/* LOG_CHANNEL */
Log(User *u, Channel *c, const Anope::string &category = "");
/* LOG_USER */
explicit Log(User *u, const Anope::string &category = "");
/* LOG_SERVER */
Log(Server *s, const Anope::string &category = "");
Log(BotInfo *b, const Anope::string &category = "");
~Log();
template<typename T> Log &operator<<(T val)
{
this->buf << val;
return *this;
}
};
class CoreExport LogInfo
{
public:
std::list<Anope::string> Targets;
std::map<Anope::string, LogFile *> Logfiles;
std::list<Anope::string> Sources;
int LogAge;
std::list<Anope::string> Admin;
std::list<Anope::string> Override;
std::list<Anope::string> Commands;
std::list<Anope::string> Servers;
std::list<Anope::string> Users;
std::list<Anope::string> Channels;
bool Normal;
bool RawIO;
bool Debug;
LogInfo(int logage, bool normal, bool rawio, bool debug);
~LogInfo();
void AddType(std::list<Anope::string> &list, const Anope::string &type);
bool HasType(std::list<Anope::string> &list, const Anope::string &type) const;
std::list<Anope::string> &GetList(LogType type);
bool HasType(LogType Type);
void ProcessMessage(const Log *l);
};
#endif // LOGGER_H
+2 -2
View File
@@ -66,7 +66,7 @@ if (true) \
} \
catch (const ModuleException &modexcept) \
{ \
Alog() << "Exception caught: " << modexcept.GetReason(); \
Log() << "Exception caught: " << modexcept.GetReason(); \
} \
_i = safei; \
} \
@@ -98,7 +98,7 @@ if (true) \
} \
catch (const ModuleException &modexcept) \
{ \
Alog() << "Exception caught: " << modexcept.GetReason(); \
Log() << "Exception caught: " << modexcept.GetReason(); \
} \
_i = safei; \
} \
+10 -31
View File
@@ -181,6 +181,7 @@ extern "C" void __pfnBkCheck() {}
/* Pull in the various bits of STL */
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <map>
@@ -253,6 +254,14 @@ class CoreException : public std::exception
}
};
class FatalException : public CoreException
{
public:
FatalException(const Anope::string &reason = "") : CoreException(reason) { }
virtual ~FatalException() throw() { }
};
class ModuleException : public CoreException
{
public:
@@ -939,6 +948,7 @@ class ServerConfig;
#include "operserv.h"
#include "mail.h"
#include "servers.h"
#include "logger.h"
#include "config.h"
class CoreExport IRCDProto
@@ -1039,10 +1049,6 @@ class CoreExport IRCDProto
virtual void SetAutoIdentificationToken(User *u) { }
};
class IRCDTS6Proto : public IRCDProto
{
};
/*************************************************************************/
struct Uplink
@@ -1055,33 +1061,6 @@ struct Uplink
Uplink(const Anope::string &_host, int _port, const Anope::string &_password, bool _ipv6) : host(_host), port(_port), password(_password), ipv6(_ipv6) { }
};
enum LogLevel
{
LOG_NORMAL,
LOG_TERMINAL,
LOG_DEBUG,
LOG_DEBUG_2,
LOG_DEBUG_3,
LOG_DEBUG_4
};
class CoreExport Alog
{
private:
std::stringstream buf;
LogLevel Level;
public:
Alog(LogLevel val = LOG_NORMAL);
~Alog();
template<typename T> Alog &operator<<(T val)
{
buf << val;
return *this;
}
};
/*************************************************************************/
#include "timers.h"
/** Timer for colliding nicks to force people off of nicknames
+5 -3
View File
@@ -76,10 +76,12 @@ class CoreExport User : public Extensible
/** Create a new user object, initialising necessary fields and
* adds it to the hash
*
* @param nick The nickname of the user.
* @param uid The unique identifier of the user.
* @param snick The nickname of the user.
* @param sident The username of the user
* @param shost The hostname of the user
* @param suid The unique identifier of the user.
*/
User(const Anope::string &nick, const Anope::string &uid);
User(const Anope::string &snick, const Anope::string &sident, const Anope::string &shost, const Anope::string &suid);
/** Destroy a user.
*/