File tree Expand file tree Collapse file tree 7 files changed +97
-6
lines changed
include/boost/http_io/server Expand file tree Collapse file tree 7 files changed +97
-6
lines changed Original file line number Diff line number Diff line change @@ -37,7 +37,8 @@ class http_responder
3737 http_responder (
3838 server& srv,
3939 router_type& rr)
40- : id_(
40+ : sect_(srv.sections().get(" http_responder" ))
41+ , id_(
4142 []() noexcept
4243 {
4344 static std::size_t n = 0 ;
Original file line number Diff line number Diff line change @@ -66,6 +66,7 @@ workers(
6666 std::size_t num_workers,
6767 Args&&... args)
6868 : srv_(srv)
69+ , sect_(srv.sections().get(" workers" ))
6970 , ex_(ex)
7071 , vw_(num_workers)
7172 , concurrency_(concurrency)
Original file line number Diff line number Diff line change 1212
1313#include < boost/http_io/detail/config.hpp>
1414#include < boost/core/detail/string_view.hpp>
15+ #include < memory>
1516#include < sstream>
17+ #include < string>
1618
1719namespace boost {
1820namespace http_io {
1921
2022struct section
2123{
22- int threshold () const noexcept { return 0 ; }
24+ BOOST_HTTP_IO_DECL
25+ section () noexcept ;
26+
27+ /* * Return the level below which logging is squelched
28+ */
29+ int threshold () const noexcept
30+ {
31+ return impl_->level ;
32+ }
2333
2434 template <class ... Args>
2535 void operator ()(
@@ -72,6 +82,18 @@ struct section
7282
7383 BOOST_HTTP_IO_DECL
7484 void write (int , boost::core::string_view);
85+
86+ section (core::string_view);
87+
88+ friend class log_sections ;
89+
90+ struct impl
91+ {
92+ std::string name;
93+ int level = 0 ;
94+ };
95+
96+ std::shared_ptr<impl> impl_;
7597};
7698
7799// ------------------------------------------------
@@ -103,7 +125,6 @@ class log_stream
103125
104126// ------------------------------------------------
105127
106- #if 0
107128class log_sections
108129{
109130public:
@@ -130,7 +151,6 @@ class log_sections
130151 struct impl ;
131152 impl* impl_;
132153};
133- #endif
134154
135155// ------------------------------------------------
136156
Original file line number Diff line number Diff line change 1818namespace boost {
1919namespace http_io {
2020
21+ class log_sections ;
22+
2123/* * A generic server interface
2224
2325 In this model a server contains zero or more parts, where each part
@@ -73,6 +75,9 @@ class BOOST_SYMBOL_VISIBLE
7375 BOOST_HTTP_IO_DECL
7476 rts::context& services () noexcept ;
7577
78+ BOOST_HTTP_IO_DECL
79+ log_sections& sections () noexcept ;
80+
7681 BOOST_HTTP_IO_DECL
7782 void install (std::unique_ptr<part> pp);
7883
Original file line number Diff line number Diff line change @@ -115,12 +115,12 @@ class workers
115115 void do_stop ();
116116
117117 http_io::server& srv_;
118+ section sect_;
118119 Executor ex_;
119120 fixed_array<worker> vw_;
120121 std::vector<acceptor> va_;
121122 worker* idle_ = nullptr ;
122123 std::size_t n_idle_ = 0 ;
123- section sect_;
124124 unsigned concurrency_;
125125};
126126
Original file line number Diff line number Diff line change 1010#include < boost/http_io/server/logger.hpp>
1111#include < iostream>
1212#include < mutex>
13+ #include < unordered_map>
1314
1415namespace boost {
1516namespace http_io {
1617
18+ section::
19+ section () noexcept = default ;
20+
1721void
1822section::
1923write (
@@ -36,7 +40,8 @@ format_impl(
3640 std::size_t * plen,
3741 std::size_t n)
3842{
39- std::string s;
43+ std::string s = impl_->name ;
44+ s.push_back (' ' );
4045 char const * p = fs.data ();
4146 char const * end = fs.data () + fs.size ();
4247 auto p0 = p;
@@ -63,5 +68,55 @@ format_impl(
6368 write (level, s);
6469}
6570
71+ section::
72+ section (core::string_view name)
73+ : impl_(std::make_shared<impl>())
74+ {
75+ impl_->name = name;
76+ }
77+
78+ // ------------------------------------------------
79+
80+ struct log_sections ::impl
81+ {
82+ struct hash
83+ {
84+ std::size_t
85+ operator ()(core::string_view const & s) const noexcept
86+ {
87+ std::size_t hash = 1469598103934665603ull ; // FNV offset basis
88+ for (unsigned char c : s)
89+ hash ^= c, hash *= 1099511628211ull ; // FNV prime
90+ return hash;
91+ }
92+ };
93+
94+ std::unordered_map<core::string_view, section, hash> map;
95+ };
96+
97+ log_sections::
98+ ~log_sections ()
99+ {
100+ delete impl_;
101+ }
102+
103+ log_sections::
104+ log_sections ()
105+ : impl_(new impl)
106+ {
107+ }
108+
109+ section
110+ log_sections::
111+ get (core::string_view name)
112+ {
113+ auto it = impl_->map .find (name);
114+ if (it != impl_->map .end ())
115+ return it->second ;
116+ auto v = section (name);
117+ impl_->map .emplace ( core::string_view (v.impl_ ->name ), v);
118+ return v;
119+ }
120+
66121} // http_io
67122} // boost
Original file line number Diff line number Diff line change 77// Official repository: https://github.com/cppalliance/http_io
88//
99
10+ #include < boost/http_io/server/logger.hpp>
1011#include < boost/http_io/server/server.hpp>
1112#include < boost/http_io/detail/except.hpp>
1213#include < mutex>
@@ -28,6 +29,7 @@ struct server::impl
2829{
2930 std::mutex m;
3031 rts::context services;
32+ log_sections sections;
3133 std::vector<std::unique_ptr<part>> v;
3234 state st = state::none;
3335};
@@ -62,6 +64,13 @@ services() noexcept
6264 return impl_->services ;
6365}
6466
67+ log_sections&
68+ server::
69+ sections () noexcept
70+ {
71+ return impl_->sections ;
72+ }
73+
6574void
6675server::
6776install (std::unique_ptr<part> pp)
You can’t perform that action at this time.
0 commit comments