lean cpp library
A lean C++ library providing efficient utility classes for high-performance C++ applications.
|
00001 /*****************************************************/ 00002 /* lean Logging (c) Tobias Zirr 2011 */ 00003 /*****************************************************/ 00004 00005 #ifndef LEAN_LOGGING_LOG_STREAM 00006 #define LEAN_LOGGING_LOG_STREAM 00007 00008 #include "../lean.h" 00009 #include "../strings/types.h" 00010 #include "../concurrent/spin_lock.h" 00011 #include "log_target.h" 00012 #include <ostream> 00013 00014 namespace lean 00015 { 00016 namespace logging 00017 { 00018 00022 template <class Char = char, class Traits = std::char_traits<Char> > 00023 class basic_log_stream : public log_target 00024 { 00025 public: 00027 typedef ::std::basic_ostream<Char, Traits> stream_type; 00028 00029 private: 00030 stream_type &m_stream; 00031 00032 spin_lock<> m_printLock; 00033 00034 public: 00036 explicit basic_log_stream(stream_type *stream) 00037 : m_stream(*stream) { }; 00038 00040 void print(const char_ntri &message) 00041 { 00042 scoped_sl_lock lock(m_printLock); 00043 // Use streaming operator to allow for implicit character widening 00044 m_stream << message.c_str(); 00045 } 00046 }; 00047 00050 typedef basic_log_stream<> log_stream; 00053 typedef basic_log_stream<wchar_t> wlog_stream; 00054 00055 } // namespace 00056 00057 using logging::basic_log_stream; 00058 00059 using logging::log_stream; 00060 using logging::wlog_stream; 00061 00062 } // namespace 00063 00064 #endif