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

set_level not setting _level #105

Closed
dougtinkham opened this issue May 31, 2015 · 4 comments
Closed

set_level not setting _level #105

dougtinkham opened this issue May 31, 2015 · 4 comments

Comments

@dougtinkham
Copy link

Great and fast library.

I am using a custom sink though I do not think this matters.

Problem: After creating a logger, I use spdlog::set_level(spdlog::level::trace); but my trace and debug level logs do not log. I found that if I comment line 43 in logger_impl.h that my trace and debug logs are logged. Line 43 is currently the line _level = level::info; in logger function:

template
inline spdlog::logger::logger(const std::string& logger_name, const It& begin, const It& end) :
_name(logger_name),
_sinks(begin, end),
_formatter(std::make_shared<pattern_formatter>("%+"))
{

// no support under vs2013 for member initialization for std::atomic
_level = level::info;

}

I'm using clang in QtCreator on Mac OS X Yosemity, logging to a QTextEdit from a logger created at global namespace.

Please let me know if you think I've failed to do something to setup my logging and/or if commenting that line is ok or bad.

Thanks!

@xaqq
Copy link
Contributor

xaqq commented May 31, 2015

If I recall correctly, spdlog::set_level() only apply for loggers that
are created after the call to set_level().
You have 2 possiblities:
* Call set_loger() on your logger object.
* Create your logger object after calling spdlog::set_level().

On Sun, May 31, 2015 at 2:38 AM, gedrite notifications@github.com wrote:

Great and fast library.

I am using a custom sink though I do not think this matters.

Problem: After creating a logger, I use
spdlog::set_level(spdlog::level::trace); but my trace and debug level logs
do not log. I found that if I comment line 43 in logger_impl.h that my
trace and debug logs are logged. Line 43 is currently the line _level =
level::info; in logger function:

template
inline spdlog::logger::logger(const std::string& logger_name, const It&
begin, const It& end) :
_name(logger_name),
_sinks(begin, end),
_formatter(std::make_shared("%+"))
{

// no support under vs2013 for member initialization for std::atomic
_level = level::info;

}

I'm using clang in QtCreator on Mac OS X Yosemity, logging to a QTextEdit
from a logger created at global namespace.

Please let me know if you think I've failed to do something to setup my
logging and/or if commenting that line is ok or bad.

Thanks!


Reply to this email directly or view it on GitHub
#105.

Kapp Arnaud - Xaqq

@dougtinkham
Copy link
Author

I chose your option #1, setting the level on my logger object. It now works as expected.

Thanks xaqq!

@gabime
Copy link
Owner

gabime commented May 31, 2015

spdlog:set_level can be called before creation actually.

I think the problem is that this logger was not regisered.

A call to register_logger before the call would fix this too..

@coderc264
Copy link

Hi all, i have the same problem but the workaround didn't work for me

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

4 participants