nestlog: expand ex2

This commit is contained in:
Roland Conybeare 2023-09-16 15:16:10 -04:00
commit 0260ca79c1
2 changed files with 12 additions and 5 deletions

View file

@ -49,7 +49,7 @@ output:
- indentation reflects call structure. We don't see anything for `main()`,
since we didn't put any logging there
### 2
### 2 slightly more elaborate
```
/* examples ex2/ex2.cpp */
@ -89,6 +89,9 @@ main(int argc, char ** argv) {
log && log("<- :fib(n) ", fn);
}
```
- global configuration settings live in the `xo::log_config` class. see [log_config.hpp](include/nestlog/log_config.hpp)
- the recommended form `log && log(...)` tests whether logging at this site is enabled /before/ evaluating/formatting the log message;
when logging is disabled, this saves the cost of computing and formatting that message.
output:
![ex2 output](img/ex2.png)

View file

@ -2,13 +2,17 @@
using namespace xo;
void A(int x) {
XO_SCOPE(log, info);
void inner(int x) {
scope log(XO_ENTER0(always), ":x ", x);
}
log("x:", x);
void outer(int y) {
scope log(XO_ENTER0(always), ":y ", y);
inner(2*y);
}
int
main(int argc, char ** argv) {
A(66);
outer(123);
}