Thrill  0.1
logger.hpp
Go to the documentation of this file.
1 /*******************************************************************************
2  * thrill/common/logger.hpp
3  *
4  * Simple and less simple logging classes.
5  *
6  * Part of Project Thrill - http://project-thrill.org
7  *
8  * Copyright (C) 2015 Timo Bingmann <[email protected]>
9  *
10  * All rights reserved. Published under the BSD-2 license in the LICENSE file.
11  ******************************************************************************/
12 
13 #pragma once
14 #ifndef THRILL_COMMON_LOGGER_HEADER
15 #define THRILL_COMMON_LOGGER_HEADER
16 
17 #include <thrill/mem/allocator.hpp>
18 #include <thrill/mem/pool.hpp>
19 #include <tlx/logger.hpp>
20 #include <tlx/logger/array.hpp>
21 #include <tlx/logger/tuple.hpp>
23 
24 namespace thrill {
25 namespace common {
26 
27 //! memory manager singleton for Logger
29 
30 //! Defines a name for the current thread.
31 void NameThisThread(const std::string& name);
32 
33 //! Returns the name of the current thread or 'unknown [id]'
35 
36 /******************************************************************************/
37 
38 /*!
39 
40 \brief LOG and sLOG for development and debugging
41 
42 This is a short description of how to use \ref LOG and \ref sLOG for rapid
43 development of modules with debug output, and how to **keep it afterwards**.
44 
45 There are two classes Logger and SpacingLogger, but one does not use these
46 directly.
47 
48 Instead there are the macros: \ref LOG and \ref sLOG that can be used as such:
49 \code
50 LOG << "This will be printed with a newline";
51 sLOG << "Print variables a" << a << "b" << b << "c" << c;
52 \endcode
53 
54 There macros only print the lines if the boolean variable **debug** is
55 true. This variable is searched for in the scope of the LOG, which means it can
56 be set or overridden in the function scope, the class scope, from **inherited
57 classes**, or even the global scope.
58 
59 \code
60 class MyClass
61 {
62  static constexpr bool debug = true;
63 
64  void func1()
65  {
66  LOG << "Hello World";
67 
68  LOG0 << "This is temporarily disabled.";
69  }
70 
71  void func2()
72  {
73  static constexpr bool debug = false;
74  LOG << "This is not printed any more.";
75 
76  LOG1 << "But this is forced.";
77  }
78 };
79 \endcode
80 
81 There are two variation of \ref LOG and \ref sLOG : append 0 or 1 for
82 temporarily disabled or enabled debug lines. These macros are then \ref LOG0,
83 \ref LOG1, \ref sLOG0, and \ref sLOG1. The suffix overrides the debug variable's
84 setting.
85 
86 After a module works as intended, one can just set `debug = false`, and all
87 debug output will disappear.
88 
89 ## Critique of LOG and sLOG
90 
91 The macros are only for rapid module-based development. It cannot be used as an
92 extended logging system for our network framework, where logs of network
93 execution and communication are collected for later analysis. Something else is
94 needed here.
95 
96  */
97 
98 } // namespace common
99 } // namespace thrill
100 
101 #endif // !THRILL_COMMON_LOGGER_HEADER
102 
103 /******************************************************************************/
mem::Manager g_logger_mem_manager(nullptr, "Logger")
memory manager singleton for Logger
Definition: logger.hpp:28
std::string GetNameForThisThread()
Returns the name of the current thread or &#39;unknown [id]&#39;.
void NameThisThread(const std::string &name)
Defines a name for the current thread, only if no name was set previously.
Definition: logger.cpp:40
std::basic_string< char, std::char_traits< char >, Allocator< char > > string
string with Manager tracking
Definition: allocator.hpp:220
Object shared by allocators and other classes to track memory allocations.
Definition: manager.hpp:28