Esempio n. 1
0
	void vmessage(Severity severity, const char* fmt, va_list ap){
		static char buf[255]; /* this isn't thread-safe anyway, might as well make it static */

		std::unique_ptr<char, free_delete> content(vasprintf2(fmt, ap));
		std::unique_ptr<char, free_delete> decorated(asprintf2("(%s) [%s] %s", severity_string(severity), timestring(buf, 255), content.get()));

		for ( iterator it = destinations.begin(); it != destinations.end(); ++it ){
			if ( severity < it->second ) continue;
			Destination* dst = it->first;
			dst->write(content.get(), decorated.get());
		}
	}
Esempio n. 2
0
	static void add_destination(Severity severity, FILE* dst, bool autoclose){
		Destination* o = new Destination(severity, dst, false);
		output.push_back(o);

		if ( dst == stdout || dst == stderr ){
			return;
		}

#ifdef HAVE_GETTIMEOFDAY
		struct timeval tv;
		gettimeofday(&tv, nullptr);
		struct tm* local = localtime(&tv.tv_sec);
#else
		__time64_t tv;
		struct tm tm, *local = &tm;
        _time64(&tv);
        _localtime64_s(local, &tv);
#endif

		char buf[64] = {0,};
		strftime(buf, sizeof(buf), "\nLogging started at %Y-%m-%d %H.%M.%S\n", local);
		o->write(INFO, buf);
	}