add the CLUTCHCODE macro
This commit is contained in:
parent
3175e2d87b
commit
74c33f6371
2 changed files with 45 additions and 3 deletions
12
README.md
12
README.md
|
|
@ -313,6 +313,18 @@ Thus, any call like `ASSERT(error, x > 3);` will be declutchable
|
||||||
with the same configuration than a call to `CLUTCHLOG`.
|
with the same configuration than a call to `CLUTCHLOG`.
|
||||||
|
|
||||||
|
|
||||||
|
(De)clutch any code section
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
The `CLUTCHCODE` macro allows to wrap any code within the current logger.
|
||||||
|
|
||||||
|
For instance:
|
||||||
|
```cpp
|
||||||
|
CLUTCHCODE(info,
|
||||||
|
std::clog << "We are clutched!\n";
|
||||||
|
);
|
||||||
|
```
|
||||||
|
|
||||||
Log level semantics
|
Log level semantics
|
||||||
===================
|
===================
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@
|
||||||
}
|
}
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
|
|
||||||
//! Call an assert at the given level.
|
//! Call any function if the scope matches.
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
#define CLUTCHFUNC( LEVEL, FUNC, ... ) { \
|
#define CLUTCHFUNC( LEVEL, FUNC, ... ) { \
|
||||||
auto& logger = clutchlog::logger(); \
|
auto& logger = clutchlog::logger(); \
|
||||||
|
|
@ -126,16 +126,46 @@
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#else // not Debug build.
|
#else // not Debug build.
|
||||||
#define CLUTCHFUNC( LEVEL, FUNC, ... ) { do {/*nothing*/} while(false); }
|
#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) { \
|
||||||
|
FUNC(__VA_ARGS__); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#endif // NDEBUG
|
||||||
|
|
||||||
|
//! Run any code if the scope matches.
|
||||||
|
#ifndef NDEBUG
|
||||||
|
#define CLUTCHCODE( LEVEL, CODE ) { \
|
||||||
|
auto& logger = clutchlog::logger(); \
|
||||||
|
clutchlog::scope_t scope = logger.locate(clutchlog::level::LEVEL, CLUTCHLOC); \
|
||||||
|
if(scope.matches) { \
|
||||||
|
CODE \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#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) { \
|
||||||
|
CODE \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
|
}
|
||||||
#endif // NDEBUG
|
#endif // NDEBUG
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
#else // not WITH_CLUTCHLOG
|
#else // not WITH_CLUTCHLOG
|
||||||
// Disabled macros can still be used in Release builds.
|
// Disabled macros can still be called in Release builds.
|
||||||
#define CLUTCHLOG( LEVEL, WHAT ) { do {/*nothing*/} while(false); }
|
#define CLUTCHLOG( LEVEL, WHAT ) { do {/*nothing*/} while(false); }
|
||||||
#define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) { do {/*nothing*/} while(false); }
|
#define CLUTCHDUMP( LEVEL, CONTAINER, FILENAME ) { do {/*nothing*/} while(false); }
|
||||||
#define CLUTCHFUNC( LEVEL, FUNC, ... ) { do {/*nothing*/} while(false); }
|
#define CLUTCHFUNC( LEVEL, FUNC, ... ) { do {/*nothing*/} while(false); }
|
||||||
|
#define CLUTCHCODE( LEVEL, CODE ) { do {/*nothing*/} while(false); }
|
||||||
#endif // WITH_CLUTCHLOG
|
#endif // WITH_CLUTCHLOG
|
||||||
|
|
||||||
/**********************************************************************
|
/**********************************************************************
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue