Skip to content

Commit 8593fd2

Browse files
authored
Adding a log_ prefix to the log() sub-structs (motis-project#32)
1 parent 69e700e commit 8593fd2

File tree

5 files changed

+29
-29
lines changed

5 files changed

+29
-29
lines changed

docs/index.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ This is the documentation for the **utl** (utility) module.
1212
## Logging
1313
The simplest way to produce log lines is to use the `utl:log()` function,
1414
or the wrapping functions for the various log levels,
15-
`utl::debug()`, `utl::info()` and `utl::error()`:
15+
`utl::log_debug()`, `utl::log_info()` and `utl::log_error()`:
1616
```c++
1717
#include "utl/logging.h"
1818

19-
utl::info("MyCtx", "Simple message");
19+
utl::log_info("MyCtx", "Simple message");
2020
```
2121
2222
The first parameter is the **context**, that provides an information of the origin of the log line inside MOTIS code.
@@ -36,12 +36,12 @@ error
3636
You can insert variables in the message by using `{}` and passing them as extra arguments
3737
(formatting is performed by the [fmt](https://fmt.dev>) library):
3838
```c++
39-
utl::info("MyCtx", "String={} Int={}", "Hello", 42);
39+
utl::log_info("MyCtx", "String={} Int={}", "Hello", 42);
4040
```
4141

4242
You can specify **metadata** using `.attrs()`:
4343
```c++
44-
utl::info("MyCtx", "Message").attrs({{"key1", "value1"}, {"key2", "value2"}});
44+
utl::log_info("MyCtx", "Message").attrs({{"key1", "value1"}, {"key2", "value2"}});
4545
```
4646
4747
### API details
@@ -50,23 +50,23 @@ utl::info("MyCtx", "Message").attrs({{"key1", "value1"}, {"key2", "value2"}});
5050
:members:
5151
:::
5252
53-
:::{doxygenstruct} utl::debug
53+
:::{doxygenstruct} utl::log_debug
5454
:no-link:
5555
:members:
5656
:::
5757
58-
:::{doxygenstruct} utl::info
58+
:::{doxygenstruct} utl::log_info
5959
:no-link:
6060
:members:
6161
:::
6262
63-
:::{doxygenstruct} utl::error
63+
:::{doxygenstruct} utl::log_error
6464
:no-link:
6565
:members:
6666
:::
6767
6868
:::{note}
6969
Those logging function are an exception to the rule that, in MOTIS,
7070
we use [Aggregate Initialization](https://en.cppreference.com/w/cpp/language/aggregate_initialization) wherever possible,
71-
but here we do not want to use `utl::info{...}`.
71+
but here we do not want to use `utl::log_info{...}`.
7272
:::

include/utl/logging.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,19 @@ struct log {
9494

9595
/// Produce a new DEBUG log line
9696
template <typename... Args>
97-
struct debug : public log<log_level::debug, Args...> {
97+
struct log_debug : public log<log_level::debug, Args...> {
9898
using log<log_level::debug, Args...>::log;
9999
};
100100

101101
/// Produce a new INFO log line
102102
template <typename... Args>
103-
struct info : public log<log_level::info, Args...> {
103+
struct log_info : public log<log_level::info, Args...> {
104104
using log<log_level::info, Args...>::log;
105105
};
106106

107107
/// Produce a new ERROR log line
108108
template <typename... Args>
109-
struct error : public log<log_level::error, Args...> {
109+
struct log_error : public log<log_level::error, Args...> {
110110
using log<log_level::error, Args...>::log;
111111
};
112112

@@ -115,16 +115,16 @@ struct error : public log<log_level::error, Args...> {
115115
// which has a default value:
116116

117117
template <typename... Args>
118-
debug(const char* ctx, fmt::format_string<Args...>,
119-
Args&&... args) -> debug<Args...>;
118+
log_debug(const char* ctx, fmt::format_string<Args...>,
119+
Args&&... args) -> log_debug<Args...>;
120120

121121
template <typename... Args>
122-
info(const char* ctx, fmt::format_string<Args...>,
123-
Args&&... args) -> info<Args...>;
122+
log_info(const char* ctx, fmt::format_string<Args...>,
123+
Args&&... args) -> log_info<Args...>;
124124

125125
template <typename... Args>
126-
error(const char* ctx, fmt::format_string<Args...>,
127-
Args&&... args) -> error<Args...>;
126+
log_error(const char* ctx, fmt::format_string<Args...>,
127+
Args&&... args) -> log_error<Args...>;
128128

129129
} // namespace utl
130130

include/utl/parallel_for.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ inline errors_t parallel_for(
160160
jobs.size(),
161161
[&](auto const idx) {
162162
if (idx % mod == 0) {
163-
utl::info("parallel_for", "{} {}/{}", desc, idx, jobs.size());
163+
utl::log_info("parallel_for", "{} {}/{}", desc, idx, jobs.size());
164164
}
165165
func(jobs[idx]);
166166
},

src/timer.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace utl {
66

77
scoped_timer::scoped_timer(std::string name)
88
: name_{std::move(name)}, start_{std::chrono::steady_clock::now()} {
9-
utl::info("scoped_timer", "[{}] starting", name);
9+
utl::log_info("scoped_timer", "[{}] starting", name);
1010
}
1111

1212
scoped_timer::~scoped_timer() {
@@ -15,7 +15,7 @@ scoped_timer::~scoped_timer() {
1515
double t =
1616
static_cast<double>(duration_cast<microseconds>(stop - start_).count()) /
1717
1000.0;
18-
utl::info("scoped_timer", "[{}] finished ({}ms)", name_, t);
18+
utl::log_info("scoped_timer", "[{}] finished ({}ms)", name_, t);
1919
}
2020

2121
void scoped_timer::print(std::string_view const message) const {
@@ -24,12 +24,12 @@ void scoped_timer::print(std::string_view const message) const {
2424
double const t =
2525
static_cast<double>(duration_cast<microseconds>(stop - start_).count()) /
2626
1000.0;
27-
utl::info("scoped_timer", "[{}] {} ({}ms)", name_, message, t);
27+
utl::log_info("scoped_timer", "[{}] {} ({}ms)", name_, message, t);
2828
}
2929

3030
manual_timer::manual_timer(std::string name)
3131
: name_{std::move(name)}, start_{std::chrono::steady_clock::now()} {
32-
utl::info("scoped_timer", "[{}] starting", name_);
32+
utl::log_info("scoped_timer", "[{}] starting", name_);
3333
}
3434

3535
void manual_timer::stop_and_print() const {
@@ -38,7 +38,7 @@ void manual_timer::stop_and_print() const {
3838
double t =
3939
static_cast<double>(duration_cast<microseconds>(stop - start_).count()) /
4040
1000.0;
41-
utl::info("scoped_timer", "[{}] finished ({}ms)", name_, t);
41+
utl::log_info("scoped_timer", "[{}] finished ({}ms)", name_, t);
4242
}
4343

4444
void manual_timer::print(std::string_view const message) const {
@@ -47,7 +47,7 @@ void manual_timer::print(std::string_view const message) const {
4747
double const t =
4848
static_cast<double>(duration_cast<microseconds>(stop - start_).count()) /
4949
1000.0;
50-
utl::info("scoped_timer", "[{}] {} ({}ms)", name_, message, t);
50+
utl::log_info("scoped_timer", "[{}] {} ({}ms)", name_, message, t);
5151
}
5252

5353
} // namespace utl

test/logging_test.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ using ::testing::MatchesRegex;
77

88
TEST(log, can_send_info_msg) {
99
testing::internal::CaptureStderr();
10-
utl::info("MyCtx", "Message");
10+
utl::log_info("MyCtx", "Message");
1111
EXPECT_THAT(
1212
testing::internal::GetCapturedStderr(),
1313
MatchesRegex(
@@ -16,7 +16,7 @@ TEST(log, can_send_info_msg) {
1616

1717
TEST(log, can_send_debug_msg) {
1818
testing::internal::CaptureStderr();
19-
utl::debug("MyCtx", "Message");
19+
utl::log_debug("MyCtx", "Message");
2020
EXPECT_THAT(
2121
testing::internal::GetCapturedStderr(),
2222
MatchesRegex(
@@ -25,7 +25,7 @@ TEST(log, can_send_debug_msg) {
2525

2626
TEST(log, can_send_error_msg) {
2727
testing::internal::CaptureStderr();
28-
utl::error("MyCtx", "Message");
28+
utl::log_error("MyCtx", "Message");
2929
EXPECT_THAT(
3030
testing::internal::GetCapturedStderr(),
3131
MatchesRegex(
@@ -35,15 +35,15 @@ TEST(log, can_send_error_msg) {
3535
TEST(log, can_format_extra_params) {
3636
testing::internal::CaptureStderr();
3737
auto const value = 42;
38-
utl::info("MyCtx", "String={} Int={}", "Hello", value);
38+
utl::log_info("MyCtx", "String={} Int={}", "Hello", value);
3939
EXPECT_THAT(testing::internal::GetCapturedStderr(),
4040
MatchesRegex(".+T.+Z \\[info\\] \\[logging.+:.+\\] \\[MyCtx\\] "
4141
"String=Hello Int=42\n"));
4242
};
4343

4444
TEST(log, can_have_optional_attrs) {
4545
testing::internal::CaptureStderr();
46-
utl::info("MyCtx", "Message").attrs({{"key", "value"}});
46+
utl::log_info("MyCtx", "Message").attrs({{"key", "value"}});
4747
EXPECT_THAT(
4848
testing::internal::GetCapturedStderr(),
4949
MatchesRegex(

0 commit comments

Comments
 (0)