Skip to content

Commit 4e9f2e2

Browse files
committed
Add description of the supported log levels
1 parent 51bb855 commit 4e9f2e2

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
---
2+
title: Log Levels
3+
description: How customise log levels.
4+
keywords: logging, log, levels, setup, cmake
5+
author: RSP Systems A/S
6+
---
7+
8+
# Log Levels
9+
10+
[TOC]
11+
12+
## PSR Log Levels
13+
14+
The logging module defines the following log levels (_severities_), from
15+
[PSR-3: Logger Interface](https://www.php-fig.org/psr/psr-3/) - (_In accordance with [RFC 5424](https://datatracker.ietf.org/doc/html/rfc5424)_).
16+
17+
* `EMERGENCY_LEVEL`: _Emergency: system is unusable._
18+
* `ALERT_LEVEL`: _Alert: action must be taken immediately._
19+
* `CRITICAL_LEVEL`: _Critical: critical conditions._
20+
* `ERROR_LEVEL`: _Error: error conditions._
21+
* `WARNING_LEVEL`: _Warning: warning conditions._
22+
* `NOTICE_LEVEL`: _Notice: normal but significant condition._
23+
* `INFO_LEVEL`: _Informational: informational messages._
24+
* `DEBUG_LEVEL`: _Debug: debug-level messages._
25+
26+
## CMake Message Modes
27+
28+
All the PSR log levels are associated with the following cmake [message modes](https://cmake.org/cmake/help/latest/command/message.html#general-messages).
29+
This means that cmake's [message log level](https://cmake.org/cmake/help/latest/command/cmake_language.html#get-message-log-level)
30+
is respected, when using any of the logging functions that are offered by this module.
31+
32+
| Psr Log Level | CMake Message Mode |
33+
|-------------------|--------------------|
34+
| `EMERGENCY_LEVEL` | `FATAL_ERROR` |
35+
| `ALERT_LEVEL` | `FATAL_ERROR` |
36+
| `CRITICAL_LEVEL` | `FATAL_ERROR` |
37+
| `ERROR_LEVEL` | `SEND_ERROR` |
38+
| `WARNING_LEVEL` | `WARNING` |
39+
| `NOTICE_LEVEL` | `NOTICE` |
40+
| `INFO_LEVEL` | `NOTICE` |
41+
| `DEBUG_LEVEL` | `DEBUG` |
42+
43+
## Customize
44+
45+
To change the default PSR log level / cmake message mode association, set the `RSP_LOG_LEVELS_CMAKE` property,
46+
before you include the `rsp/logging` module
47+
or by [force](https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry) caching the property.
48+
49+
Use the following format for associating the levels:
50+
51+
```txt
52+
"<psr> <cmake_mode>"
53+
```
54+
* _`<psr>`_: PSR log level name (_lowercase_).
55+
* _`<cmake_mode>`_: cmake's [message modes](https://cmake.org/cmake/help/latest/command/message.html#general-messages).
56+
57+
```cmake
58+
set(RSP_LOG_LEVELS_CMAKE
59+
"${EMERGENCY_LEVEL} FATAL_ERROR"
60+
"${ALERT_LEVEL} FATAL_ERROR"
61+
"${CRITICAL_LEVEL} FATAL_ERROR"
62+
"${ERROR_LEVEL} FATAL_ERROR"
63+
"${WARNING_LEVEL} WARNING"
64+
"${NOTICE_LEVEL} NOTICE"
65+
"${INFO_LEVEL} STATUS"
66+
"${DEBUG_LEVEL} STATUS"
67+
68+
CACHE STRING "Log levels / message mode"
69+
)
70+
```

0 commit comments

Comments
 (0)