Skip to content

Commit 2a637c2

Browse files
committed
feat docs: a few more additions to changelog
Tests: протестировано локально и в CI commit_hash:54473433f3190a276e51734e534d5f5f9b658e44
1 parent 1e7e144 commit 2a637c2

File tree

3 files changed

+20
-18
lines changed

3 files changed

+20
-18
lines changed

core/src/logging/log_test.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,20 @@ TEST_F(LoggingTest, Call) {
181181
}
182182

183183
TEST_F(LoggingTest, CallFormat) {
184-
/// [Example lambda-based logging usage]
185-
std::map<int, int> map{{1, 2}, {2, 3}, {3, 4}};
186-
LOG_ERROR() << [&map](auto& out) {
187-
for (const auto& [key, value] : map) {
188-
out.Format("{}={}, ", key, value);
189-
}
190-
};
191-
/// [Example lambda-based logging usage]
192-
EXPECT_EQ("1=2, 2=3, 3=4, ", LoggedText());
184+
const int user_id = 42;
185+
std::string ip_address = "127.0.0.1";
186+
std::string_view expected_result = "User 42 logged in from 127.0.0.1";
187+
188+
/// [Example format bad logging usage]
189+
LOG_INFO() << fmt::format("User {} logged in from {}", user_id, ip_address);
190+
/// [Example format bad logging usage]
191+
EXPECT_EQ(expected_result, LoggedText());
192+
ClearLog();
193+
194+
/// [Example format-based logging usage]
195+
LOG_INFO("User {} logged in from {}", user_id, ip_address);
196+
/// [Example format-based logging usage]
197+
EXPECT_EQ(expected_result, LoggedText());
193198
}
194199

195200
TEST_F(LoggingTest, LoggingContainerElementFields) {

scripts/docs/en/userver/logging.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,14 @@ LOG_INFO(<format-string>, <args>...);
150150
151151
#### Examples
152152
153-
@snippet logging/log_test.cpp Example inline formatting usage
154-
155153
**Basic Usage**
156154
Instead of:
157-
```cpp
158-
LOG_INFO() << fmt::format("User {} logged in from {}", user_id, ip_address);
159-
```
155+
156+
@snippet logging/log_test.cpp Example format bad logging usage
160157
161158
Use:
162-
```cpp
163-
LOG_INFO("User {} logged in from {}", user_id, ip_address);
164-
```
159+
160+
@snippet logging/log_test.cpp Example format-based logging usage
165161
166162
This writes the formatted message directly to the log buffer.
167163

scripts/docs/en/userver/roadmap_and_changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ Changelog news also go to the
3636

3737
### Release v2.9
3838

39-
* Logging now supports `fmt` formatting in macro: `LOG_INFO("This is {} message", "informational");`
39+
* Logging now supports `fmt` formatting in macro `LOG_INFO("User {} logged in from {}", user_id, ip_address);` and
40+
lambda formatting. See @ref scripts/docs/en/userver/logging.md for more info.
4041
* PostgreSQL driver now can disable all the statements logging via static config option `statement-log-mode`
4142
* ClickHouse driver now supports doubles in the queries.
4243
* YDB now can be used with GCC compiler, not only Clang. YDB still requires C++20 support

0 commit comments

Comments
 (0)