]>
git.ipfire.org Git - thirdparty/pdns.git/blob - pdns/logger.cc
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 Additionally, the license of this program contains a special
10 exception which allows to distribute the program in binary form when
11 it is linked against OpenSSL.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 #include "namespaces.hh"
32 Logger
&theL(const string
&pname
)
34 static Logger
l("", LOG_DAEMON
);
40 void Logger::log(const string
&msg
, Urgency u
)
47 if(u
<=consoleUrgency
) {// Sep 14 06:52:09
49 strftime(buffer
,sizeof(buffer
),"%b %d %H:%M:%S ", &tm
);
53 if( u
<= d_loglevel
) {
55 S
.ringAccount("logmessages",msg
);
57 syslog(u
,"%s",msg
.c_str());
61 void Logger::setLoglevel( Urgency u
)
67 void Logger::toConsole(Urgency u
)
76 openlog(name
.c_str(),flags
,d_facility
);
80 void Logger::setName(const string
&_name
)
86 Logger::Logger(const string
&n
, int facility
)
89 flags
=LOG_PID
|LOG_NDELAY
;
93 pthread_mutex_init(&lock
,0);
98 Logger
& Logger::operator<<(Urgency u
)
100 pthread_mutex_lock(&lock
);
102 d_outputurgencies
[pthread_self()]=u
;
104 pthread_mutex_unlock(&lock
);
108 Logger
& Logger::operator<<(const string
&s
)
110 pthread_mutex_lock(&lock
);
112 if(!d_outputurgencies
.count(pthread_self())) // default urgency
113 d_outputurgencies
[pthread_self()]=Info
;
115 // if(d_outputurgencies[pthread_self()]<=(unsigned int)consoleUrgency) // prevent building strings we won't ever print
116 d_strings
[pthread_self()].append(s
);
118 pthread_mutex_unlock(&lock
);
122 Logger
& Logger::operator<<(int i
)
132 Logger
& Logger::operator<<(double i
)
140 Logger
& Logger::operator<<(unsigned int i
)
150 Logger
& Logger::operator<<(unsigned long i
)
160 Logger
& Logger::operator<<(unsigned long long i
)
171 Logger
& Logger::operator<<(long i
)
181 Logger
& Logger::operator<<(ostream
& (&)(ostream
&))
183 // *this<<" ("<<(int)d_outputurgencies[pthread_self()]<<", "<<(int)consoleUrgency<<")";
184 pthread_mutex_lock(&lock
);
186 log(d_strings
[pthread_self()], d_outputurgencies
[pthread_self()]);
187 d_strings
.erase(pthread_self());
188 d_outputurgencies
.erase(pthread_self());
190 pthread_mutex_unlock(&lock
);