r17864 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r17863‎ | r17864 | r17865 >
Date:22:42, 22 November 2006
Author:river
Status:old
Tags:
Comment:
logging should be better encapsulated
Modified paths:
  • /trunk/willow/src/include/cache.h (modified) (history)
  • /trunk/willow/src/include/dbwrap.h (modified) (history)
  • /trunk/willow/src/include/flowio.h (modified) (history)
  • /trunk/willow/src/include/wlog.h (modified) (history)
  • /trunk/willow/src/libwillow/mbuffer.cc (modified) (history)
  • /trunk/willow/src/willow/cache.cc (modified) (history)
  • /trunk/willow/src/willow/cachedentity.cc (modified) (history)
  • /trunk/willow/src/willow/cachedir_data_store.cc (modified) (history)
  • /trunk/willow/src/willow/chunking.cc (modified) (history)
  • /trunk/willow/src/willow/confparse.cc (modified) (history)
  • /trunk/willow/src/willow/dbwrap.cc (modified) (history)
  • /trunk/willow/src/willow/flowio.cc (modified) (history)
  • /trunk/willow/src/willow/htcp.cc (modified) (history)
  • /trunk/willow/src/willow/wbackend.cc (modified) (history)
  • /trunk/willow/src/willow/wconfig.cc (modified) (history)
  • /trunk/willow/src/willow/whttp.cc (modified) (history)
  • /trunk/willow/src/willow/whttp_header.cc (modified) (history)
  • /trunk/willow/src/willow/willow.cc (modified) (history)
  • /trunk/willow/src/willow/wlog.cc (modified) (history)
  • /trunk/willow/src/willow/wnet.cc (modified) (history)
  • /trunk/willow/willow.conf.example (modified) (history)

Diff [purge]

