1 // formatter_thread_id.hpp
2 
3 // Boost Logging library
4 //
5 // Author: John Torjo, www.torjo.com
6 //
7 // Copyright (C) 2007 John Torjo (see www.torjo.com for email)
8 //
9 // Distributed under the Boost Software License, Version 1.0.
10 //    (See accompanying file LICENSE_1_0.txt or copy at
11 //          http://www.boost.org/LICENSE_1_0.txt)
12 //
13 // See http://www.boost.org for updates, documentation, and revision history.
14 // See http://www.torjo.com/log2/ for more details
15 
16 
17 #ifndef JT28092007_formatter_thread_id_HPP_DEFINED
18 #define JT28092007_formatter_thread_id_HPP_DEFINED
19 
20 #include <hpx/config.hpp>
21 #include <hpx/util/logging/detail/fwd.hpp>
22 #include <hpx/util/logging/format/formatter/convert_format.hpp>
23 #include <hpx/util/logging/detail/manipulator.hpp> // is_generic
24 #include <sstream>
25 
26 namespace hpx { namespace util { namespace logging { namespace formatter {
27 
28 /**
29 @brief Writes the thread_id to the log
30 
31 @param convert [optional] In case there needs to be a conversion between
32 std::(w)string and the string that holds your logged message. See convert_format.
33 For instance, you might use @ref hpx::util::logging::optimize::cache_string_one_str
34 "a cached_string class" (see @ref hpx::util::logging::optimize "optimize namespace").
35 */
36 template<class convert = do_convert_format::prepend> struct thread_id_t : is_generic,
37 hpx::util::logging::op_equal::always_equal {
38     typedef convert convert_type;
39 
operator ()hpx::util::logging::formatter::thread_id_t40     void operator()(msg_type & msg) const {
41         std::ostringstream out;
42         out
43     #if defined (HPX_WINDOWS)
44             << ::GetCurrentThreadId()
45     #else
46             << pthread_self ()
47     #endif
48             ;
49 
50         convert::write( out.str(), msg );
51     }
52 };
53 
54 /** @brief thread_id_t with default values. See thread_id_t
55 
56 @copydoc thread_id_t
57 */
58 typedef thread_id_t<> thread_id;
59 
60 }}}}
61 
62 #endif
63