diff --git a/README.md b/README.md index e9d0d3c..836f02a 100644 --- a/README.md +++ b/README.md @@ -374,6 +374,12 @@ Clutchlog needs `C++-17` with the `filesystem` feature. You may need to indicate `-std=c++17 -lstdc++fs` to some compilers. +### Variable names within the CLUTCHLOG macro + +Calling the `CLUTCHLOG` macro with a message using a variable named `clutchlog__msg` will end in +an error. Avoid this kind of naming for the logger singleton, also. + + ### Features What Clutchlog do not provide at the moment (but may in a near future): diff --git a/clutchlog/clutchlog.h b/clutchlog/clutchlog.h index 8120717..28b42c8 100644 --- a/clutchlog/clutchlog.h +++ b/clutchlog/clutchlog.h @@ -98,16 +98,16 @@ namespace fs = std::filesystem; //! Log a message at the given level. #ifndef NDEBUG #define CLUTCHLOG( LEVEL, WHAT ) { \ - auto& logger = clutchlog::logger(); \ - std::ostringstream msg ; msg << WHAT; \ - logger.log(clutchlog::level::LEVEL, msg.str(), CLUTCHLOC); \ + auto& clutchlog__logger = clutchlog::logger(); \ + std::ostringstream clutchlog__msg ; clutchlog__msg << WHAT; \ + clutchlog__logger.log(clutchlog::level::LEVEL, clutchlog__msg.str(), CLUTCHLOC); \ } #else // not Debug build. #define CLUTCHLOG( LEVEL, WHAT ) { \ if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \ - auto& logger = clutchlog::logger(); \ - std::ostringstream msg ; msg << WHAT; \ - logger.log(clutchlog::level::LEVEL, msg.str(), CLUTCHLOC); \ + auto& clutchlog__logger = clutchlog::logger(); \ + std::ostringstream clutchlog__msg ; clutchlog__msg << WHAT; \ + clutchlog__logger.log(clutchlog::level::LEVEL, clutchlog__msg.str(), CLUTCHLOC); \ } \ } #endif // NDEBUG @@ -115,15 +115,15 @@ namespace fs = std::filesystem; //! Dump the given container. #ifndef NDEBUG #define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) { \ - auto& logger = clutchlog::logger(); \ - logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \ + auto& clutchlog__logger = clutchlog::logger(); \ + clutchlog__logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \ CLUTCHLOC, FILENAME, CLUTCHDUMP_DEFAULT_SEP); \ } #else // not Debug build. #define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) { \ if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \ - auto& logger = clutchlog::logger(); \ - logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \ + auto& clutchlog__logger = clutchlog::logger(); \ + clutchlog__logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \ CLUTCHLOC, FILENAME, CLUTCHDUMP_DEFAULT_SEP); \ } \ } @@ -132,18 +132,18 @@ namespace fs = std::filesystem; //! Call any function if the scope matches. #ifndef NDEBUG #define CLUTCHFUNC( LEVEL, FUNC, ... ) { \ - auto& logger = clutchlog::logger(); \ - clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \ - if(scope.matches) { \ + auto& clutchlog__logger = clutchlog::logger(); \ + clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \ + if(clutchlog__scope.matches) { \ FUNC(__VA_ARGS__); \ } \ } #else // not Debug build. #define CLUTCHFUNC( LEVEL, FUNC, ... ) { \ if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \ - auto& logger = clutchlog::logger(); \ - clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \ - if(scope.matches) { \ + auto& clutchlog__logger = clutchlog::logger(); \ + clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \ + if(clutchlog__scope.matches) { \ FUNC(__VA_ARGS__); \ } \ } \ @@ -153,18 +153,18 @@ namespace fs = std::filesystem; //! Run any code if the scope matches. #ifndef NDEBUG #define CLUTCHCODE( LEVEL, ... ) { \ - auto& logger = clutchlog::logger(); \ - clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \ - if(scope.matches) { \ + auto& clutchlog__logger = clutchlog::logger(); \ + clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \ + if(clutchlog__scope.matches) { \ __VA_ARGS__ \ } \ } #else // not Debug build. #define CLUTCHCODE( LEVEL, CODE ) { \ if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \ - auto& logger = clutchlog::logger(); \ - clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \ - if(scope.matches) { \ + auto& clutchlog__logger = clutchlog::logger(); \ + clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \ + if(clutchlog__scope.matches) { \ CODE \ } \ } \ diff --git a/docs/clutchlog_8h_source.html b/docs/clutchlog_8h_source.html index 51cc1bb..17dd412 100644 --- a/docs/clutchlog_8h_source.html +++ b/docs/clutchlog_8h_source.html @@ -152,31 +152,31 @@ $(function() {
- - - + + + - - - + + + - - + + - - + + @@ -184,18 +184,18 @@ $(function() { - - - + +Log a message at the given level.
diff --git a/docs/index.html b/docs/index.html index a8dbaba..03f5da3 100644 --- a/docs/index.html +++ b/docs/index.html @@ -171,7 +171,8 @@ Output ConfigurationThe default log format is "[{name}] {level_letter}:{depth_marks} {msg}\t\t\t\t\t{func} @ {file}:{line}\n", it can be overriden at compile time by defining the CLUTCHLOG_DEFAULT_FORMAT macro.
The default format of the first line of comment added with the dump macro is "# [{name}] {level} in {func} (at depth {depth}) @ {file}:{line}". It can be edited with the format_comment method. If it is set to an empty string, then no comment line is added. The default can be modified at compile time with CLUTCHDUMP_DEFAULT_FORMAT. By default, the separator between items in the container is a new line. To change this behaviour, you can change CLUTCHDUMP_DEFAULT_SEP or call the low-level dump method.
The mark used with the {depth_marks} tag can be configured with the depth_mark method, and its default with the CLUTCHLOG_DEFAULT_DEPTH_MARK macro:
By default, clutchlog removes 5 levels of the calls stack, so that your main entrypoint corresponds to a depth of zero. You can change this behaviour by defining the CLUTCHLOG_STRIP_CALLS macro.
The output can be colored differently depending on the log level.
Some colors/styles may not be supported by some exotic terminal emulators.
Clutchlog needs C++-17 with the filesystem feature. You may need to indicate -std=c++17 -lstdc++fs to some compilers.
Calling the CLUTCHLOG macro with a message using a variable named clutchlog__msg will end in an error. Avoid this kind of naming for the logger singleton, also.
What Clutchlog do not provide at the moment (but may in a near future):