log: Remove trailing and embedded newlines from log messages #36904

Open
maflcko wants to merge 4 commits from 2611-less-trailing-newline into master AGit
maflcko commented 2026-11-17 21:01:00 +00:00 (Migrated from github.com)

The log functions sometimes have a trailing newline character. This is perfectly fine, because that char will be stripped again by the log framework. However, it is still confusing:

So remove them, and also fix a few places to remove embedded newlines.

The log functions sometimes have a trailing newline character. This is perfectly fine, because that char will be stripped again by the log framework. However, it is still confusing: * After https://github.com/bitcoin/bitcoin/pull/35833 *embedded* newlines are escaped and a single trailing one is excluded. It would be clearer to not have a special carve-out here. Also the carve-out may be missing two-or-more trailing newlines. * The trailing newline may incorrectly imply that newlines are supported at all. So remove them, and also fix a few places to remove embedded newlines.
DrahtBot commented 2026-11-17 21:01:11 +00:00 (Migrated from github.com)

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

External sites

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
Concept ACK jeanpablojp, stickies-v

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #37094 (validation: validate assumeutxo snapshots with a single chainstate by fjahr)
  • #37060 (zmq: improve handling of invalid configurations by jlopp)
  • #37038 (coins: store spent dbcache entries compactly by LarryRuane)
  • #36980 (log: mask SENSITIVE rw_settings in LogArgs by enessubass)
  • #36969 (net: Warn only once when a proxy or the I2P proxy is unreachable by fjahr)
  • #36858 (refactor: break the blockstorage/validation circular dependency by pzafonte)
  • #36856 (kernel: add manual pruning by pzafonte)
  • #36820 (refactor: remove more dead code by fanquake)
  • #36738 (refactor: move block writes and pruning into BlockManager by pzafonte)
  • #36540 (mempool: remove time-based transaction expiry by ismaelsadeeq)
  • #36434 (http: support unix sockets by pinheadmz)
  • #36326 (kernel: Use typed errors for fatal and flush error notifications by arejula27)
  • #35998 (wallet: Handle or explicitly ignore WalletBatch write failures by achow101)
  • #35906 (First steps towards a stateless, side-effect free validation library by purpleKarrot)
  • #35902 (zmq: Log bind error at Error level, abort startup on init error by chriszeng1010)
  • #35591 ([DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) by sr-gi)
  • #35355 (Use atomics for determining whether trace logging is enabled by ajtowns)
  • #34778 (logging: rewrite macros to enforce restrictions at compile-time, improve efficiency and usability by ryanofsky)
  • #34534 (rpc: Manual prune lock management (Take 2) by fjahr)
  • #34400 (wallet: parallel fast rescan by Eunovo)
  • #34132 (coins,dbwrapper: make database point-read failures fatal by l0rinc)
  • #34038 (logging: replace -loglevel with -trace, expose trace logging via RPC by ajtowns)
  • #33324 (blocks: add resumable reobfuscation for existing block files by l0rinc)
  • #29256 (log, refactor: Allow log macros to accept context arguments by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

