File: ostream.cpp

package info (click to toggle)
libwibble 0.1.19
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 832 kB
  • ctags: 1,940
  • sloc: cpp: 9,798; makefile: 163; perl: 84; sh: 11
file content (32 lines) | stat: -rw-r--r-- 819 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <wibble/log/ostream.h>
#include <time.h>

namespace wibble {
namespace log {

OstreamSender::OstreamSender(std::ostream& out) : out(out) {}

void OstreamSender::send(Level level, const std::string& msg)
{
	time_t now = time(NULL);
	struct tm pnow;
	localtime_r(&now, &pnow);
	char timebuf[20];
	/*
	 * Strftime specifiers used here:
	 *	%b      The abbreviated month name according to the current locale.
	 *	%d      The day of the month as a decimal number (range 01 to 31).
	 *	%e      Like %d, the day of the month as a decimal number, but a
	 *			leading zero is replaced by a space. (SU)
	 *	%T      The time in 24-hour notation (%H:%M:%S). (SU)
	 */
	strftime(timebuf, 20, "%b %e %T", &pnow);
	out << timebuf << ": " << msg << std::endl;
	if (level >= WARN)
		out.flush();
}
	
}
}

// vim:set ts=4 sw=4: