Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

show file and line number on global logger #3257

Open
thewh1teagle opened this issue Nov 14, 2024 · 1 comment
Open

show file and line number on global logger #3257

thewh1teagle opened this issue Nov 14, 2024 · 1 comment

Comments

@thewh1teagle
Copy link

thewh1teagle commented Nov 14, 2024

Hi!

I would like to show filename and line number in the global logger.
I tried to use the macros like

SPDLOG_DEBUG(...)

but seems like it depends on constant static level defined with #define otherwise it's not print anything (also I can't change it?). However I would like to simply use:

spdlog::debug(...)

And it will show line numbers.

If it's not possible and it's possible only when specifying the logger, should I declare the logger statically in some header file and use it directly eg.

spdlog::debug(g_logger, ...)

TLDR of what I'm looking for:

int main() {
  spdlog::cfg::load_env_levels();
  spdlog::debug("hello");
  return 0;
}
./app
DEBUG main.cpp:2: hello

The project for repo: loud.cpp

@tt4g
Copy link
Contributor

tt4g commented Nov 14, 2024

The logging macro was originally introduced as a feature to remove unnecessary log output at compile time: https://github.com/gabime/spdlog/wiki/0.-FAQ#how-to-remove-all-debug-statements-at-compile-time-

Replace all logging statements with logging macros and define #define SPDLOG_ACTIVE_LEVEL SPDLOG_LEVEL_TRACE macro (before using spdlog) so that logging macros are not removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants