Syslog.h

Go to the documentation of this file.
00001 #ifndef __SYSLOG_H__
00002 #define __SYSLOG_H__
00003 
00004 /*
00005 
00006 $Header$
00007 
00008 */
00009 
00010 #include "Support.h"
00011 #include "Singleton.h"
00012 #include "UdpConnection.h"
00013 #include "Registry.h"
00014 
00015 // Registry manuals.
00016 
00017 static const char *const MAN_SYSLOG_TAG = "\
00018 <registry>String syslog.tag(\"pylon\")</registry>\n\n\
00019 According to syslog protocol (RFC3164) the value will be considered as a \
00020 name of the program or process that generated the message.\
00021 ";
00022 
00023 static const char *const MAN_SYSLOG_COLLECTOR = "\
00024 <registry>String syslog.collector(\"255.255.255.255\")</registry>\n\n\
00025 Host name or IP address of syslog server which will collect the \
00026 messages. Value <value>\"255.255.255.255\"</value> means messaged \
00027 will be broadcasted. It is not a standard behavior (see RFC3164) \
00028 but usually syslog servers support it.\
00029 ";
00030 
00031 static const char *const MAN_SYSLOG_FACILITY = "\
00032 <registry>String syslog.facility(\"local5\")</registry>\n\n\
00033 Syslog facility that generates messages. Acceptable values are (see RFC3164):\n\
00034 <value>\"kernel\"</value> - kernel messages;\n\
00035 <value>\"user\"</value> - user-level messages;\n\
00036 <value>\"mail\"</value> - mail system;\n\
00037 <value>\"daemon\"</value> - system daemons;\n\
00038 <value>\"security\"</value> - security/authorization messages;\n\
00039 <value>\"syslog\"</value> - messages generated internally by syslogd;\n\
00040 <value>\"printer\"</value> - line printer subsystem;\n\
00041 <value>\"news\"</value> - network news subsystem;\n\
00042 <value>\"uucp\"</value> - UUCP subsystem;\n\
00043 <value>\"clock\"</value> - clock daemon;\n\
00044 <value>\"security2\"</value> - security/authorization messages;\n\
00045 <value>\"ftp\"</value> - FTP daemon;\n\
00046 <value>\"ntp\"</value> - NTP subsystem;\n\
00047 <value>\"log_audit\"</value> - log audit;\n\
00048 <value>\"log_alert\"</value> - log alert;\n\
00049 <value>\"clock2\"</value> - clock daemon;\n\
00050 <value>\"local0\"</value> - local use 0;\n\
00051 <value>\"local1\"</value> - local use 1;\n\
00052 <value>\"local2\"</value> - local use 2;\n\
00053 <value>\"local3\"</value> - local use 3;\n\
00054 <value>\"local4\"</value> - local use 4;\n\
00055 <value>\"local5\"</value> - local use 5;\n\
00056 <value>\"local6\"</value> - local use 6;\n\
00057 <value>\"local7\"</value> - local use 7.\
00058 ";
00059 
00060 static const char *const SYSLOG_PORT = "514";
00061 
00062 static const unsigned int SYSLOG_LIMIT_MSG_SIZE_MAX       = 1024;
00063 static const unsigned int SYSLOG_LIMIT_TIMESTAMP_SIZE_MAX = 32;
00064 
00065 typedef enum
00066 {
00067   SEVERITY_EMERGENCY = 0,
00068   SEVERITY_ALERT     = 1,
00069   SEVERITY_CRITICAL  = 2,
00070   SEVERITY_ERROR     = 3,
00071   SEVERITY_WARNING   = 4,
00072   SEVERITY_NOTICE    = 5,
00073   SEVERITY_INFO      = 6,
00074   SEVERITY_DEBUG     = 7
00075 } Severity;
00076 
00077 typedef enum
00078 {
00079   FACILITY_KERNEL    = 0,
00080   FACILITY_USER      = 1,
00081   FACILITY_MAIL      = 2,
00082   FACILITY_DAEMON    = 3,
00083   FACILITY_SECURITY  = 4,
00084   FACILITY_SYSLOG    = 5,
00085   FACILITY_PRINTER   = 6,
00086   FACILITY_NEWS      = 7,
00087   FACILITY_UUCP      = 8,
00088   FACILITY_CLOCK     = 9,
00089   FACILITY_SECURITY2 = 10,
00090   FACILITY_FTP       = 11,
00091   FACILITY_NTP       = 12,
00092   FACILITY_LOG_AUDIT = 13,
00093   FACILITY_LOG_ALERT = 14,
00094   FACILITY_CLOCK2    = 15,
00095   FACILITY_LOCAL0    = 16,
00096   FACILITY_LOCAL1    = 17,
00097   FACILITY_LOCAL2    = 18,
00098   FACILITY_LOCAL3    = 19,
00099   FACILITY_LOCAL4    = 20,
00100   FACILITY_LOCAL5    = 21,
00101   FACILITY_LOCAL6    = 22,
00102   FACILITY_LOCAL7    = 23
00103 } Facility;
00104 
00105 using namespace std;
00106 
00107 class Syslog : public Object,
00108                public Singleton<Syslog>
00109 
00110 {
00111 
00112 friend class Singleton<Syslog>;
00113 
00114   PYLON_OBJECT
00115 
00116 public:
00117 
00118   int log(const Severity severity, const String &msg);
00119   int log(const Severity &severity, const String &timestamp, const String &fileName,
00120           const unsigned int lineNum, const String &functionName, const String &msg);
00121 
00122   static Facility facilityId(const String &facility);
00123   static String facilityName(const Facility facility);
00124   static String severityName(const Severity severity);
00125 
00126   SLOT(setTag, const String &);
00127 
00128 private:
00129 
00130   REGISTRY(String, tag,       "pylon",           MAN_SYSLOG_TAG);
00131   REGISTRY(String, collector, "255.255.255.255", MAN_SYSLOG_COLLECTOR);
00132   REGISTRY(String, facility,  "local5",          MAN_SYSLOG_FACILITY);
00133 
00134   Syslog();
00135   virtual ~Syslog();
00136 
00137   String _tag;
00138   UdpConnection *_connection;
00139   unsigned int _facility;
00140 };
00141 
00142 inline
00143 Syslog *SYSLOG()
00144 {
00145   return Syslog::instance();
00146 }
00147 
00148 #endif

Generated on Thu Sep 6 20:11:25 2007 for Pylon Application Platform by  doxygen 1.5.1