<!--e57a25ab6845829454e8d69fc972939a--> The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. <!--006a51241073e994b41acfe9ec718e94--> ### External sites * Code coverage & benchmarks: https://corecheck.dev/bitcoin/bitcoin/pulls/36904 * Ralph review <img src=https://review.fish.foo/assets/bitcoin/bitcoin/36904.png alt="Ralph review status"> https://git.fish.foo/bitcoin/bitcoin/pulls/36904#author-ralph <!--021abf342d371248e50ceaed478a90ca--> ### Reviews See [the guideline](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#code-review) and [AI policy](https://github.com/bitcoin/bitcoin/blob/master/doc/AI_POLICY.md) for information on the review process. | Type | Reviewers | | ---- | --------- | | Concept ACK | [jeanpablojp](https://github.com/bitcoin/bitcoin/pull/36904#pullrequestreview-6029426663), [stickies-v](https://github.com/bitcoin/bitcoin/pull/36904#issuecomment-7142986835) | If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore. <!--174a7506f384e20aa4161008e828411d--> ### Conflicts Reviewers, this pull request conflicts with the following ones: * [#37094](https://github.com/bitcoin/bitcoin/pull/37094) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/37094.svg"></sub> (validation: validate assumeutxo snapshots with a single chainstate by fjahr) * [#37060](https://github.com/bitcoin/bitcoin/pull/37060) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/37060.svg"></sub> (zmq: improve handling of invalid configurations by jlopp) * [#37038](https://github.com/bitcoin/bitcoin/pull/37038) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/37038.svg"></sub> (coins: store spent dbcache entries compactly by LarryRuane) * [#36980](https://github.com/bitcoin/bitcoin/pull/36980) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36980.svg"></sub> (log: mask SENSITIVE rw_settings in LogArgs by enessubass) * [#36969](https://github.com/bitcoin/bitcoin/pull/36969) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36969.svg"></sub> (net: Warn only once when a proxy or the I2P proxy is unreachable by fjahr) * [#36858](https://github.com/bitcoin/bitcoin/pull/36858) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36858.svg"></sub> (refactor: break the blockstorage/validation circular dependency by pzafonte) * [#36856](https://github.com/bitcoin/bitcoin/pull/36856) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36856.svg"></sub> (kernel: add manual pruning by pzafonte) * [#36820](https://github.com/bitcoin/bitcoin/pull/36820) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36820.svg"></sub> (refactor: remove more dead code by fanquake) * [#36738](https://github.com/bitcoin/bitcoin/pull/36738) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36738.svg"></sub> (refactor: move block writes and pruning into BlockManager by pzafonte) * [#36540](https://github.com/bitcoin/bitcoin/pull/36540) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36540.svg"></sub> (mempool: remove time-based transaction expiry by ismaelsadeeq) * [#36434](https://github.com/bitcoin/bitcoin/pull/36434) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36434.svg"></sub> (http: support unix sockets by pinheadmz) * [#36326](https://github.com/bitcoin/bitcoin/pull/36326) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/36326.svg"></sub> (kernel: Use typed errors for fatal and flush error notifications by arejula27) * [#35998](https://github.com/bitcoin/bitcoin/pull/35998) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35998.svg"></sub> (wallet: Handle or explicitly ignore `WalletBatch` write failures by achow101) * [#35906](https://github.com/bitcoin/bitcoin/pull/35906) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35906.svg"></sub> (First steps towards a stateless, side-effect free validation library by purpleKarrot) * [#35902](https://github.com/bitcoin/bitcoin/pull/35902) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35902.svg"></sub> (zmq: Log bind error at Error level, abort startup on init error by chriszeng1010) * [#35591](https://github.com/bitcoin/bitcoin/pull/35591) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35591.svg"></sub> ([DO NOT MERGE] Erlay: bandwidth-efficient transaction relay protocol (Full implementation) by sr-gi) * [#35355](https://github.com/bitcoin/bitcoin/pull/35355) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/35355.svg"></sub> (Use atomics for determining whether trace logging is enabled by ajtowns) * [#34778](https://github.com/bitcoin/bitcoin/pull/34778) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34778.svg"></sub> (logging: rewrite macros to enforce restrictions at compile-time, improve efficiency and usability by ryanofsky) * [#34534](https://github.com/bitcoin/bitcoin/pull/34534) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34534.svg"></sub> (rpc: Manual prune lock management (Take 2) by fjahr) * [#34400](https://github.com/bitcoin/bitcoin/pull/34400) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34400.svg"></sub> (wallet: parallel fast rescan by Eunovo) * [#34132](https://github.com/bitcoin/bitcoin/pull/34132) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34132.svg"></sub> (coins,dbwrapper: make database point-read failures fatal by l0rinc) * [#34038](https://github.com/bitcoin/bitcoin/pull/34038) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/34038.svg"></sub> (logging: replace -loglevel with -trace, expose trace logging via RPC by ajtowns) * [#33324](https://github.com/bitcoin/bitcoin/pull/33324) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/33324.svg"></sub> (blocks: add resumable reobfuscation for existing block files by l0rinc) * [#29256](https://github.com/bitcoin/bitcoin/pull/29256) <sub><img src="https://drahtbot.space/ack_count/bitcoin/bitcoin/29256.svg"></sub> (log, refactor: Allow log macros to accept context arguments by ryanofsky) If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. <!--5faf32d7da4f0f540f40219e4f7537a3-->
First-time contributor

Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive linked from the Review report for their assessments.

