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

Use enum class for log level for type safety #1794

Open
FalcoGer opened this issue Jan 9, 2021 · 3 comments
Open

Use enum class for log level for type safety #1794

FalcoGer opened this issue Jan 9, 2021 · 3 comments

Comments

@FalcoGer
Copy link

FalcoGer commented Jan 9, 2021

The sink::set_level() expects a level argument.
Currently the levels are defined using #define and a normal enumeration.
A better way would be to use an enum class for type safety. in that case a user can't input random numbers into the function and gets more verbose help from his IDE.

@gabime
Copy link
Owner

gabime commented Jan 9, 2021

This is an api breaking change so can be considered only for next major version (2.x).

@visstro
Copy link

visstro commented May 29, 2022

While breaking API in this area, could we consider making it a little more flexible and allow user defined levels?
I think that something like this was requested a few times already, like here: #834, #2279

Personally, I don't like too many levels and existing ones are fine... But it could make adapting spdlog into existing solutions much easier.
Linux traditionally uses 8 predefined levels. Google log has some severity levels, but then it has verbose logging, when log level is just any number. Etc...

@stephanlachnit
Copy link

I just want to point out, if this is done there should be way to define its own spdlog::level::level_enum. There some cases where you want to have log levels in a file without the need to include the full spdlog header (think compilation time). Currently you can just create an int enum and cast them to spdlog's enum, but when you make it a class enum that is not (easily) possible anymore.

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

No branches or pull requests

4 participants