From 0ed8d865a08e7d7a03e94d6b8c586c65e3438f9d Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 16 Sep 2023 15:08:37 -0400 Subject: [PATCH] nestlog: README improvements --- README.md | 71 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 4943e8f0..8145c91a 100644 --- a/README.md +++ b/README.md @@ -42,53 +42,60 @@ main(int argc, char ** argv) { ``` output: -![ex12 output](img/ex1.png) +![ex1 output](img/ex1.png) + +- nestlog types are provided in the `xo` namespace. + macros are prefixed with `XO_` +- indentation reflects call structure. We don't see anything for `main()`, + since we didn't put any logging there ### 2 - /* examples ex2/ex2.cpp */ +``` +/* examples ex2/ex2.cpp */ - #include "nestlog/scope.hpp" +#include "nestlog/scope.hpp" - using namespace xo; +using namespace xo; - int - fib(int n) { - scope log(XO_ENTER0(info), ":n ", n); +int +fib(int n) { + scope log(XO_ENTER0(info), ":n ", n); - int retval = 1; - - if (n >= 2) { - retval = fib(n - 1) + fib(n - 2); - log && log(":n ", n); - } - - log.end_scope("<- :retval ", retval); - - return retval; - } - - int - main(int argc, char ** argv) { - log_config::min_log_level = xo::log_level::info; - log_config::indent_width = 4; - - int n = 4; - - scope log(XO_ENTER0(info), ":n ", 4); - - int fn = fib(n); + int retval = 1; + if (n >= 2) { + retval = fib(n - 1) + fib(n - 2); log && log(":n ", n); - log && log("<- :fib(n) ", fn); } + log.end_scope("<- :retval ", retval); + + return retval; +} + +int +main(int argc, char ** argv) { + log_config::min_log_level = xo::log_level::info; + log_config::indent_width = 4; + + int n = 4; + + scope log(XO_ENTER0(info), ":n ", 4); + + int fn = fib(n); + + log && log(":n ", n); + log && log("<- :fib(n) ", fn); +} +``` + output: ![ex2 output](img/ex2.png) ### 3 example exposing runtime configuration options - ``` +``` /* examples ex3/ex3.cpp */ #include "nestlog/scope.hpp" @@ -135,7 +142,7 @@ output: } /* ex3/ex3.cpp */ - ``` +``` output: ![ex3 output](img/ex3.png)