Thrill  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
logger.cpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * tlx/logger.cpp
3  *
4  * Simple logging methods using ostream output.
5  *
6  * Part of tlx - http://panthema.net/tlx
7  *
8  * Copyright (C) 2015-2017 Timo Bingmann <[email protected]>
9  *
10  * All rights reserved. Published under the Boost Software License, Version 1.0
11  ******************************************************************************/
12 
13 #include <tlx/logger.hpp>
14 
15 #include <iostream>
16 #include <mutex>
17 #include <string>
18 
19 namespace tlx {
20 
21 /******************************************************************************/
22 
23 //! mutex for log output
24 static std::mutex s_logger_mutex;
25 
26 void Logger::Output(const char* str) {
27  // lock the global mutex of logger for serialized output in multi-threaded
28  // programs.
29  std::unique_lock<std::mutex> lock(s_logger_mutex);
30  std::cout << str;
31 }
32 
33 void Logger::Output(const std::string& str) {
34  // lock the global mutex of logger for serialized output in multi-threaded
35  // programs.
36  std::unique_lock<std::mutex> lock(s_logger_mutex);
37  std::cout << str;
38 }
39 
41  oss_ << '\n';
42  Output(oss_.str());
43 }
44 
46  oss_ << '\n';
47  Logger::Output(oss_.str());
48 }
49 
50 } // namespace tlx
51 
52 /******************************************************************************/
~SpacingLogger()
destructor: output a newline
Definition: logger.cpp:45
static void Output(const char *str)
mutex synchronized output to std::cout
Definition: logger.cpp:26
std::ostringstream oss_
collector stream
Definition: logger.hpp:76
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
~Logger()
destructor: output a newline
Definition: logger.cpp:40
static std::mutex s_logger_mutex
mutex for log output
Definition: logger.cpp:24
std::ostringstream oss_
collector stream
Definition: logger.hpp:106