0

How can I format the output of SPDLOG macro calls to exclude [main.cpp:9] parts?

#include <spdlog/spdlog.h>

int main()
{
    SPDLOG_DEBUG("SMTH1");
    SPDLOG_TRACE("SMTH2");
    SPDLOG_INFO("SMTH3");
}

default output:

[2022-11-11 21:07:28.346] [temp] [debug] [main.cpp:9] SMTH1
[2022-11-11 21:07:28.348] [trace] [debug] [main.cpp:10] SMTH2
[2022-11-11 21:07:28.349] [info] [debug] [main.cpp:11] SMTH3

desired output:

[2022-11-11 21:07:28.346] [temp] [debug] SMTH1
[2022-11-11 21:07:28.348] [trace] [debug] SMTH2
[2022-11-11 21:07:28.349] [info] [debug] SMTH3
Burak
  • 2,251
  • 1
  • 16
  • 33
lbsmart
  • 83
  • 6
  • Why do you set the active level to `TRACE` where you do not wish to see `DEBUG` level? You could set it to `INFO` in the first place. – Burak Nov 11 '22 at 17:40
  • @Burak it doesn't matter, just a typo, that's not the question – lbsmart Nov 11 '22 at 17:55
  • Typo or not, you just changed `TRACE` to `DEBUG`. My question is still the same. Why do you set the active level to `DEBUG` where you do not want to see log calls at level `DEBUG`? If that is because some external code defines that macro, you should mention that in the question. If you are the one who is setting that macro in the first place, you are contradicting yourself. Elaborate please. – Burak Nov 11 '22 at 18:04
  • Could you please explain how macro output formatting is related to the output level? How will this information help you? There are no definitions before this, I corrected the code, although the essence of this does not change in any way, because the problem is in the formatting and not in the output level. And i don't say what i do not want to see logs calls at level DEBUG? – lbsmart Nov 11 '22 at 18:12
  • So you want to see `[2022-11-11 21:07:28.349] [info] [debug] SMTH3` instead of `[2022-11-11 21:07:28.349] [info] [debug] [main.cpp:11] SMTH3`. The question is not clear. I'm just poking around to clarify what resulting behavior you expect. – Burak Nov 11 '22 at 18:19
  • @Burak yes, youre right – lbsmart Nov 11 '22 at 18:35
  • I have edited the question accordingly. Please see [how to ask](https://stackoverflow.com/help/how-to-ask). – Burak Nov 11 '22 at 18:50

2 Answers2

1

From the wiki page https://github.com/gabime/spdlog/wiki/3.-Custom-formatting

spdlog::set_pattern("[%Y-%m-%d %H:%M:%S.%e] [%n] [%l]  %v");

We have the date pattern, %n is the logger name, %l is the log level of the message and %v is the message. You can do a lot of things by checking the wiki.

Matoran
  • 114
  • 1
  • 6
0

#define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_INFO before including spdlog.h

GabiMe
  • 18,105
  • 28
  • 76
  • 113
  • You sure what my quastion sound like "Where me need include define SPDLOG_...?" ? I have another problem, and i include this define before spdlog.h if you doesnt see my quastion description – lbsmart Nov 11 '22 at 17:53
  • 3
    It seems the question is not about suppressing the output but about formatting it. This answer is irrelevant in that case. – Burak Nov 11 '22 at 18:54