2 PowerDNS Versatile Database Driven Nameserver
3 Copyright (C) 2005 PowerDNS.COM BV
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License version 2 as
7 published by the Free Software Foundation
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /* (C) 2002 POWERDNS.COM BV */
33 # define WINDOWS_LEAN_AND_MEAN
35 typedef int pthread_mutex_t;
36 typedef int pthread_t;
41 //! The Logger class can be used to log messages in various ways.
46 Logger(const string &, int facility=LOG_DAEMON); //!< pass the identification you wish to appear in the log
48 //! The urgency of a log message
49 enum Urgency {All=99999,NTLog=12345,Alert=LOG_ALERT, Critical=LOG_CRIT, Error=LOG_ERR, Warning=LOG_WARNING,
50 Notice=LOG_NOTICE,Info=LOG_INFO, Debug=LOG_DEBUG, None=-1};
53 Logger( const string &, int facility = 0 ); //!< pass the identification you wish to appear in the log
55 //! The urgency of a log message
60 Alert = EVENTLOG_ERROR_TYPE,
61 Critical= EVENTLOG_ERROR_TYPE,
62 Error = EVENTLOG_ERROR_TYPE,
63 Warning = EVENTLOG_WARNING_TYPE,
64 Notice = EVENTLOG_INFORMATION_TYPE,
65 Info = EVENTLOG_INFORMATION_TYPE,
66 Debug = EVENTLOG_INFORMATION_TYPE,
73 //! Handle used to communicate with the event log.
74 HANDLE m_eventLogHandle;
79 //! Log current message to the NT log?
80 map< pthread_t, bool > m_toNTLog;
87 \param msg Message you wish to log
88 \param Urgency Urgency of the message you wish to log
90 void log(const string &msg, Urgency u=Notice);
92 void setFacility(int f){d_facility=f;open();} //!< Choose logging facility
93 void setFlag(int f){flags|=f;open();} //!< set a syslog flag
94 void setName(const string &);
96 //! set lower limit of urgency needed for console display. Messages of this urgency, and higher, will be displayed
97 void toConsole(Urgency);
98 void setLoglevel( Urgency );
101 void toFile( const string & filename );
103 void resetFlags(){flags=0;open();} //!< zero the flags
104 /** Use this to stream to your log, like this:
106 L<<"This is an informational message"<<endl; // logged at default loglevel (Info)
107 L<<Logger::Warning<<"Out of diskspace"<<endl; // Logged as a warning
108 L<<"This is an informational message"<<endl; // logged AGAIN at default loglevel (Info)
111 Logger& operator<<(const string &s); //!< log a string
112 Logger& operator<<(int); //!< log an int
113 Logger& operator<<(unsigned int); //!< log an unsigned int
114 Logger& operator<<(long); //!< log an unsigned int
115 Logger& operator<<(unsigned long); //!< log an unsigned int
116 Logger& operator<<(unsigned long long); //!< log an unsigned 64 bit int
117 Logger& operator<<(Urgency); //!< set the urgency, << style
120 Logger& operator<<(ostream & (&)(ostream &)); //!< this is to recognise the endl, and to commit the log
122 // This is a hack to keep MSVC from generating a internal compiler error.
123 Logger& operator<<(ostream & (hack)(ostream &)); //!< this is to recognise the endl, and to commit the log
127 map<pthread_t,string>d_strings;
128 map<pthread_t,Urgency> d_outputurgencies;
135 Urgency consoleUrgency;
136 pthread_mutex_t lock;
139 extern Logger &theL(const string &pname="");