Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * common/verbose.cpp 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2009, 2010 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 00007 * 00008 * Distributed under the Boost Software License, Version 1.0. 00009 * (See accompanying file LICENSE_1_0.txt or copy at 00010 * http://www.boost.org/LICENSE_1_0.txt) 00011 **************************************************************************/ 00012 00013 #include <iostream> 00014 #include <cstdio> 00015 #include <cmath> 00016 #include <stxxl/bits/verbose.h> 00017 #include <stxxl/bits/common/log.h> 00018 #include <stxxl/bits/common/timer.h> 00019 #include <stxxl/bits/msvc_compatibility.h> 00020 00021 00022 #ifndef STXXL_THREAD_ID 00023 # ifdef BOOST_MSVC 00024 # define STXXL_THREAD_ID (-1) 00025 # else 00026 # define STXXL_THREAD_ID pthread_self() 00027 # endif 00028 #endif 00029 00030 00031 __STXXL_BEGIN_NAMESPACE 00032 00033 static const double program_start_time_stamp = timestamp(); 00034 00035 void print_msg(const char * label, const std::string & msg, unsigned flags) 00036 { 00037 std::string s; 00038 #ifdef STXXL_PRINT_TIMESTAMP_ALWAYS 00039 const bool timestamp_always = true; 00040 #else 00041 const bool timestamp_always = false; 00042 #endif 00043 if (timestamp_always || (flags & _STXXL_PRNT_TIMESTAMP)) { 00044 double t = timestamp() - program_start_time_stamp; 00045 char tstr[23]; /* "[364:23:59:59.999999] " */ 00046 snprintf(tstr, sizeof(tstr), "[%d.%02d:%02d:%02d.%06d] ", 00047 int(t / (24 * 60 * 60)), 00048 int(t / (60 * 60)) % 24, 00049 int(t / 60) % 60, int(t) % 60, 00050 int((t - floor(t)) * 1000000)); 00051 s += tstr; 00052 } 00053 if (label) { 00054 s += '['; 00055 s += label; 00056 s += "] "; 00057 } 00058 if (flags & _STXXL_PRNT_THREAD_ID) { 00059 char tstr[32]; 00060 snprintf(tstr, sizeof(tstr), "[T%ld] ", long(STXXL_THREAD_ID)); 00061 s += tstr; 00062 } 00063 s += msg; 00064 if (flags & _STXXL_PRNT_ADDNEWLINE) 00065 s += '\n'; 00066 if (flags & _STXXL_PRNT_COUT) 00067 std::cout << s << std::flush; 00068 if (flags & _STXXL_PRNT_CERR) 00069 std::cerr << s << std::flush; 00070 logger * logger_instance = logger::get_instance(); 00071 if (flags & _STXXL_PRNT_LOG) 00072 logger_instance->log_stream() << s << std::flush; 00073 if (flags & _STXXL_PRNT_ERRLOG) 00074 logger_instance->errlog_stream() << s << std::flush; 00075 } 00076 00077 __STXXL_END_NAMESPACE 00078 00079 // vim: et:ts=4:sw=4