fix {depth} display, warnings and doc
- fix call stack depth display with {depth}: remove (5) stripped depths.
- fix warnings in tests
- Explain CLUTCHLOG_HAVE_UNIX_SYSINFO in the README.
This commit is contained in:
parent
6123490af6
commit
44ffe6309a
4 changed files with 63 additions and 2 deletions
17
README.md
17
README.md
|
|
@ -345,16 +345,33 @@ Note: the log levels constants are lower case (for example: `clutchlog::level::x
|
|||
Limitations
|
||||
===========
|
||||
|
||||
### System-dependent stack depth
|
||||
|
||||
Because the call stack depth and program name access are system-dependent,
|
||||
the features relying on the depth of the call stack and the display of the program name
|
||||
are only available for operating systems having the following headers:
|
||||
`execinfo.h`, `stdlib.h` and `libgen.h` (so far, tested with Linux).
|
||||
|
||||
Clutchlog sets the `CLUTCHLOG_HAVE_UNIX_SYSINFO` to 1 if the headers are
|
||||
available, and to 0 if they are not.
|
||||
You can make portable code using something like:
|
||||
```cpp
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
|
||||
log.depth( x );
|
||||
#endif
|
||||
```
|
||||
|
||||
|
||||
### 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.
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
What Clutchlog do not provide at the moment (but may in a near future):
|
||||
|
||||
- Super fast log writing.
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ namespace fs = std::filesystem;
|
|||
#include <execinfo.h> // execinfo
|
||||
#include <stdlib.h> // getenv
|
||||
#include <libgen.h> // basename
|
||||
//! POSIX headers necessary for stack depth management are available.
|
||||
#define CLUTCHLOG_HAVE_UNIX_SYSINFO 1
|
||||
#else
|
||||
#define CLUTCHLOG_HAVE_UNIX_SYSINFO 0
|
||||
|
|
@ -36,6 +37,7 @@ namespace fs = std::filesystem;
|
|||
**********************************************************************/
|
||||
#ifndef WITH_CLUTCHLOG
|
||||
#ifndef NDEBUG
|
||||
//! Actually enable clutchlog features.
|
||||
#define WITH_CLUTCHLOG
|
||||
#endif
|
||||
#endif
|
||||
|
|
@ -662,7 +664,7 @@ class clutchlog
|
|||
|
||||
#if CLUTCHLOG_HAVE_UNIX_SYSINFO == 1
|
||||
format = replace(format, "\\{name\\}", name);
|
||||
format = replace(format, "\\{depth\\}", depth);
|
||||
format = replace(format, "\\{depth\\}", depth - _strip_calls);
|
||||
|
||||
std::ostringstream chevrons;
|
||||
for(size_t i = _strip_calls; i < depth; ++i) {
|
||||
|
|
|
|||
42
tests/t-assert.cpp
Normal file
42
tests/t-assert.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
#include "../clutchlog/clutchlog.h"
|
||||
|
||||
// Make asserts (de)clutchable.
|
||||
#define ASSERT(LEVEL, ...) { CLUTCHFUNC(LEVEL, assert, __VA_ARGS__) }
|
||||
|
||||
void h()
|
||||
{
|
||||
CLUTCHLOG(info, "!");
|
||||
ASSERT(info, true == true);
|
||||
std::clog << "--" << std::endl;
|
||||
}
|
||||
|
||||
void g()
|
||||
{
|
||||
CLUTCHLOG(warning, "world");
|
||||
ASSERT(warning, strcmp("life","life") == 0);
|
||||
h();
|
||||
}
|
||||
|
||||
void f()
|
||||
{
|
||||
CLUTCHLOG(error, "hello ");
|
||||
ASSERT(error, strcmp("no more","please")!=0);
|
||||
g();
|
||||
}
|
||||
|
||||
int main(/*const int argc, char* argv[]*/)
|
||||
{
|
||||
auto& log = clutchlog::logger();
|
||||
|
||||
log.func("f");
|
||||
f();
|
||||
|
||||
log.func("g");
|
||||
f();
|
||||
|
||||
log.func("h");
|
||||
f();
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ int main(const int argc, char* argv[])
|
|||
} else {
|
||||
try {
|
||||
log.threshold(log.level_of(argv[1]));
|
||||
} catch(std::out_of_range err) {
|
||||
} catch(std::out_of_range& err) {
|
||||
CLUTCHLOG(critical,err.what());
|
||||
exit(100);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue