Update docs

This commit is contained in:
Alexey Rybalchenko 2019-08-22 12:21:21 +02:00 committed by Mohammad Al-Turany
parent bb5e67a5e7
commit 2a7d4dfd9a
2 changed files with 28 additions and 9 deletions

View File

@ -18,6 +18,8 @@ cmake -DCMAKE_INSTALL_PREFIX=./FairLogger_install ../FairLogger
cmake --build . --target install
```
FairLogger bundles a version of the [fmt](https://github.com/fmtlib/fmt) library. You can override this with your own fmt installation via the `-DUSE_EXTERNAL_FMT=ON` and `-DFMT_ROOT=/fmt/location` CMake switches.
## Usage
In your `CMakeLists.txt`:
@ -35,6 +37,8 @@ find_package(FairLogger)
`find_package(FairLogger)` will define an imported target `FairLogger::FairLogger`.
In case of external fmt, the using project will need to find it.
## CMake options
On command line:
@ -49,7 +53,18 @@ On command line:
All log calls go through the provided LOG(severity) macro. Output through this macro is thread-safe. Logging is done to cout, file output and/or custom sinks.
## 2. Severity
## 2. Additional macros
A number of additional logging macros are provided:
- `LOGV(severity, verbosity)` Log the line with the provided verbosity, e.g. `LOG(info, veryhigh) << "abcd";`
- `LOGF(severity, ...)` The arguments are given to `fmt::format` and the result is logged, e.g. `LOGF(info, "Hello {}!", "world");`
- `LOGP(severity, ...)` The arguments are given to `fmt::printf` and the result is logged, e.g. `LOGP(info, "Hello %s!", "world");`
- `LOGN(severity)` Logs an empty line, e.g. `LOGN(info);`
- `LOG_IF(severity, condition)` Logs the line if the provided condition if true
- `LOGD(severity, file, line, f)` Logs the line with the provided file, line and function parameters (only if the active verbosity allows it).
## 3. Severity
The log severity is controlled via:
```C++
@ -79,21 +94,25 @@ where severity level is one of the following:
Logger will log the chosen severity and all above it (except "nolog", which deactivates logging for that sink completely). Fatal severity is always logged.
## 3. Verbosity
## 4. Verbosity
The log verbosity is controlled via:
```C++
fair::Logger::SetVerbosity("<verbosity level>");
```
it is same for all sinks, and is one of the following values: `verylow`, `low`, `medium`, `high`, `veryhigh`, which translates to following output:
it is same for all sinks, and is one of the following values: `verylow`, `low`, `medium`, `high`, `veryhigh`, `user1`, `user2`, `user3`, `user4`, which translates to following output:
```
verylow: message
low: [severity] message
medium: [HH:MM:SS][severity] message
high: [process name][HH:MM:SS:µS][severity] message
high: [process name][HH:MM:SS][severity] message
veryhigh: [process name][HH:MM:SS:µS][severity][file:line:function] message
user1: [severity] message
user2: [severity] message
user3: [severity] message
user4: [severity] message
```
When running a FairMQ device, the log severity can be simply provided via `--verbosity <level>` cmd option.
@ -122,7 +141,7 @@ auto spec = fair::VerbositySpec::Make(VerbositySpec::Info::timestamp_s,
| `fair::VerbositySpec::Info::file_line_function` | `[file:line:function]` |
### 3.1 `BOOST_PRETTY_FUNCTION` support
### 4.1 `BOOST_PRETTY_FUNCTION` support
By default, the `veryhigh` verbosity prints the function name from which the `LOG` macro was invoked. If you desire a more verbose function signature including the full namespace, return value and function arguments, you can enable support for `BOOST_PRETTY_FUNCTION`
@ -136,7 +155,7 @@ By default, the `veryhigh` verbosity prints the function name from which the `LO
In the latter case, the user needs to take care of adding the boost include path to the compiler search path manually (e.g. `-I/path/to/boost/include`).
## 4. Color
## 5. Color
Colored output on console can be activated with:
```C++
@ -145,7 +164,7 @@ Logger::SetConsoleColor(true);
When running a FairMQ device, the log color (console) can be simply provided via `--color <true/false>` cmd option (default is true).
## 5. File output
## 6. File output
Output to file can be enabled via:
```C++
@ -155,7 +174,7 @@ which will add output to "test_log" filename (if third parameter is `true` it wi
When running a FairMQ device, the log file can be simply provided via `--log-to-file <filename_prefix>` cmd option (this will also turn off console output).
## 5.5 Custom sinks
## 7. Custom sinks
Custom sinks can be added via `Logger::AddCustomSink("sink name", "<severity>", callback)` method.

View File

@ -79,7 +79,7 @@ enum class Severity : int
// verylow: message
// low: [severity] message
// medium: [HH:MM:SS][severity] message
// high: [process name][HH:MM:SS:µS][severity] message
// high: [process name][HH:MM:SS][severity] message
// veryhigh: [process name][HH:MM:SS:µS][severity][file:line:function] message
enum class Verbosity : int
{