Index: trunk/willow/src/include/flowio.h
@@ -162,7 +162,7 @@
163163
164164 sink_result data_ready(char const *buf, size_t len, ssize_t &discard);
165165 sink_result data_empty(void) {
166 - WDEBUG((WLOG_DEBUG, "socket_sink::data_empty"));
 166+ WDEBUG("socket_sink::data_empty");
167167 _reg = false;
168168 return sink_result_finished;
169169 }
@@ -323,7 +323,7 @@
324324
325325 sink_result data_empty () {
326326 sink_result res;
327 - WDEBUG((WLOG_DEBUG, "buffering_filter: data_empty"));
 327+ WDEBUG("buffering_filter: data_empty");
328328 res = bf_eof();
329329 if (res != sink_result_finished)
330330 return res;
Index: trunk/willow/src/include/cache.h
@@ -90,9 +90,8 @@
9191 * Assume it's valid if the time it was last validated is
9292 * less than 25% greater than its age.
9393 */
94 - WDEBUG((WLOG_DEBUG,
95 - str(format("expired: now=%d, revalidating at %d")
96 - % time(0) % _revalidate_at)));
 94+ WDEBUG((format("expired: now=%d, revalidating at %d")
 95+ % time(0) % _revalidate_at));
9796 if (_revalidate_at <= time(0)) {
9897 _complete = false;
9998 return true;
@@ -269,13 +268,11 @@
270269 if (create) {
271270 _file.open(path.c_str(), ios::out | ios::binary | ios::trunc);
272271 if (!_file)
273 - wlog(WLOG_WARNING,
274 - format("creating cache file %s: %s")
 272+ wlog.warn(format("creating cache file %s: %s")
275273 % path % strerror(errno));
276274 }else {
277275 if (stat(path.c_str(), &sb) == -1) {
278 - wlog(WLOG_WARNING,
279 - format("cache file %s: %s")
 276+ wlog.warn(format("cache file %s: %s")
280277 % path % strerror(errno));
281278 return;
282279 }
@@ -503,10 +500,9 @@
504501 ssize_t disc = 0;
505502 io::sink_result res;
506503 for (;;) {
507 - WDEBUG((WLOG_DEBUG,
508 - str(format("cached_spigot: %d left, off %d fd %d")
 504+ WDEBUG(format("cached_spigot: %d left, off %d fd %d")
509505 % (_ent->_data.size() - _off)
510 - % _off % _ent->_data.fd())));
 506+ % _off % _ent->_data.fd());
511507 if (_dio) {
512508 res = _sp_dio_ready(_ent->_data.fd(), _off,
513509 _ent->_data.size() - _off, disc);
@@ -518,23 +514,22 @@
519515 switch (res) {
520516 case io::sink_result_finished:
521517 _sp_completed_callee();
522 - WDEBUG((WLOG_DEBUG, "all finished"));
 518+ WDEBUG("all finished");
523519 return;
524520 case io::sink_result_okay:
525521 if (_off == _ent->_data.size()) {
526522 _sp_completed_callee();
527523 return;
528524 }
529 - WDEBUG((WLOG_DEBUG, "continuing"));
 525+ WDEBUG("continuing");
530526 continue;
531527 case io::sink_result_error:
532 - WDEBUG((WLOG_DEBUG, str(format("error %s")
533 - % strerror(errno))));
 528+ WDEBUG(format("error %s") % strerror(errno));
534529 _sp_error_callee();
535530 return;
536531 case io::sink_result_blocked:
537532 sp_cork();
538 - WDEBUG((WLOG_DEBUG, "blocked"));
 533+ WDEBUG("blocked");
539534 return;
540535 }
541536 }
Index: trunk/willow/src/include/wlog.h
@@ -21,35 +21,51 @@
2222 #include "config.h"
2323 #include "ptalloc.h"
2424
25 -#define WLOG_DEBUG 0
26 -#define WLOG_NOTICE 1
27 -#define WLOG_WARNING 2
28 -#define WLOG_ERROR 3
29 -#define WLOG_MAX 3
 25+enum log_level {
 26+ ll_debug,
 27+ ll_notice,
 28+ ll_warn,
 29+ ll_error
 30+};
3031
31 -extern struct log_variables {
32 - string file;
33 - int level;
34 - ofstream fp;
35 - bool syslog;
36 - int facility;
37 -} logging;
 32+struct logger {
 33+ logger();
3834
39 -void wlog_init(void);
40 -void wlog(int, string const &);
 35+ void syslog (bool, int facility = 0);
 36+ void level (log_level);
 37+ bool file (string const &fname);
4138
42 -template<typename charT, typename traits, typename allocator>
43 -void wlog(int lev, basic_format<charT, traits, allocator> const &f)
44 -{
45 - wlog(lev, str(f));
46 -}
 39+ bool open(void);
 40+ void close(void);
4741
48 -void wlog_close(void);
 42+ void debug (format const &f) { _log(ll_debug, str(f)); }
 43+ void notice(format const &f) { _log(ll_notice, str(f));}
 44+ void warn (format const &f) { _log(ll_warn, str(f)); }
 45+ void error (format const &f) { _log(ll_error, str(f)); }
4946
 47+ void debug (string const &s) { _log(ll_debug, s); }
 48+ void notice(string const &s) { _log(ll_notice, s); }
 49+ void warn (string const &s) { _log(ll_warn, s); }
 50+ void error (string const &s) { _log(ll_error, s); }
 51+
 52+private:
 53+ bool _syslog;
 54+ int _facility;
 55+ log_level _level;
 56+ string _file;
 57+
 58+ ofstream *_fp;
 59+ lockable _lock;
 60+
 61+ void _log(log_level l, string const &);
 62+};
 63+
 64+extern logger wlog;
 65+
5066 #ifndef WILLOW_DEBUG
5167 # define WDEBUG(x) ((void)0)
5268 #else
53 -# define WDEBUG(x) wlog x
 69+# define WDEBUG(x) wlog.debug(x)
5470 #endif
5571
5672 #endif
Index: trunk/willow/src/include/dbwrap.h
@@ -244,9 +244,9 @@
245245 database<Key, Value, Datastore>::errcall(DB_ENV const *, char const *pfx, char const *msg)
246246 {
247247 if (pfx)
248 - wlog(WLOG_WARNING, str(format("%s: %s") % pfx % msg));
 248+ wlog.warn(format("%s: %s") % pfx % msg);
249249 else
250 - wlog(WLOG_WARNING, msg);
 250+ wlog.warn(msg);
251251 }
252252
253253 template<typename Key, typename Value, typename Datastore>
Index: trunk/willow/src/libwillow/mbuffer.cc
@@ -23,7 +23,7 @@
2424 marshalling_buffer::extract<imstring>(imstring &s)
2525 {
2626 size_t sz = 0;
27 - WDEBUG((WLOG_DEBUG, "DB: extracting an imstring"));
 27+ WDEBUG("DB: extracting an imstring");
2828 if (!extract<size_t>(sz))
2929 return false;
3030 if (_size + sz > _bufsz)
Index: trunk/willow/src/willow/cache.cc
@@ -45,8 +45,8 @@
4646 if (it != _entities.end()) {
4747 shared_ptr<cachedentity> ret(it->second);
4848 /* entity was cached */
49 - WDEBUG((WLOG_DEBUG, str(format("[%s] cached, complete=%d")
50 - % url % ret->_complete)));
 49+ WDEBUG(format("[%s] cached, complete=%d")
 50+ % url % ret->_complete);
5151 wasnew = false;
5252 _lru.erase(it);
5353 it->second->reused();
@@ -63,21 +63,20 @@
6464 e = _db->get(url);
6565 if (e != NULL) {
6666 shared_ptr<cachedentity> ret(e);
67 - WDEBUG((WLOG_DEBUG,
68 - str(format("found [%s] in disk cache complete %d void %d")
69 - % url % e->complete() % e->isvoid())));
 67+ WDEBUG(format("found [%s] in disk cache complete %d void %d")
 68+ % url % e->complete() % e->isvoid());
7069 _lru.insert(_entities.insert(make_pair(url, ret)).first);
7170 wasnew = false;
7271 ret->ref();
7372 return ret;
7473 }
7574 if (_db->error() && _db->error() != DB_NOTFOUND) {
76 - wlog(WLOG_WARNING, str(format("fetching cached data: %s")
77 - % _db->strerror()));
 75+ wlog.warn(format("fetching cached data: %s")
 76+ % _db->strerror());
7877 }
7978 }
8079
81 - WDEBUG((WLOG_DEBUG, str(format("[%s] not cached") % url)));
 80+ WDEBUG(format("[%s] not cached") % url);
8281 if (!create)
8382 return shared_ptr<cachedentity>();
8483
@@ -168,14 +167,14 @@
169168 void
170169 httpcache::_swap_out(cachedentity *ent)
171170 {
172 - WDEBUG((WLOG_DEBUG, str(format("swapping out %s") % ent->url())));
 171+ WDEBUG(format("swapping out %s") % ent->url());
173172 HOLDING(_lock);
174173 if (!_db)
175174 return;
176175 _db->put(ent->url(), *ent);
177176 if (_db->error()) {
178 - wlog(WLOG_WARNING, str(format("storing cached data: %s")
179 - % _db->strerror()));
 177+ wlog.warn(format("storing cached data: %s")
 178+ % _db->strerror());
180179 }
181180 }
182181
@@ -218,9 +217,8 @@
219218
220219 _env = db::environment::open(config.cache_master);
221220 if (_env->error()) {
222 - wlog(WLOG_ERROR,
223 - str(format("cannot open cache master environment \"%s\": %s")
224 - % config.cache_master % _env->strerror()));
 221+ wlog.error(format("cannot open cache master environment \"%s\": %s")
 222+ % config.cache_master % _env->strerror());
225223 delete _env;
226224 _env = NULL;
227225 return false;
@@ -229,9 +227,8 @@
230228 _db = _env->open_database<imstring, cachedentity,
231229 cachedir_data_store>("objects", _store);
232230 if (_db->error()) {
233 - wlog(WLOG_ERROR,
234 - str(format("cannot open cache master database \"%s\": %s")
235 - % config.cache_master % _db->strerror()));
 231+ wlog.error(format("cannot open cache master database \"%s\": %s")
 232+ % config.cache_master % _db->strerror());
236233 _env->close();
237234 delete _env;
238235 delete _db;
@@ -246,22 +243,22 @@
247244 httpcache::create(void)
248245 {
249246 if (config.cache_master.empty()) {
250 - wlog(WLOG_ERROR, "no cache master to create");
 247+ wlog.error("no cache master to create");
251248 return false;
252249 }
253250
254251 _store = new cachedir_data_store;
255252
256253 if (mkdir(config.cache_master.c_str(), 0700) < 0) {
257 - wlog(WLOG_ERROR, format("cannot create cache master \"%s\": %s")
 254+ wlog.error(format("cannot create cache master \"%s\": %s")
258255 % config.cache_master % strerror(errno));
259256 return false;
260257 }
261258
262259 _env = db::environment::create(config.cache_master);
263260 if (_env->error()) {
264 - wlog(WLOG_ERROR,
265 - format("cannot create cache master environmet \"%s\": %s")
 261+ wlog.error(format(
 262+ "cannot create cache master environmet \"%s\": %s")
266263 % config.cache_master % _env->strerror());
267264 delete _env;
268265 _env = NULL;
@@ -271,8 +268,8 @@
272269 _db = _env->create_database<imstring, cachedentity,
273270 cachedir_data_store>("objects", _store);
274271 if (_db->error()) {
275 - wlog(WLOG_ERROR,
276 - format("cannot create cache master database \"%s\": %s")
 272+ wlog.error(format(
 273+ "cannot create cache master database \"%s\": %s")
277274 % config.cache_master % _db->strerror());
278275 _env->close();
279276 delete _env;
Index: trunk/willow/src/willow/cachedentity.cc
@@ -27,8 +27,7 @@
2828 , _expires(0)
2929 , _modified(0)
3030 {
31 - WDEBUG((WLOG_DEBUG, format("CACHE: creating cached entity with URL %s")
32 - % url));
 31+ WDEBUG(format("CACHE: creating cached entity with URL %s") % url);
3332 assert(_url.size());
3433 }
3534
@@ -49,7 +48,7 @@
5049 }
5150
5251 if (!entitycache.cache_mem_increase(size, this)) {
53 - WDEBUG((WLOG_DEBUG, "object is too large, voiding cache"));
 52+ WDEBUG("object is too large, voiding cache");
5453 _void = true;
5554 return;
5655 }
@@ -70,7 +69,7 @@
7170 cachedentity::set_complete(void)
7271 {
7372 header *h;
74 - WDEBUG((WLOG_DEBUG, format("set_complete: void=%d") % _void));
 73+ WDEBUG(format("set_complete: void=%d") % _void);
7574 if (_void)
7675 return;
7776 _headers.remove("transfer-encoding");
@@ -112,7 +111,7 @@
113112 return;
114113 }
115114
116 - WDEBUG((WLOG_DEBUG, format("CACHE: object lifetime=%d sec.") % _lifetime));
 115+ WDEBUG(format("CACHE: object lifetime=%d sec.") % _lifetime);
117116 revalidated();
118117 _builthdrs = _headers.build();
119118 _builtsz = _headers.length();
@@ -157,8 +156,7 @@
158157 size_t bufsz;
159158 if (!buf.extract<imstring>(url))
160159 return NULL;
161 - WDEBUG((WLOG_DEBUG, format("unmarshall: URL [%s], len %d")
162 - % url % url.size()));
 160+ WDEBUG(format("unmarshall: URL [%s], len %d") % url % url.size());
163161 ret = new cachedentity(url);
164162 if (!buf.extract<imstring>(ret->_status)) {
165163 delete ret;
@@ -242,10 +240,9 @@
243241 assert(f);
244242 if (!f->okay())
245243 return false;
246 - WDEBUG((WLOG_DEBUG, format("CACHE: writing cached data to %s")
247 - % f->filename()));
 244+ WDEBUG(format("CACHE: writing cached data to %s") % f->filename());
248245 if (!sm.write(_data.ptr(), _data.size())) {
249 - wlog(WLOG_WARNING, format("writing cached data to %s: %s")
 246+ wlog.warn(format("writing cached data to %s: %s")
250247 % f->filename() % strerror(errno));
251248 return false;
252249 }
Index: trunk/willow/src/willow/whttp.cc
@@ -392,9 +392,9 @@
393393 char dstr[64];
394394 struct tm tm;
395395 time_t mod = _cachedent->modified();
396 - WDEBUG((WLOG_DEBUG,
397 - format("HTTP: need to revalidate, %d refs")
398 - % _cachedent->refs()));
 396+ WDEBUG(format(
 397+ "HTTP: need to revalidate, %d refs")
 398+ % _cachedent->refs());
399399 gmtime_r(&mod, &tm);
400400 /* need to revalidate */
401401 if (_cachedent->refs() == 1) {
@@ -519,7 +519,7 @@
520520 void
521521 httpcllr::header_read_error(void)
522522 {
523 - WDEBUG((WLOG_DEBUG, format("header read error errno=%s") % strerror(errno)));
 523+ WDEBUG(format("header read error errno=%s") % strerror(errno));
524524
525525 if (_header_parser->_eof) {
526526 force_end_request();
@@ -821,7 +821,7 @@
822822 snprintf(cache_hit_hdr, hsize, "HIT from %s", my_hostname);
823823 snprintf(cache_miss_hdr, hsize, "MISS from %s", my_hostname);
824824
825 - wlog(WLOG_NOTICE, format("whttp: starting %d worker threads")
 825+ wlog.notice(format("whttp: starting %d worker threads")
826826 % config.nthreads);
827827 for (int i = 0; i < config.nthreads; ++i) {
828828 http_thread *t = new http_thread;
@@ -843,11 +843,11 @@
844844 map<wsocket *, listener *>::iterator lsnit;
845845
846846 if (s->read((char *)socks, sizeof(socks)) < (int)sizeof(socks)) {
847 - wlog(WLOG_ERROR, format("accept_wakeup: reading fd: %s")
 847+ wlog.error(format("accept_wakeup: reading fd: %s")
848848 % strerror(errno));
849849 exit(1);
850850 }
851 - WDEBUG((WLOG_DEBUG, format("accept_wakeup, lsnr = %d") % socks[1]));
 851+ WDEBUG(format("accept_wakeup, lsnr = %d") % socks[1]);
852852 s->readback(polycaller<wsocket *, int>(*this,
853853 &http_thread::accept_wakeup), 0);
854854 if ((lsnit = sock2lsn.find(socks[1])) == sock2lsn.end())
@@ -922,7 +922,7 @@
923923 if (config.access_log.size()) {
924924 alf.open(config.access_log.c_str(), ofstream::app);
925925 if (!alf.good()) {
926 - wlog(WLOG_WARNING, format("opening %s: %s")
 926+ wlog.warn(format("opening %s: %s")
927927 % config.access_log % strerror(errno));
928928 }
929929 }
@@ -937,14 +937,14 @@
938938 config.udplog_port, st_dgram, "UDP logger", prio_norm);
939939 udplog_sock->connect();
940940 } catch (socket_error &e) {
941 - wlog(WLOG_WARNING,
942 - format("connecting to UDP log host %s: %s; disabling UDP logging")
 941+ wlog.warn(format(
 942+ "connecting to UDP log host %s: %s; disabling UDP logging")
943943 % config.udplog_host % e.what());
944944 return;
945945 }
946946
947947 do_udplog = true;
948 - wlog(WLOG_NOTICE, format("UDP logging to %s%s, sample rate 1/%d")
 948+ wlog.notice(format("UDP logging to %s%s, sample rate 1/%d")
949949 % config.udplog_host
950950 % udplog_sock->straddr()
951951 % config.log_sample);
@@ -1170,8 +1170,8 @@
11711171 HOLDING(alf_lock);
11721172
11731173 if (!(alf << line << endl)) {
1174 - wlog(WLOG_ERROR,
1175 - format("writing access log: %s; log will be closed")
 1174+ wlog.error(format(
 1175+ "writing access log: %s; log will be closed")
11761176 % strerror(errno));
11771177 alf.close();
11781178 }
Index: trunk/willow/src/willow/chunking.cc
@@ -41,7 +41,7 @@
4242 io::sink_result
4343 chunking_filter::bf_eof(void)
4444 {
45 - WDEBUG((WLOG_DEBUG, "chunking_filter: EOF"));
 45+ WDEBUG("chunking_filter: EOF");
4646 _buf.add("\r\n0\r\n\r\n", 7, false);
4747 return io::sink_result_finished;
4848 }
Index: trunk/willow/src/willow/cachedir_data_store.cc
@@ -30,12 +30,12 @@
3131 {
3232 assert(dirn >= 0);
3333 if (dirn > (int)_cachedirs.size()) {
34 - wlog(WLOG_WARNING,
35 - format("trying to open cachedir %d, but only %d configured")
 34+ wlog.warn(format(
 35+ "trying to open cachedir %d, but only %d configured")
3636 % dirn % _cachedirs.size());
37 - wlog(WLOG_WARNING,
 37+ wlog.warn(
3838 "this probably means the cachedir configuration has been "
39 - "changed but old cache-master data is being used");
 39+ "changed but old cache-master data is being used");
4040 return NULL;
4141 }
4242 return _cachedirs[dirn]->open(num);
@@ -51,7 +51,7 @@
5252 int d;
5353 { HOLDING(_lock);
5454 d = _curdir++;
55 - WDEBUG((WLOG_DEBUG, format("got cachedir %d of %d") % d % _cachedirs.size()));
 55+ WDEBUG(format("got cachedir %d of %d") % d % _cachedirs.size());
5656 if (_curdir == _cachedirs.size())
5757 _curdir = 0;
5858 }
@@ -71,11 +71,11 @@
7272 * Read the cached data from the cachedir.
7373 */
7474 ent = m.unmarshall(d);
75 - WDEBUG((WLOG_DEBUG, format("CACHE: unmarshalling a cached entity, dir=%d")
76 - % ent->cachedir()));
 75+ WDEBUG(format("CACHE: unmarshalling a cached entity, dir=%d")
 76+ % ent->cachedir());
7777 if (ent == NULL)
7878 return NULL;
79 - WDEBUG((WLOG_DEBUG, format("CACHE: loading cache data for %s") % ent->url()));
 79+ WDEBUG(format("CACHE: loading cache data for %s") % ent->url());
8080 assert(ent->complete() && !ent->isvoid());
8181 ent->loadcachefile();
8282 return ent;
@@ -97,8 +97,7 @@
9898 */
9999 cachefile *f = nextfile();
100100 o.savecachefile(f);
101 - WDEBUG((WLOG_DEBUG, format("CACHE: storing %s, dir=%d")
102 - % o.url() % o.cachedir()));
 101+ WDEBUG(format("CACHE: storing %s, dir=%d") % o.url() % o.cachedir());
103102 ret = m.marshall(o);
104103 delete f;
105104 return ret;
Index: trunk/willow/src/willow/wlog.cc
@@ -30,8 +30,7 @@
3131 #include "wconfig.h"
3232 #include "format.h"
3333
34 -struct log_variables logging;
35 -static lockable log_lock;
 34+logger wlog;
3635
3736 static const char *sev_names[] = {
3837 "Debug",
@@ -47,43 +46,45 @@
4847 LOG_ERR,
4948 };
5049
51 -void
52 -wlog_init(void)
 50+bool
 51+logger::open(void)
5352 {
54 - if (logging.syslog)
55 - openlog("willow", LOG_PID, logging.facility);
 53+ if (_syslog)
 54+ openlog("willow", LOG_PID, _facility);
5655
57 - if (logging.file.empty())
58 - return;
 56+ if (_file.empty())
 57+ return true;
5958
60 - logging.fp.open(logging.file.c_str(), ios::app);
61 - if (!logging.fp.is_open()) {
62 - wlog(WLOG_ERROR, format("cannot open error log file %s: %s")
63 - % logging.file % strerror(errno));
64 - exit(8);
 59+ _fp = new ofstream(_file.c_str(), ios::app);
 60+ if (!_fp->is_open()) {
 61+ wlog.error(format("cannot open error log file %s: %s")
 62+ % _file % strerror(errno));
 63+ delete _fp;
 64+ _fp = NULL;
 65+ return false;
6566 }
 67+
 68+ return true;
6669 }
6770
6871 void
69 -wlog(int sev, string const &e)
 72+logger::_log(log_level sev, string const &e)
7073 {
7174 string r;
7275
73 - if (sev > WLOG_MAX)
74 - sev = WLOG_NOTICE;
75 - if (sev < logging.level)
 76+ if (sev < _level)
7677 return;
7778
7879 r = str(format("%s| %s: %s") % current_time_short % sev_names[sev] % e);
7980
80 - HOLDING(log_lock);
81 - if (logging.syslog)
82 - syslog(syslog_pri[sev], "%s", e.c_str());
 81+ HOLDING(_lock);
 82+ if (_syslog)
 83+ ::syslog(syslog_pri[sev], "%s", e.c_str());
8384
84 - if (logging.fp.is_open()) {
85 - if (!(logging.fp << r << '\n')) {
86 - logging.fp.close();
87 - wlog(WLOG_ERROR, format("writing to logfile: %s")
 85+ if (_fp) {
 86+ if (!(*_fp << r << '\n')) {
 87+ _fp->close();
 88+ wlog.error(format("writing to logfile: %s")
8889 % strerror(errno));
8990 exit(8);
9091 }
@@ -94,11 +95,40 @@
9596 }
9697
9798 void
98 -wlog_close(void)
 99+logger::close(void)
99100 {
100 - if (logging.fp.is_open())
101 - logging.fp.close();
 101+ HOLDING(_lock);
 102+
 103+ if (_fp)
 104+ _fp->close();
102105
103 - if (logging.syslog)
 106+ if (_syslog)
104107 closelog();
105108 }
 109+
 110+void
 111+logger::syslog(bool do_, int facility)
 112+{
 113+ _syslog = do_;
 114+ _facility = facility;
 115+}
 116+
 117+bool
 118+logger::file(string const &file)
 119+{
 120+ _file = file;
 121+ return true;
 122+}
 123+
 124+void
 125+logger::level(log_level l)
 126+{
 127+ _level = l;
 128+}
 129+
 130+logger::logger(void)
 131+ : _syslog(false)
 132+ , _facility(0)
 133+ , _level(ll_notice)
 134+{
 135+}
Index: trunk/willow/src/willow/willow.cc
@@ -164,7 +164,8 @@
165165 }
166166 }
167167
168 - wlog_init();
 168+ if (!wlog.open())
 169+ return 1;
169170
170171 if (zflag) {
171172 if (!entitycache.create())
@@ -182,14 +183,14 @@
183184 stats_init();
184185 htcp_init();
185186
186 - wlog(WLOG_NOTICE, "running");
 187+ wlog.notice("running");
187188
188189 if (!config.foreground)
189190 daemon(0, 0);
190191
191192 ioloop->run();
192 - wlog(WLOG_NOTICE, "shutting down");
193 - wlog_close();
 193+ wlog.notice("shutting down");
 194+ wlog.close();
194195 whttp_shutdown();
195196 entitycache.close();
196197
@@ -205,7 +206,7 @@
206207 if (count++)
207208 abort();
208209
209 - wlog(WLOG_ERROR, "fatal: out of memory. exiting.");
 210+ wlog.error("fatal: out of memory. exiting.");
210211 exit(8);
211212 }
212213
@@ -393,7 +394,7 @@
394395 try {
395396 alist = addrlist::resolve(hstr, pstr, st_dgram);
396397 } catch (socket_error &e) {
397 - wlog(WLOG_WARNING, format("resolving [%s]:%s: %s")
 398+ wlog.warn(format("resolving [%s]:%s: %s")
398399 % hstr % pstr % e.what());
399400 return;
400401 }
@@ -405,8 +406,7 @@
406407 sock = it->makesocket("statistics listener", prio_stats);
407408 sock->nonblocking(true);
408409 } catch (socket_error &e) {
409 - wlog(WLOG_WARNING,
410 - format("creating statistics listener: %s:%s: %s")
 410+ wlog.warn(format("creating statistics listener: %s:%s: %s")
411411 % ip.first % ip.second % e.what());
412412 delete sock;
413413 continue;
@@ -415,8 +415,7 @@
416416 try {
417417 sock->bind();
418418 } catch (socket_error &e) {
419 - wlog(WLOG_WARNING,
420 - format("binding statistics listener %s: %s")
 419+ wlog.warn(format("binding statistics listener %s: %s")
421420 % it->straddr() % e.what());
422421 delete sock;
423422 continue;
@@ -424,7 +423,7 @@
425424
426425 sock->readback(polycaller<wsocket *, int>(stats_handler,
427426 &stats_handler_stru::callback), 0);
428 - wlog(WLOG_NOTICE, format("statistics listener: %s")
 427+ wlog.notice(format("statistics listener: %s")
429428 % sock->straddr());
430429 }
431430 }
@@ -454,7 +453,7 @@
455454 munmap(_buf, _size);
456455 _size = newsize;
457456 _reserved = pagesize * (newsize / pagesize + 1);
458 - WDEBUG((WLOG_DEBUG, format("new size %d reserved %d") % _size % _reserved));
 457+ WDEBUG(format("new size %d reserved %d") % _size % _reserved);
459458 lseek(_fd, _reserved, SEEK_SET);
460459 write(_fd, "", 1);
461460 _buf = (char *)mmap(0, _reserved, PROT_READ | PROT_WRITE, MAP_SHARED, _fd, 0);
@@ -493,7 +492,7 @@
494493 , _size(0)
495494 , _reserved(pagesize * (size / pagesize + 1))
496495 {
497 - WDEBUG((WLOG_DEBUG, format("reserved: %d") % _reserved));
 496+ WDEBUG(format("reserved: %d") % _reserved);
498497
499498 if (size == 0)
500499 _reserved = size = pagesize;
@@ -506,7 +505,7 @@
507506 snprintf(path, sizeof(path), "/dev/shm/willow.diobuf.%d.%d.%d",
508507 (int) getpid(), (int) pthread_self(), rand());
509508 if ((_fd = open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) {
510 - wlog(WLOG_WARNING, format("opening diobuf %s: %s")
 509+ wlog.warn(format("opening diobuf %s: %s")
511510 % path % strerror(errno));
512511 _buf = new char[size];
513512 return;
@@ -514,7 +513,7 @@
515514 unlink(path);
516515
517516 if (lseek(_fd, _reserved, SEEK_SET) == -1) {
518 - wlog(WLOG_WARNING, format("seeking diobuf %s: %s")
 517+ wlog.warn(format("seeking diobuf %s: %s")
519518 % path % strerror(errno));
520519 close(_fd);
521520 _fd = -1;
@@ -523,7 +522,7 @@
524523 }
525524
526525 if (write(_fd, "", 1) < 1) {
527 - wlog(WLOG_WARNING, format("extending diobuf %s: %s")
 526+ wlog.warn(format("extending diobuf %s: %s")
528527 % path % strerror(errno));
529528 close(_fd);
530529 _fd = -1;
@@ -533,7 +532,7 @@
534533
535534 _buf = (char *)mmap(0, _reserved, PROT_READ | PROT_WRITE, MAP_SHARED, _fd, 0);
536535 if (_buf == MAP_FAILED) {
537 - wlog(WLOG_WARNING, format("mapping diobuf %s: %s")
 536+ wlog.warn(format("mapping diobuf %s: %s")
538537 % path % strerror(errno));
539538 close(_fd);
540539 _fd = -1;
Index: trunk/willow/src/willow/wnet.cc
@@ -99,7 +99,7 @@
100100 {
101101 size_t i;
102102
103 - wlog(WLOG_NOTICE, format("maximum number of open files: %d")
 103+ wlog.notice(format("maximum number of open files: %d")
104104 % getdtablesize());
105105
106106 signal(SIGPIPE, SIG_IGN);
@@ -112,14 +112,14 @@
113113 lns->sock->bind();
114114 lns->sock->listen();
115115 } catch (socket_error &e) {
116 - wlog(WLOG_ERROR, format("creating listener %s: %s")
 116+ wlog.error(format("creating listener %s: %s")
117117 % lns->sock->straddr() % e.what());
118118 exit(8);
119119 }
120120
121121 lns->sock->readback(polycaller<wsocket *, int>(*this, &ioloop_t::_accept), 0);
122122 }
123 - wlog(WLOG_NOTICE, format("wnet: initialised, using libevent %s (%s)")
 123+ wlog.notice(format("wnet: initialised, using libevent %s (%s)")
124124 % event_get_version() % event_get_method());
125125 secondly_sched();
126126 }
@@ -135,8 +135,7 @@
136136 if ((errno != ENFILE && errno != EMFILE) || (now - last_nfile) > 60) {
137137 if (errno == ENFILE || errno == EMFILE)
138138 last_nfile = now;
139 - wlog(WLOG_NOTICE, format("accept error: %s")
140 - % strerror(errno));
 139+ wlog.warn(format("accept error: %s") % strerror(errno));
141140 }
142141 s->readback(polycaller<wsocket *, int>(*this, &ioloop_t::_accept), 0);
143142 return;
@@ -151,10 +150,10 @@
152151 char buf[sizeof(wsocket *) * 2];
153152 memcpy(buf, &newe, sizeof(newe));
154153 memcpy(buf + sizeof(newe), &s, sizeof(s));
155 - WDEBUG((WLOG_DEBUG, format("_accept, lsnr=%d") % s));
 154+ WDEBUG(format("_accept, lsnr=%d") % s);
156155
157156 if (awaks[cawak]->write(buf, sizeof(wsocket *) * 2) < 0) {
158 - wlog(WLOG_ERROR, format("writing to thread wakeup socket: %s")
 157+ wlog.error(format("writing to thread wakeup socket: %s")
159158 % strerror(errno));
160159 exit(1);
161160 }
@@ -188,10 +187,10 @@
189188 {
190189 wsocket *s = (wsocket *)d;
191190
192 - WDEBUG((WLOG_DEBUG, format("_ev_callback: %s%son %d (%s)")
 191+ WDEBUG(format("_ev_callback: %s%son %d (%s)")
193192 % ((ev & EV_READ) ? "read " : "")
194193 % ((ev & EV_WRITE) ? "write " : "")
195 - % fd % s->_desc));
 194+ % fd % s->_desc);
196195
197196 if (ev & EV_READ)
198197 s->_read_handler(s);
@@ -204,10 +203,10 @@
205204 {
206205 int ev_flags = 0;
207206
208 - WDEBUG((WLOG_DEBUG, format("_register: %s%son %d (%s)")
 207+ WDEBUG(format("_register: %s%son %d (%s)")
209208 % ((what & FDE_READ) ? "read " : "")
210209 % ((what & FDE_WRITE) ? "write " : "")
211 - % _s % _desc));
 210+ % _s % _desc);
212211
213212 if (event_pending(&ev, EV_READ | EV_WRITE, NULL))
214213 event_del(&ev);
@@ -441,7 +440,7 @@
442441 int i;
443442 if ((i = ::recvfrom(_s, buf, count, 0, (sockaddr *)&saddr, &addrlen)) < 0)
444443 return i;
445 - WDEBUG((WLOG_DEBUG, format("recvfrom: fam=%d") % saddr.ss_family));
 444+ WDEBUG(format("recvfrom: fam=%d") % saddr.ss_family);
446445 addr = wnet::address((sockaddr *)&saddr, addrlen);
447446 return i;
448447 }
@@ -578,8 +577,8 @@
579578 memset(&mr, 0, sizeof(mr));
580579 mr.imr_multiaddr.s_addr = inbind->sin_addr.s_addr;
581580 mr.imr_interface.s_addr = inif->sin_addr.s_addr;
582 - WDEBUG((WLOG_DEBUG, format("NET: %s joins mcast on if %s")
583 - % straddr() % ifaddr.straddr()));
 581+ WDEBUG(format("NET: %s joins mcast on if %s")
 582+ % straddr() % ifaddr.straddr());
584583 setopt(IPPROTO_IP, IP_ADD_MEMBERSHIP, &mr, sizeof(mr));
585584 break;
586585 }
Index: trunk/willow/src/willow/wbackend.cc
@@ -56,8 +56,8 @@
5757 , be_hash(_carp_hosthash(be_straddr))
5858 , be_load(1.)
5959 {
60 - WDEBUG((WLOG_DEBUG, format("adding backend with straddr [%s], hash %s")
61 - % be_straddr % be_hash));
 60+ WDEBUG(format("adding backend with straddr [%s], hash %s")
 61+ % be_straddr % be_hash);
6262 }
6363
6464 backend_pool::backend_pool(string const &name, lb_type lbt, int failgroup)
@@ -65,7 +65,7 @@
6666 , _name(name)
6767 , _failgroup(failgroup)
6868 {
69 - WDEBUG((WLOG_DEBUG, format("creating backend_pool, lbt=%d") % (int) lbt));
 69+ WDEBUG(format("creating backend_pool, lbt=%d") % (int) lbt);
7070 }
7171
7272 void
@@ -75,8 +75,7 @@
7676 try {
7777 list = addrlist::resolve(addr, port, st_stream, family);
7878 } catch (resolution_error &e) {
79 - wlog(WLOG_ERROR, format("resolving %s: %s")
80 - % addr % e.what());
 79+ wlog.error(format("resolving %s: %s") % addr % e.what());
8180 return;
8281 }
8382
@@ -84,7 +83,7 @@
8584
8685 for (; it != end; ++it) {
8786 backends.push_back(new backend(addr, *it));
88 - wlog(WLOG_NOTICE, format("backend server: %s%s")
 87+ wlog.notice(format("backend server: %s%s")
8988 % addr % it->straddr());
9089 }
9190
@@ -131,8 +130,7 @@
132131 s->nonblocking(true);
133132 } catch (socket_error &e) {
134133 if (e.err() != ENFILE || now - last_nfile > 60)
135 - wlog(WLOG_WARNING,
136 - format("opening backend socket: %s")
 134+ wlog.warn(format("opening backend socket: %s")
137135 % e.what());
138136 if (e.err() == ENFILE)
139137 last_nfile = now;
@@ -146,7 +144,7 @@
147145 cs = s->connect();
148146 } catch (socket_error &e) {
149147 time_t retry = time(NULL) + config.backend_retry;
150 - wlog(WLOG_WARNING, format("%s: %s; retry in %d seconds")
 148+ wlog.warn(format("%s: %s; retry in %d seconds")
151149 % cbd->bc_backend->be_name
152150 % e.what() % config.backend_retry);
153151 cbd->bc_backend->be_dead = 1;
@@ -174,7 +172,7 @@
175173
176174 if (error && error != EINPROGRESS) {
177175 time_t retry = time(NULL) + config.backend_retry;
178 - wlog(WLOG_WARNING, format("%s: %s; retry in %d seconds")
 176+ wlog.warn(format("%s: %s; retry in %d seconds")
179177 % cbd->bc_backend->be_name
180178 % strerror(error)
181179 % config.backend_retry);
@@ -205,7 +203,7 @@
206204 , _failgroup(failgroup)
207205 , _delegate(NULL)
208206 {
209 - WDEBUG((WLOG_DEBUG, format("lbt = %d") % (int)lbt));
 207+ WDEBUG(format("lbt = %d") % (int)lbt);
210208 rotate(backends.begin(), backends.begin() + cur, backends.end());
211209 if (lbt == lb_carp || lbt == lb_carp_hostonly)
212210 _carp_recalc(url, host, lbt);
@@ -331,7 +329,8 @@
332330 hash = rotl(hash, 21);
333331 hash *= (uint32_t) backends[i]->be_carplfm;
334332 backends[i]->be_carp = hash;
335 - WDEBUG((WLOG_DEBUG, format("host for CARP: [%s] -> %d, be hash %d") % s % hash % backends[i]->be_hash));
 333+ WDEBUG(format("host for CARP: [%s] -> %d, be hash %d")
 334+ % s % hash % backends[i]->be_hash);
336335 }
337336 sort(backends.begin(), backends.end(), _becarp_cmp);
338337 }
Index: trunk/willow/src/willow/whttp_header.cc
@@ -390,15 +390,13 @@
391391 size_t vlen, nlen, rnpos;
392392 int htype;
393393
394 - WDEBUG((WLOG_DEBUG, format("header parser: got [%s]")
395 - % string(buf, buf + len)));
 394+ WDEBUG(format("header parser: got [%s]") % string(buf, buf + len));
396395 while ((rn = find_rn(bufp, bufp + len)) != NULL) {
397 - WDEBUG((WLOG_DEBUG, format("processing: [%s]")
398 - % string(bufp, rn)));
 396+ WDEBUG(format("processing: [%s]") % string(bufp, rn));
399397 for (char const *c = bufp; c < rn; ++c)
400398 if (*(unsigned char *)c > 0x7f || !*c)
401399 return io::sink_result_error;
402 - WDEBUG((WLOG_DEBUG, "chars all okay"));
 400+ WDEBUG("chars all okay");
403401
404402 if (rn == bufp) {
405403 _sink_spigot->sp_cork();
@@ -556,9 +554,9 @@
557555 _http_vers = http11;
558556 else return -1;
559557
560 - WDEBUG((WLOG_DEBUG, format("parse_response: codelen=%d [%s] desclen=%d [%s]")
 558+ WDEBUG(format("parse_response: codelen=%d [%s] desclen=%d [%s]")
561559 % codelen % string(errcode, errcode + codelen)
562 - % desclen % string(errdesc, errdesc + desclen)));
 560+ % desclen % string(errdesc, errdesc + desclen));
563561
564562 _response = str10toint(errcode, codelen);
565563 _http_path.reserve(codelen + desclen + 1);
Index: trunk/willow/src/willow/dbwrap.cc
@@ -82,7 +82,7 @@
8383 {
8484 _error = env->_env->txn_begin(env->_env, NULL, &_txn, 0);
8585 if (_error != 0) {
86 - wlog(WLOG_WARNING, format("error starting transaction: %s")
 86+ wlog.warn(format("error starting transaction: %s")
8787 % strerror());
8888 _txn = NULL;
8989 }
Index: trunk/willow/src/willow/confparse.cc
@@ -71,8 +71,7 @@
7272 }
7373
7474 if ((yyin = fopen(file.c_str(), "r")) == NULL) {
75 - wlog(WLOG_ERROR,
76 - format("could not open configuration file %s: %s")
 75+ wlog.error(format("could not open configuration file %s: %s")
7776 % file % strerror(errno));
7877 return NULL;
7978 }
@@ -153,7 +152,7 @@
154153 while (isspace(*dir))
155154 dir++;
156155
157 - WDEBUG((WLOG_DEBUG, format("PARSE: if[n]def %s") % dir));
 156+ WDEBUG(format("PARSE: if[n]def %s") % dir);
158157 return if_parser.variable_defined(dir);
159158 }
160159
@@ -169,7 +168,7 @@
170169 name = str.substr(0, i);
171170 value = str.substr(i + 1);
172171
173 - WDEBUG((WLOG_DEBUG, format("add var: [%s] = [%s]") % name % value));
 172+ WDEBUG(format("add var: [%s] = [%s]") % name % value);
174173 if_parser.add_variable(name, strtoll(value.c_str(), NULL, 0));
175174 }
176175
@@ -379,8 +378,7 @@
380379 vsnprintf(msg, sizeof msg, fmt, ap);
381380 va_end(ap);
382381
383 - wlog(WLOG_ERROR, format("%s(%d): %s")
384 - % current_file % lineno % msg);
 382+ wlog.error(format("%s(%d): %s") % current_file % lineno % msg);
385383 }
386384
387385 void
@@ -388,7 +386,7 @@
389387 {
390388 char msg[1024] = { 0 };
391389 vsnprintf(msg, sizeof msg, fmt, ap);
392 - wlog(WLOG_ERROR, format("%s: %s") % cv_pos.format() % msg);
 390+ wlog.error(format("%s: %s") % cv_pos.format() % msg);
393391 }
394392
395393 void
@@ -417,7 +415,7 @@
418416 {
419417 char msg[1024] = { 0 };
420418 vsnprintf(msg, sizeof msg, fmt, ap);
421 - wlog(WLOG_ERROR, format("%s: %s") % item_pos.format() % msg);
 419+ wlog.error(format("%s: %s") % item_pos.format() % msg);
422420 }
423421
424422 void
@@ -437,7 +435,7 @@
438436 va_start(ap, fmt);
439437 vsnprintf(msg, sizeof msg, fmt, ap);
440438 va_end(ap);
441 - wlog(WLOG_ERROR, format("%s(%d): catastrophic error: %s")
 439+ wlog.error(format("%s(%d): catastrophic error: %s")
442440 % current_file % lineno % msg);
443441 parse_error = true;
444442 }
@@ -446,8 +444,7 @@
447445 yyerror(const char *err)
448446 {
449447 parse_error = true;
450 - wlog(WLOG_ERROR, format("%s(%d): %s")
451 - % current_file % lineno % err);
 448+ wlog.error(format("%s(%d): %s") % current_file % lineno % err);
452449 }
453450
454451 void
Index: trunk/willow/src/willow/wconfig.cc
@@ -115,8 +115,7 @@
116116 try {
117117 res = addrlist::resolve(e.item_key, port, st_stream, fam);
118118 } catch (socket_error &ex) {
119 - wlog(WLOG_ERROR, format("resolving %s: %s")
120 - % e.item_key % ex.what());
 119+ wlog.error(format("resolving %s: %s") % e.item_key % ex.what());
121120 return;
122121 }
123122
@@ -128,14 +127,13 @@
129128 try {
130129 nl->sock = it->makesocket("HTTP listener", prio_accept);
131130 } catch (socket_error &ex) {
132 - wlog(WLOG_DEBUG, format("creating listener %s: %s")
 131+ wlog.error(format("creating listener %s: %s")
133132 % e.item_key % ex.what());
134133 delete nl;
135134 delete res;
136135 return;
137136 }
138 - WDEBUG((WLOG_DEBUG, format("listener %d has group %d")
139 - % nl->sock % gn));
 137+ WDEBUG(format("listener %d has group %d") % nl->sock % gn);
140138 sock2lsn[nl->sock] = nl;
141139 used_pools.insert(gn);
142140
@@ -143,7 +141,7 @@
144142 nl->name = e.item_key;
145143 nl->group = gn;
146144 listeners.push_back(nl);
147 - wlog(WLOG_NOTICE, format("listening on %s%s (group %d)")
 145+ wlog.notice(format("listening on %s%s (group %d)")
148146 % e.item_key % it->straddr() % gn);
149147 }
150148 delete res;
@@ -191,8 +189,7 @@
192190 static void
193191 set_log_facility(tree_entry &, value &v)
194192 {
195 - logging.syslog = true;
196 - logging.facility = log_levels.find(v.cv_values[0].av_strval)->second;
 193+ wlog.syslog(true, log_levels.find(v.cv_values[0].av_strval)->second);
197194 }
198195
199196 static bool
@@ -361,7 +358,7 @@
362359 }
363360 }
364361
365 - WDEBUG((WLOG_DEBUG, format("adding backend %d type = %d") % gn % (int) lbtype));
 362+ WDEBUG(format("adding backend %d type = %d") % gn % (int) lbtype);
366363 bpools.insert(make_pair(gn, backend_pool(e.item_key, lbtype, fogroup)));
367364
368365 if ((v = e/"hosts") != NULL) {
@@ -430,6 +427,18 @@
431428 }
432429 }
433430
 431+void
 432+set_log_level(tree_entry &e, value &v)
 433+{
 434+ wlog.level(log_level(v.cv_values[0].av_intval));
 435+}
 436+
 437+void
 438+set_log_file(tree_entry &e, value &v)
 439+{
 440+ wlog.file(v.cv_values[0].av_strval);
 441+}
 442+
434443 bool
435444 read_config(string const &file)
436445 {
@@ -437,10 +446,10 @@
438447 tree *t;
439448 conf
440449 .block("log")
441 - .value("level", simple_range(0, 3), set_int(logging.level))
442 - .value("file", nonempty_qstring, set_qstring(logging.file))
443 - .value("syslog", simple_yesno, set_yesno(logging.syslog))
444 - .value("facility", func(validate_log_facility), func(set_log_facility))
 450+ .value("level", simple_range(0, 3), func(set_log_level))
 451+ .value("file", nonempty_qstring, func(set_log_file))
 452+ .value("syslog-facility",
 453+ func(validate_log_facility), func(set_log_facility))
445454 .value("access-log", nonempty_qstring, set_qstring(config.access_log))
446455 .value("log-sample", simple_range(1, INT_MAX), set_int(config.log_sample))
447456 .value("udp-log", func(v_udp_log), set_yesno(config.udp_log))
@@ -543,35 +552,36 @@
544553 file = CONFIGFILE;
545554 conf::current_file = file;
546555
547 - wlog(WLOG_NOTICE, format("loading configuration from %s")
 556+ wlog.notice(format("loading configuration from %s")
548557 % conf::current_file);
549558
550559 if (!read_config(file)) {
551 - wlog(WLOG_ERROR, "cannot load configuration");
 560+ wlog.error("cannot load configuration");
552561 nerrors++;
553562 }
554563
555564 if (!listeners.size()) {
556 - wlog(WLOG_ERROR, "no listeners defined");
 565+ wlog.error("no listeners defined");
557566 nerrors++;
558567 }
559568 if (!bpools.size()) {
560 - wlog(WLOG_ERROR, "no backends defined");
 569+ wlog.error("no backends defined");
561570 nerrors++;
562571 }
563572
564573 for (map<int, backend_pool>::iterator it = bpools.begin(), end = bpools.end();
565574 it != end; ++it) {
566575 if (!it->second.size() && used_pools.find(it->first) != used_pools.end()) {
567 - wlog(WLOG_ERROR, format("backend group \"%s\" is used but has no backends")
 576+ wlog.error(format(
 577+ "backend group \"%s\" is used but has no backends")
568578 % it->second.name());
569579 nerrors++;
570580 }
571581 }
572582
573583 if (nerrors) {
574 - wlog(WLOG_ERROR,
575 - format("%d error(s) in configuration file. cannot continue.")
 584+ wlog.error(format(
 585+ "%d error(s) in configuration file. cannot continue.")
576586 % nerrors);
577587 exit(8);
578588 }
Index: trunk/willow/src/willow/htcp.cc
@@ -41,25 +41,25 @@
4242 if ((len = s->recvfrom(buf, sizeof(buf), addr)) < 1)
4343 return;
4444
45 - WDEBUG((WLOG_DEBUG, format("HTCP: received packet from %s, len %d")
46 - % s->straddr() % len));
 45+ WDEBUG(format("HTCP: received packet from %s, len %d")
 46+ % s->straddr() % len);
4747
4848 htcp_decoder ip(buf, len);
4949 htcp_encoder op;
5050 if (!ip.okay()) {
5151 if (ip.major() != 0 || ip.minor() != 1) {
5252 /* send an appropriate error */
53 - WDEBUG((WLOG_DEBUG, format("HTCP: wrong version, %d %d")
54 - % ip.major() % ip.minor()));
 53+ WDEBUG(format("HTCP: wrong version, %d %d")
 54+ % ip.major() % ip.minor());
5555 } else
5656 /* packet was too malformed to send an error */
57 - WDEBUG((WLOG_DEBUG, "HTCP: packet mangled"));
 57+ WDEBUG("HTCP: packet mangled");
5858 return;
5959 }
6060
61 - WDEBUG((WLOG_DEBUG,
62 - format("HTCP: packet length %d, packet declares length %d and data length %d")
63 - % len % ip.length() % ip.opdata()->length()));
 61+ WDEBUG(format(
 62+ "HTCP: packet length %d, packet declares length %d and data length %d")
 63+ % len % ip.length() % ip.opdata()->length());
6464
6565 /*
6666 * If the packet is signed, verify the signature.
@@ -67,18 +67,18 @@
6868 if (!ip.keyname().empty()) {
6969 map<string,ustring>::iterator it;
7070 if ((it = config.htcp_keys.find(ip.keyname())) == config.htcp_keys.end()) {
71 - WDEBUG((WLOG_DEBUG, format("HTCP: unknown key %s")
72 - % ip.keyname()));
 71+ WDEBUG(format("HTCP: unknown key %s")
 72+ % ip.keyname());
7373 return;
7474 }
7575
7676 if (!ip.verify_signature(ip.keyname(), it->second,
7777 addr.addr(), s->address().addr())) {
78 - WDEBUG((WLOG_DEBUG, "HTCP: sig verify failed"));
 78+ WDEBUG("HTCP: sig verify failed");
7979 return;
8080 }
8181
82 - WDEBUG((WLOG_DEBUG, "HTCP: sig okay"));
 82+ WDEBUG("HTCP: sig okay");
8383 } else if (config.htcp_sigrequired) {
8484 return;
8585 }
@@ -92,7 +92,7 @@
9393 break;
9494
9595 htcp_opdata_nop odp;
96 - WDEBUG((WLOG_DEBUG, "HTCP: NOP"));
 96+ WDEBUG("HTCP: NOP");
9797 op.opcode(htcp_op_nop);
9898 op.opdata(&odp);
9999 op.build_packet(addr.addr(), s->address().addr());
@@ -105,8 +105,8 @@
106106 break;
107107
108108 htcp_opdata_tst *opd = (htcp_opdata_tst *)ip.opdata();
109 - WDEBUG((WLOG_DEBUG, format("HTCP: TST: url=[%s]")
110 - % opd->tst_specifier.hs_url));
 109+ WDEBUG(format("HTCP: TST: url=[%s]")
 110+ % opd->tst_specifier.hs_url);
111111 bool cached = entitycache.cached(opd->tst_specifier.hs_url);
112112 htcp_opdata_tst_resp_found tf;
113113 htcp_opdata_tst_resp_notfound tnf;
@@ -161,7 +161,7 @@
162162 try {
163163 alist = addrlist::resolve(hstr, pstr, st_dgram);
164164 } catch (socket_error &e) {
165 - wlog(WLOG_WARNING, format("resolving [%s]:%s: %s")
 165+ wlog.warn(format("resolving [%s]:%s: %s")
166166 % hstr % pstr % e.what());
167167 return;
168168 }
@@ -173,8 +173,7 @@
174174 sock = it->makesocket("HTCP listener", prio_stats);
175175 sock->nonblocking(true);
176176 } catch (socket_error &e) {
177 - wlog(WLOG_WARNING,
178 - format("creating HTCP listener: %s:%s: %s")
 177+ wlog.warn(format("creating HTCP listener: %s:%s: %s")
179178 % ip.first % ip.second % e.what());
180179 delete sock;
181180 continue;
@@ -183,8 +182,7 @@
184183 try {
185184 sock->bind();
186185 } catch (socket_error &e) {
187 - wlog(WLOG_WARNING,
188 - format("binding HTCP listener %s: %s")
 186+ wlog.warn(format("binding HTCP listener %s: %s")
189187 % it->straddr() % e.what());
190188 delete sock;
191189 continue;
@@ -195,8 +193,7 @@
196194
197195 sock->readback(polycaller<wsocket *, int>(htcp_handler,
198196 &htcp_handler_stru::callback), 0);
199 - wlog(WLOG_NOTICE, format("HTCP listener: %s")
200 - % sock->straddr());
 197+ wlog.notice(format("HTCP listener: %s") % sock->straddr());
201198 }
202199 }
203200
@@ -217,7 +214,7 @@
218215 ifn = it->first.substr(i + 1);
219216 it->first = it->first.substr(0, i);
220217 }
221 - WDEBUG((WLOG_DEBUG, format("HTCP: mcast if: %s") % ifn));
 218+ WDEBUG(format("HTCP: mcast if: %s") % ifn);
222219 add_htcp_listener(*it, ifn);
223220 }
224221
Index: trunk/willow/src/willow/flowio.cc
@@ -80,21 +80,21 @@
8181 snprintf(path, sizeof(path), "/dev/shm/willow.diobuf.%d.%d.%d",
8282 getpid(), (int) pthread_self(), rand());
8383 if ((_diofd = open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) == -1) {
84 - wlog(WLOG_WARNING, format("opening diobuf %s: %s")
 84+ wlog.warn(format("opening diobuf %s: %s")
8585 % path % strerror(errno));
8686 return new char[DIOBUFSZ];
8787 }
8888 unlink(path);
8989
9090 if (lseek(_diofd, DIOBUFSZ, SEEK_SET) == -1) {
91 - wlog(WLOG_WARNING, format("seeking diobuf %s: %s")
 91+ wlog.warn(format("seeking diobuf %s: %s")
9292 % path % strerror(errno));
9393 close(_diofd);
9494 _diofd = -1;
9595 return new char[DIOBUFSZ];
9696 }
9797 if (write(_diofd, "", 1) < 1) {
98 - wlog(WLOG_WARNING, format("extending diobuf %s: %s")
 98+ wlog.warn(format("extending diobuf %s: %s")
9999 % path % strerror(errno));
100100 close(_diofd);
101101 _diofd = -1;
@@ -102,7 +102,7 @@
103103 }
104104 ret = (char *)mmap(0, DIOBUFSZ, PROT_READ | PROT_WRITE, MAP_SHARED, _diofd, 0);
105105 if (ret == MAP_FAILED) {
106 - wlog(WLOG_WARNING, format("mapping diobuf %s: %s")
 106+ wlog.warn(format("mapping diobuf %s: %s")
107107 % path % strerror(errno));
108108 close(_diofd);
109109 _diofd = -1;
@@ -232,7 +232,7 @@
233233 socket_sink::dio_ready(int fd, off_t off, size_t len, ssize_t &discard)
234234 {
235235 ssize_t wrote;
236 - WDEBUG((WLOG_DEBUG, format("dio_ready: starting off %d") % off));
 236+ WDEBUG(format("dio_ready: starting off %d") % off);
237237 if ((wrote = _socket->sendfile(fd, &off, len)) == -1) {
238238 if (errno == EAGAIN) {
239239 _sink_spigot->sp_cork();
@@ -249,8 +249,8 @@
250250 discard += wrote;
251251 _counter += wrote;
252252
253 - WDEBUG((WLOG_DEBUG, format("dio_ready: len %d off %d wrote %d fileoff=%d")
254 - % len % off % wrote % lseek(fd, 0, SEEK_CUR)));
 253+ WDEBUG(format("dio_ready: len %d off %d wrote %d fileoff=%d")
 254+ % len % off % wrote % lseek(fd, 0, SEEK_CUR));
255255
256256 if ((ssize_t)len == wrote) {
257257 return sink_result_okay;
@@ -308,7 +308,7 @@
309309
310310 if (cache) {
311311 if (stat(file, &sb) == -1) {
312 - wlog(WLOG_WARNING, format("cannot open %s: %s")
 312+ wlog.warn(format("cannot open %s: %s")
313313 % file % strerror(errno));
314314 return false;
315315 }
@@ -327,7 +327,7 @@
328328
329329 _file.open(file);
330330 if (!_file.is_open()) {
331 - wlog(WLOG_WARNING, format("cannot open %s: %s")
 331+ wlog.warn(format("cannot open %s: %s")
332332 % file % strerror(errno));
333333 return false;
334334 }
@@ -349,8 +349,7 @@
350350
351351 _file.open(file);
352352 if (!_file.is_open())
353 - wlog(WLOG_WARNING, format("cannot open %s: %s")
354 - % file % strerror(errno));
 353+ wlog.warn(format("cannot open %s: %s") % file % strerror(errno));
355354 return _file.is_open();
356355 }
357356
Index: trunk/willow/willow.conf.example
@@ -268,19 +268,17 @@
269269 file = "/var/log/willow/willow.log";
270270
271271 /*
272 - * Log to system.
273 - */
274 - syslog = yes;
275 -
276 - /*
277 - * Facilities:
 272+ * Log to syslog.
278273 *
279 - * user, mail, daemon, auth, lpr, news, uucp,
280 - * cron, audit, local0 .. local7.
 274+ * Available facilities:
281275 *
282 - * If not specified, defaults to 'daemon'.
 276+ * user, mail, daemon, auth, lpr, news, uucp, * cron, audit,
 277+ * local0 .. local7; plus some OS-specific ones that you probably
 278+ * con'f want to use.
 279+ *
 280+ * If not specified, syslog is not used.
283281 */
284 - facility = daemon;
 282+ syslog-facility = daemon;
285283
286284 /*
287285 * Log client requests. Every 1/log-sample requests are logged.
@@ -323,7 +321,7 @@
324322 * access blocks, with or without apply-at; they will be merged.
325323 */
326324
327 -access-v4 {
 325+access {
328326 /* allow localhost and the local network */
329327 allow = "127.0.0.1/32", "10.0.0.0/8";
330328