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() {
97 
99 #ifndef NDEBUG
100 #define CLUTCHLOG( LEVEL, WHAT ) { \
-
101  auto& logger = clutchlog::logger(); \
-
102  std::ostringstream msg ; msg << WHAT; \
-
103  logger.log(clutchlog::level::LEVEL, msg.str(), CLUTCHLOC); \
+
101  auto& clutchlog__logger = clutchlog::logger(); \
+
102  std::ostringstream clutchlog__msg ; clutchlog__msg << WHAT; \
+
103  clutchlog__logger.log(clutchlog::level::LEVEL, clutchlog__msg.str(), CLUTCHLOC); \
104 }
105 #else // not Debug build.
106 #define CLUTCHLOG( LEVEL, WHAT ) { \
107  if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \
-
108  auto& logger = clutchlog::logger(); \
-
109  std::ostringstream msg ; msg << WHAT; \
-
110  logger.log(clutchlog::level::LEVEL, msg.str(), CLUTCHLOC); \
+
108  auto& clutchlog__logger = clutchlog::logger(); \
+
109  std::ostringstream clutchlog__msg ; clutchlog__msg << WHAT; \
+
110  clutchlog__logger.log(clutchlog::level::LEVEL, clutchlog__msg.str(), CLUTCHLOC); \
111  } \
112 }
113 #endif // NDEBUG
114 
116 #ifndef NDEBUG
117 #define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) { \
-
118  auto& logger = clutchlog::logger(); \
-
119  logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \
+
118  auto& clutchlog__logger = clutchlog::logger(); \
+
119  clutchlog__logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \
120  CLUTCHLOC, FILENAME, CLUTCHDUMP_DEFAULT_SEP); \
121 }
122 #else // not Debug build.
123 #define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) { \
124  if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \
-
125  auto& logger = clutchlog::logger(); \
-
126  logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \
+
125  auto& clutchlog__logger = clutchlog::logger(); \
+
126  clutchlog__logger.dump(clutchlog::level::LEVEL, std::begin(CONTAINER), std::end(CONTAINER), \
127  CLUTCHLOC, FILENAME, CLUTCHDUMP_DEFAULT_SEP); \
128  } \
129 }
@@ -184,18 +184,18 @@ $(function() {
131 
133 #ifndef NDEBUG
134 #define CLUTCHFUNC( LEVEL, FUNC, ... ) { \
-
135  auto& logger = clutchlog::logger(); \
-
136  clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
-
137  if(scope.matches) { \
+
135  auto& clutchlog__logger = clutchlog::logger(); \
+
136  clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
+
137  if(clutchlog__scope.matches) { \
138  FUNC(__VA_ARGS__); \
139  } \
140 }
141 #else // not Debug build.
142 #define CLUTCHFUNC( LEVEL, FUNC, ... ) { \
143  if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \
-
144  auto& logger = clutchlog::logger(); \
-
145  clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
-
146  if(scope.matches) { \
+
144  auto& clutchlog__logger = clutchlog::logger(); \
+
145  clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
+
146  if(clutchlog__scope.matches) { \
147  FUNC(__VA_ARGS__); \
148  } \
149  } \
@@ -204,18 +204,18 @@ $(function() {
152 
154 #ifndef NDEBUG
155 #define CLUTCHCODE( LEVEL, ... ) { \
-
156  auto& logger = clutchlog::logger(); \
-
157  clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
-
158  if(scope.matches) { \
+
156  auto& clutchlog__logger = clutchlog::logger(); \
+
157  clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
+
158  if(clutchlog__scope.matches) { \
159  __VA_ARGS__ \
160  } \
161 }
162 #else // not Debug build.
163 #define CLUTCHCODE( LEVEL, CODE ) { \
164  if(clutchlog::level::LEVEL <= CLUTCHLOG_DEFAULT_DEPTH_BUILT_NODEBUG) { \
-
165  auto& logger = clutchlog::logger(); \
-
166  clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
-
167  if(scope.matches) { \
+
165  auto& clutchlog__logger = clutchlog::logger(); \
+
166  clutchlog::scope_t clutchlog__scope = clutchlog__logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
+
167  if(clutchlog__scope.matches) { \
168  CODE \
169  } \
170  } \
diff --git a/docs/group__UseMacros.html b/docs/group__UseMacros.html index 48e4663..8ddd777 100644 --- a/docs/group__UseMacros.html +++ b/docs/group__UseMacros.html @@ -116,9 +116,9 @@ Macros
Value:
{ \
-
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__ \
} \
}
@@ -159,8 +159,8 @@ Macros
Value:
{ \
-
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), \
}
@@ -200,9 +200,9 @@ Macros
Value:
{ \
-
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__); \
} \
}
@@ -237,9 +237,9 @@ Macros
Value:
{ \
-
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); \
}

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 Configuration

The 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:

log.depth_mark(CLUTCHLOG_DEFAULT_DEPTH_MARK); // Defaults to ">".
-

+

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.

+

Output style

The output can be colored differently depending on the log level.

// Print error messages in bold red:
log.style(clutchlog::level::error, // First, the log level.
@@ -268,6 +269,8 @@ Limitations

Dependencies

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.

+

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):