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