🟠 Minor · Qt transaction debug view loses per-input and per-output line breaks

When a log category is enabled, flattening CTransaction::ToString() makes the Qt transaction-details debug view display the transaction as one wrapped paragraph.

Location: src/primitives/transaction.cpp:124 (head).

🔵 Suggestion · Rewritten CTransaction::ToString() lacks output assertions

Existing tests do not check the rewritten formatter's full txid, counts or input/witness grouping, so they would miss omissions or incorrect field substitutions.

Location: src/primitives/transaction.cpp:118 (head).

Review coverage was incomplete.


Reviewed: fabb68d43103 · Review report · Previous reports

permalink

<!-- forgejo-review-bot:bitcoin/bitcoin --> <!-- ralph-engine:current:312ddb2095238aa2ca395a9cc39b05ab5a38a7177afbdb0d69098df9c3e0bef9:9a7f127b15c6116c267953d38288a9f17ec7c7bcd3a975fb71a2db8bfd974dbf --> <!-- ralph-base:afa492e233868bcf4799bb62943baa28017938f6 --> <!-- ralph-head:fabb68d4310323982ab697a8e3aea788aee346ce --> <!-- ralph-case:0d9402f87d453513192cbe875723af19dd847f30d9fa8368bf286b0d80c71d25 --> Earlier concerns neither republished nor resolved: 2 suggestions. See the Run archive linked from the Review report for their assessments. **🟠 Minor · Qt transaction debug view loses per-input and per-output line breaks** When a log category is enabled, flattening `CTransaction::ToString()` makes the Qt transaction-details debug view display the transaction as one wrapped paragraph. Location: [`src/primitives/transaction.cpp:124`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/fabb68d4310323982ab697a8e3aea788aee346ce/src/primitives/transaction.cpp#L124>) (head). **🔵 Suggestion · Rewritten `CTransaction::ToString()` lacks output assertions** Existing tests do not check the rewritten formatter's full txid, counts or input/witness grouping, so they would miss omissions or incorrect field substitutions. Location: [`src/primitives/transaction.cpp:118`](<https://git.fish.foo/bitcoin/bitcoin/src/commit/fabb68d4310323982ab697a8e3aea788aee346ce/src/primitives/transaction.cpp#L118>) (head). Review coverage was incomplete. <!-- Review tier: standard --> --- Reviewed: [`fabb68d43103`](<https://git.fish.foo/bitcoin/bitcoin/commit/fabb68d4310323982ab697a8e3aea788aee346ce>) · [Review report](<https://review.fish.foo/report/36904-fabb68d4310323982ab697a8e3aea788aee346ce-3390-7.html>) · [Previous reports](<https://review.fish.foo/traces/36904/>) [permalink](<https://review.fish.foo/report/36904-fabb68d4310323982ab697a8e3aea788aee346ce-3390-7.html>)
DrahtBot commented 2026-11-18 10:56:15 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
maflcko commented 2026-11-18 12:49:50 +00:00 (Migrated from github.com)

Ok, went ahead to exclude all reviewed pull requests in the scripted-diff. All remaining conflicts don't have any current review, or are waiting to have their reviews addressed in a push anyway.

Edit: Also pushed a fix to remove the last embedded newlines. Can be tested with something like:

diff --git a/src/logging.cpp b/src/logging.cpp
index f5d184ba33..b2b68ba0c3 100644
--- a/src/logging.cpp
+++ b/src/logging.cpp
@@ -343,2 +343,3 @@ namespace BCLog {
             uint8_t ch = (uint8_t)ch_in;
+ Assert(ch!='\n');
             if (ch >= 32 && ch != '\x7f') {
Ok, went ahead to exclude all reviewed pull requests in the scripted-diff. All remaining conflicts don't have any current review, or are waiting to have their reviews addressed in a push anyway. Edit: Also pushed a fix to remove the last embedded newlines. Can be tested with something like: ```diff diff --git a/src/logging.cpp b/src/logging.cpp index f5d184ba33..b2b68ba0c3 100644 --- a/src/logging.cpp +++ b/src/logging.cpp @@ -343,2 +343,3 @@ namespace BCLog { uint8_t ch = (uint8_t)ch_in; + Assert(ch!='\n'); if (ch >= 32 && ch != '\x7f') {
DrahtBot commented 2026-11-20 22:32:05 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
jeanpablojp (Migrated from github.com) reviewed 2026-11-23 20:59:38 +00:00
jeanpablojp (Migrated from github.com) left a comment

Concept ACK

nit: One log format string still has embedded newlines after the CommitTransaction fix, the LogWarning("\n\n************************\n%s", message) in PrintExceptionContinue, which predates this PR.
In feature_init.py it comes out in debug.log as \x0a\x0a************************\x0aEXCEPTION: ....

Concept ACK nit: One log format string still has embedded newlines after the `CommitTransaction` fix, the `LogWarning("\n\n************************\n%s", message)` in `PrintExceptionContinue`, which predates this PR. In `feature_init.py` it comes out in `debug.log` as `\x0a\x0a************************\x0aEXCEPTION: ...`.
maflcko commented 2026-11-24 10:09:12 +00:00 (Migrated from github.com)

PrintExceptionContinue

Thx, added a fix for that as well. Can be tested via:

diff --git a/src/init.cpp b/src/init.cpp
index 8a7b6d15a2..a592bc76a4 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1544,2 +1544,4 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
     }
+//throw int{};
+throw std::runtime_error{"hi"};
 

and then: bitcoind -printtoconsole=1.

Before: [init] [util/exception.cpp:39] [PrintExceptionContinue] [warning] \x0a\x0a************************\x0aEXCEPTION: St13runtime_error \x0ahi \x0abitcoin in AppInit()

After: [init] [util/exception.cpp:33] [PrintExceptionContinue] [warning] ***** EXCEPTION thread: init, caught at: bitcoind.cpp:246 type: St13runtime_error what: "hi"

> `PrintExceptionContinue` Thx, added a fix for that as well. Can be tested via: ```diff diff --git a/src/init.cpp b/src/init.cpp index 8a7b6d15a2..a592bc76a4 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1544,2 +1544,4 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info) } +//throw int{}; +throw std::runtime_error{"hi"}; ``` and then: `bitcoind -printtoconsole=1`. Before: `[init] [util/exception.cpp:39] [PrintExceptionContinue] [warning] \x0a\x0a************************\x0aEXCEPTION: St13runtime_error \x0ahi \x0abitcoin in AppInit() ` After: `[init] [util/exception.cpp:33] [PrintExceptionContinue] [warning] ***** EXCEPTION thread: init, caught at: bitcoind.cpp:246 type: St13runtime_error what: "hi"`
DrahtBot commented 2026-11-24 16:44:43 +00:00 (Migrated from github.com)

🐙 This pull request conflicts with the target branch and needs rebase.

<!--cf906140f33d8803c4a75a2196329ecb--> 🐙 This pull request conflicts with the target branch and [needs rebase](https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#rebasing-changes).
stickies-v commented 2026-11-24 20:03:44 +00:00 (Migrated from github.com)

Concept ACK

Concept ACK
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
bitcoin/bitcoin!36904
No description provided.