userver: userver/server/handlers/dynamic_debug_log.hpp Source File
Loading...
Searching...
No Matches
dynamic_debug_log.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/server/handlers/dynamic_debug_log.hpp
4/// @brief HTTP Handler to show/hide logs at the specific file:line
5
6#include <userver/concurrent/variable.hpp>
7#include <userver/engine/task/task_processor_fwd.hpp>
8#include <userver/logging/level.hpp>
9#include <userver/server/handlers/http_handler_base.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace server::handlers {
14// clang-format off
15
16/// @ingroup userver_components userver_http_handlers
17///
18/// @brief Handler for forcing specific lines logging. Feature also known as
19/// dynamic debug logging.
20///
21/// The component has no service configuration except the
22/// @ref userver_http_handlers "common handler options".
23///
24/// ## Static configuration example:
25///
26/// @snippet components/common_server_component_list_test.cpp Sample handler dynamic debug log component config
27///
28/// ## Scheme
29///
30/// `GET` request shows information about available locations and forced
31/// loggings. `PUT` adds forced logging for a particular location. `DELETE`
32/// request removes forced logging from a location.
33///
34/// ### GET
35/// For the `GET` requests this handler returns a list of all the known logging
36/// locations tab separated from a on/off value of logging:
37/// @code
38/// project/src/some.cpp:13 0
39/// project/src/some.cpp:23 0
40/// project/src/some.cpp:42 1
41/// project/src/some.cpp:113 0
42/// userver/core/src/server/server.cpp:131 0
43/// @endcode
44///
45/// In the above sample `1` means that logging was enabled via this handler
46/// and that logger would write logs even if the logger level tells not
47/// to do that. `0` means that the log will be written down only if the logger
48/// level tells to do that.
49///
50/// ### PUT
51/// `PUT` request enables logging for the location specified in a `location=`
52/// argument in URL. `PUT` request should have a `location=` argument in URL
53/// with a location from the `GET` request or with a location without line
54/// number, to enable logging for the whole file.
55///
56/// ### DELETE
57/// `DELETE` request removes the forced logging from location. Location should
58/// be specified in the `location=` argument in URL.
59///
60/// @see @ref scripts/docs/en/userver/log_level_running_service.md
61
62// clang-format on
63class DynamicDebugLog final : public HttpHandlerBase {
64public:
65 DynamicDebugLog(const components::ComponentConfig& config, const components::ComponentContext& component_context);
66
67 /// @ingroup userver_component_names
68 /// @brief The default name of server::handlers::DynamicDebugLog
69 static constexpr std::string_view kName = "handler-dynamic-debug-log";
70
71 std::string HandleRequestThrow(const http::HttpRequest& request, request::RequestContext&) const override;
72
73 static yaml_config::Schema GetStaticConfigSchema();
74};
75
76} // namespace server::handlers
77
78template <>
79inline constexpr bool components::kHasValidate<server::handlers::DynamicDebugLog> = true;
80
81USERVER_NAMESPACE_END