aboutsummaryrefslogtreecommitdiff
path: root/doc
diff options
context:
space:
mode:
authorAva Chow <github@achow101.com>2024-01-10 14:00:09 -0500
committerAva Chow <github@achow101.com>2024-01-10 14:11:32 -0500
commit7ff8e6b24054bd55adbba54e37f87672f4cf544c (patch)
tree50953fdc3d80d4baa63eaaf3a9e9241b7f7777a6 /doc
parent632a2bb731804dffe52bd4cbd90bfee352d25ede (diff)
parente60fc7d5d34f23cccbff6e4f5f3d716fa8dad50c (diff)
downloadbitcoin-7ff8e6b24054bd55adbba54e37f87672f4cf544c.tar.xz
Merge bitcoin/bitcoin#28318: logging: Simplify API for level based logging
e60fc7d5d34f23cccbff6e4f5f3d716fa8dad50c logging: Replace uses of LogPrintfCategory (Anthony Towns) f7ce5ac08c669ac763e275bb7c82dcfb2b1b6c33 logging: add LogError, LogWarning, LogInfo, LogDebug, LogTrace (Anthony Towns) fbd7642c8e5b70327e019382320f5ef0a651ecc5 logging: add -loglevelalways=1 option (Anthony Towns) 782bb6a05663ad7a53908e910d0f42b49b881e09 logging: treat BCLog::ALL like BCLog::NONE (Anthony Towns) 667ce3e3297645527b07314e1d5a82275fb25845 logging: Drop BCLog::Level::None (Anthony Towns) ab34dc6012351e7b8aab871dd9d2b38ade1cd9bc logging: Log Info messages unconditionally (Anthony Towns) dfe98b6874da04e45f68d17575c1e8a5431ca9bc logging: make [cat:debug] and [info] implicit (Anthony Towns) c5c76dc615677d226c9f6b3f2b66d833315d40da logging: refactor: pull prefix code out (Anthony Towns) Pull request description: Replace `LogPrint*` functions with severity based logging functions: * `LogInfo(...)`, `LogWarning(...)`, `LogError(...)` for unconditional (uncategorised) logging (replaces `LogPrintf`) * `LogDebug(CATEGORY, ...)` and `LogTrace(CATEGORY, ...)` for conditional logging (replaces `LogPrint`) * `LogPrintLevel(CATEGORY, LEVEL, ...)` for when the level isn't known in advance, or a category needs to be added for an info/warning/error log message (mostly unchanged, but rarely needed) Logs look roughly as they do now with `LogInfo` not having an `[info]` prefix, and `LogDebug` having a `[cat]` prefix, rather than a `[cat:debug]` prefix. This removes `BCLog::Level::None` entirely -- for `LogFlags::NONE` just use `Level::Info`, for any actual category, use `Level::Debug`. Adds docs to developer-notes about when to use which level. Adds `-loglevelalways=1` option so that you get `[net:debug]`, `[all:info]`, `[all:warning]` etc, which might be helpful for automated parsing, or just if you like everything to be consistent. Defaults to off to reduce noise in the default config, and to avoid unnecessary changes on upgrades. Changes the behaviour of `LogPrintLevel(CATEGORY, BCLog::Level::Info, ...)` to be logged unconditionally, rather than only being an additional optional logging level in addition to trace and debug. Does not change the behaviour of `LogPrintLevel(NONE, Debug, ...)` and `LogPrintLevel(NONE, Trace, ...)` being no-ops. ACKs for top commit: maflcko: re-ACK e60fc7d5d34f23cccbff6e4f5f3d716fa8dad50c 🌚 achow101: ACK e60fc7d5d34f23cccbff6e4f5f3d716fa8dad50c stickies-v: ACK e60fc7d5d34f23cccbff6e4f5f3d716fa8dad50c jamesob: ACK e60fc7d5d34f23cccbff6e4f5f3d716fa8dad50c ([`jamesob/ackr/28318.1.ajtowns.logging_simplify_api_for`](https://github.com/jamesob/bitcoin/tree/ackr/28318.1.ajtowns.logging_simplify_api_for)) Tree-SHA512: e7a4588779b148242495b7b6f64198a00c314cd57100affab11c43e9d39c9bbf85118ee2002792087fdcffdea08c84576e20844b3079f27083e26ddd7ca15d7f
Diffstat (limited to 'doc')
-rw-r--r--doc/developer-notes.md45
1 files changed, 43 insertions, 2 deletions
diff --git a/doc/developer-notes.md b/doc/developer-notes.md
index 00a3b2ea6d..1d670d39f1 100644
--- a/doc/developer-notes.md
+++ b/doc/developer-notes.md
@@ -725,6 +725,47 @@ General Bitcoin Core
- *Explanation*: If the test suite is to be updated for a change, this has to
be done first.
+Logging
+-------
+
+The macros `LogInfo`, `LogDebug`, `LogTrace`, `LogWarning` and `LogError` are available for
+logging messages. They should be used as follows:
+
+- `LogDebug(BCLog::CATEGORY, fmt, params...)` is what you want
+ most of the time, and it should be used for log messages that are
+ useful for debugging and can reasonably be enabled on a production
+ system (that has sufficient free storage space). They will be logged
+ if the program is started with `-debug=category` or `-debug=1`.
+ Note that `LogPrint(BCLog::CATEGORY, fmt, params...)` is a deprecated
+ alias for `LogDebug`.
+
+- `LogInfo(fmt, params...)` should only be used rarely, eg for startup
+ messages or for infrequent and important events such as a new block tip
+ being found or a new outbound connection being made. These log messages
+ are unconditional so care must be taken that they can't be used by an
+ attacker to fill up storage. Note that `LogPrintf(fmt, params...)` is
+ a deprecated alias for `LogInfo`.
+
+- `LogError(fmt, params...)` should be used in place of `LogInfo` for
+ severe problems that require the node (or a subsystem) to shut down
+ entirely (eg, insufficient storage space).
+
+- `LogWarning(fmt, params...)` should be used in place of `LogInfo` for
+ severe problems that the node admin should address, but are not
+ severe enough to warrant shutting down the node (eg, system time
+ appears to be wrong, unknown soft fork appears to have activated).
+
+- `LogTrace(BCLog::CATEGORY, fmt, params...) should be used in place of
+ `LogDebug` for log messages that would be unusable on a production
+ system, eg due to being too noisy in normal use, or too resource
+ intensive to process. These will be logged if the startup
+ options `-debug=category -loglevel=category:trace` or `-debug=1
+ -loglevel=trace` are selected.
+
+Note that the format strings and parameters of `LogDebug` and `LogTrace`
+are only evaluated if the logging category is enabled, so you must be
+careful to avoid side-effects in those expressions.
+
Wallet
-------
@@ -887,7 +928,7 @@ Strings and formatting
`wcstoll`, `wcstombs`, `wcstoul`, `wcstoull`, `wcstoumax`, `wcswidth`,
`wcsxfrm`, `wctob`, `wctomb`, `wctrans`, `wctype`, `wcwidth`, `wprintf`
-- For `strprintf`, `LogPrint`, `LogPrintf` formatting characters don't need size specifiers.
+- For `strprintf`, `LogInfo`, `LogDebug`, etc formatting characters don't need size specifiers.
- *Rationale*: Bitcoin Core uses tinyformat, which is type safe. Leave them out to avoid confusion.
@@ -899,7 +940,7 @@ Strings and formatting
- *Rationale*: Although this is guaranteed to be safe starting with C++11, `.data()` communicates the intent better.
- - Do not use it when passing strings to `tfm::format`, `strprintf`, `LogPrint[f]`.
+ - Do not use it when passing strings to `tfm::format`, `strprintf`, `LogInfo`, `LogDebug`, etc.
- *Rationale*: This is redundant. Tinyformat handles strings.