Commit graph

71 commits

Author SHA1 Message Date
Anthony Towns
b4dd7ab43e logging: use std::string_view 2024-07-19 15:44:38 +10:00
Anthony Towns
558df5c733 logging: Apply formatting to early log messages
The formatting of log messages isn't defined until StartLogging() is
called; so can't be correctly applied to early log messages from prior
to that call. Instead of saving the output log message, save the inputs
to the logging invocation (including time, mocktime and thread name),
and format those inputs into a log message when StartLogging() is called.
2024-07-19 12:56:15 +10:00
Anthony Towns
6cf9b34440 logging: Limit early logging buffer
Log messages created prior to StartLogging() being called go into a
buffer. Enforce a limit on the size of this buffer.
2024-07-19 12:41:28 +10:00
Anthony Towns
0b1960f1b2 logging: Add DisableLogging() 2024-07-12 10:30:39 +10:00
Anthony Towns
6bbc2dd6c5 logging: Add thread safety annotations 2024-07-04 01:52:26 +10:00
Ryan Ofsky
4f74c59334 util: Move util/string.h functions to util namespace
There are no changes to behavior. Changes in this commit are all additions, and
are easiest to review using "git diff -U0 --word-diff-regex=." options.

Motivation for this change is to keep util functions with really generic names
like "Split" and "Join" out of the global namespace so it is easier to see
where these functions are defined, and so they don't interfere with function
overloading, especially since the util library is a dependency of the kernel
library and intended to be used with external code.
2024-05-16 10:16:08 -05:00
Ryan Ofsky
3b987d03a4
Merge bitcoin/bitcoin#29419: log: deduplicate category names and improve logging.cpp
b0344c219a logging: remove unused BCLog::UTIL (Vasil Dimov)
d3b3af9034 log: deduplicate category names and improve logging.cpp (Vasil Dimov)

Pull request description:

  The code in `logging.cpp` needs to:
  * Get the category name given the flag (e.g. `BCLog::PRUNE` -> `"prune"`)
  * Get the flag given the category name (e.g. `"prune"` -> `BCLog::PRUNE`)
  * Get the list of category names sorted in alphabetical order

  Achieve this by using the proper std containers. The result is
  * less code (the diff of the first commit is +62 / -129)
  * faster code (to linear search and no copy+sort)
  * more maintainable code (the categories are no longer duplicated in `LogCategories[]` and `LogCategoryToStr()`)

  This behavior is preserved:
  `BCLog::NONE` -> `""` (lookup by `LogCategoryToStr()`)
  `""` -> `BCLog::ALL` (lookup by `GetLogCategory("")`)

  ---

  Also remove unused `BCLog::UTIL`.

  ---

  These changes (modulo the `BCLog::UTIL` removal) are part of https://github.com/bitcoin/bitcoin/pull/29415 but they make sense on their own and would be good to have them, regardless of the fate of https://github.com/bitcoin/bitcoin/pull/29415. Also, if this is merged, that would reduce the size of https://github.com/bitcoin/bitcoin/pull/29415, thus the current standalone PR.

ACKs for top commit:
  davidgumberg:
    crACK b0344c219a
  pinheadmz:
    ACK b0344c219a
  ryanofsky:
    Code review ACK b0344c219a. Nice cleanup! Having to maintain multiple copies of the same mapping seemed messy and a like a possible footgun. I checked old and new mappings in both directions and confirmed no behavior should be changing.

Tree-SHA512: 57f87a090932f9b33dc8e075d1855dba9b71a3243a0758511745483dec2d9c46d3b532eadab297e78164c9b7caba370986ee380696a45f0778a841082f8e21a7
2024-04-02 10:47:05 -04:00
Fabian Jahr
d0e6564240
log: Remove error() reference 2024-03-12 16:26:15 +01:00
MarcoFalke
fa39151394
refactor: Remove unused error() 2024-03-11 13:49:51 +01:00
MarcoFalke
fa808fb749
refactor: Make error() return type void
This is needed for the next commit to compile.
2024-03-11 13:49:35 +01:00
Vasil Dimov
b0344c219a
logging: remove unused BCLog::UTIL
Suggested by: David Gumberg (https://github.com/bitcoin/bitcoin/pull/29415#discussion_r1485310634)
2024-02-11 15:25:07 +01:00
Anthony Towns
f7ce5ac08c logging: add LogError, LogWarning, LogInfo, LogDebug, LogTrace
These provide simple and clear ways to write the most common logging
operations:

    LogInfo("msg");
    LogDebug(BCLog::LogFlags::NET, "msg");

    LogError("msg");
    LogWarning("msg");
    LogTrace(BCLog::LogFlags::NET, "msg");

For cases where the level cannot be hardcoded, LogPrintLevel(category,
level, ...) remains available.
2023-12-20 15:59:48 +10:00
Anthony Towns
fbd7642c8e logging: add -loglevelalways=1 option
This option tells the logging system to always include a "[cat:level]"
prefix, so [net] becomes [net:debug], LogInfo/LogPrint statements will have
an [all:info] prefix, and LogWarning and LogError logs will become
[all:warning] and [all:error]. This may be easier for automated parsing
of logs, particularly if additional prefixes such as thread or source
location are enabled.
2023-12-15 11:03:25 +10:00
Anthony Towns
667ce3e329 logging: Drop BCLog::Level::None
Now that Info-level logging is always logged, there is no further
need for the "None" level, so remove it.
2023-12-15 11:03:25 +10:00
Anthony Towns
c5c76dc615 logging: refactor: pull prefix code out 2023-12-15 11:03:22 +10:00
glozow
51b3275cd1 [log] add category TXPACKAGES for orphanage and package relay 2023-08-29 16:41:22 +01:00
Jon Atack
daa5a658c0 refactor: rename BCLog::BLOCKSTORE to BLOCKSTORAGE
so the enum name is the same as its value, like the other BCLog enums.
2023-06-15 10:27:56 -06:00
TheCharlatan
00e9b97f37
refactor: Move fs.* to util/fs.*
The fs.* files are already part of the libbitcoin_util library. With the
introduction of the fs_helpers.* it makes sense to move fs.* into the
util/ directory as well.
2023-03-23 12:55:18 +01:00
Ben Woosley
aaced5633b
refactor: Move error() from util/system.h to logging.h
error is a low-level function with a sole dependency on LogPrintf, which
is defined in logging.h

The background of this commit is an ongoing effort to decouple the
libbitcoinkernel library from the ArgsManager defined in system.h.
Moving the function out of system.h allows including it from a separate
source file without including the ArgsManager definitions from system.h.
2023-03-13 17:09:54 +01:00
Hennadii Stepanov
306ccd4927
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
- 2021: f47dda2c58
- 2020: fa0074e2d8
- 2019: aaaaad6ac9
2022-12-24 23:49:50 +00:00
Sebastian Falbesoner
3449880b49 wallet: fast rescan: show log message for every non-skipped block
For that purpose, a new logging category BCLog::SCAN is introduced.
2022-10-25 15:57:38 +02:00
Gleb Naumenko
24e36fac0a log: Add tx reconciliation log category 2022-10-17 12:00:59 +03:00
Jon Atack
45f9282162 Create BCLog::Level::Trace log severity level
for verbose log messages for development or debugging only, as bitcoind may run
more slowly, that are more granular/frequent than the Debug log level, i.e. for
very high-frequency, low-level messages to be logged distinctly from
higher-level, less-frequent debug logging that could still be usable in production.

An example would be to log higher-level peer events (connection, disconnection,
misbehavior, eviction) as Debug, versus Trace for low-level, high-volume p2p
messages in the BCLog::NET category. This will enable the user to log only the
former without the latter, in order to focus on high-level peer management events.

With respect to the name, "trace" is suggested as the most granular level
in resources like the following:
- https://sematext.com/blog/logging-levels
- https://howtodoinjava.com/log4j2/logging-levels

Update the test framework and add test coverage.
2022-08-20 11:55:17 +02:00
klementtan
eb7bee5f84 Create -loglevel configuration option
- add a -loglevel=<level>|<category:level> config option to allow users
  to set a global -loglevel and category-specific log levels. LogPrintLevel
  messages with a higher severity level than -loglevel will not be printed
  in the debug log.

- for now, this config option is debug-only during the migration to
  severity-based logging

- update unit and functional tests

Co-authored-by: "Jon Atack <jon@atack.com>"
2022-08-20 11:53:37 +02:00
klementtan
9c7507bf76 Create BCLog::Logger::LogLevelsString() helper function
Co-authored-by: "Jon Atack <jon@atack.com>"
2022-08-20 11:31:28 +02:00
klementtan
8fe3457dbb Update LogAcceptCategory() and unit tests with log severity levels
Co-authored-by: "Jon Atack <jon@atack.com>"
2022-08-20 11:30:51 +02:00
klementtan
c2797cfc60 Add BCLog::Logger::SetLogLevel()/SetCategoryLogLevel() for string inputs
and remove unnecessary param constness in LogPrintStr()

Co-authored-by: jonatack <jon@atack.com>
2022-08-20 11:30:50 +02:00
Jon Atack
f6c0cc0350 Add BCLog::Logger::m_category_log_levels data member and getter/setter
Co-authored-by: "klementtan <klementtan@gmail.com>"
2022-08-20 11:30:50 +02:00
Jon Atack
2978b387bf Add BCLog::Logger::m_log_level data member and getter/setter
Co-authored-by: "klementtan <klementtan@gmail.com>"
2022-08-20 11:30:35 +02:00
Jon Atack
f1379aeca9 Simplify BCLog::Level enum class and LogLevelToStr() function
- simplify the BCLog::Level enum class (and future changes to it) by
  only setting the value of the first enumerator

- move the BCLog::Level:None enumerator to the end of the BCLog::Level
  enum class and LogLevelToStr() member function, as the None enumerator
  is only used internally, and by being the highest BCLog::Level value it
  can be used to iterate over the enumerators

- replace the unused BCLog::Level:None string "none" with an empty string
  as the case will never be hit

- add documentation
2022-08-18 16:32:43 +02:00
Jon Atack
eb8aab759f logging: add LogPrintfCategory to log unconditionally with category
prefixing the output with the passed category name.

- add documentation
- add a unit test
- update lint-logs.py
- update lint-format-strings.py
2022-06-08 14:02:54 +02:00
laanwj
c4e7717727 refactor: Change LogPrintLevel order to category, severity
This is more consistent with the other functions, as well as with the
logging output itself. If we want to make this change, we should do it
before it's all over the place.
2022-05-25 11:31:58 +02:00
laanwj
bd971bffb0 logging: Unconditionally log levels >= WARN
Messages with level `WARN` or higher should be logged even when
the category is not provided with `-debug=`, to make sure important
warnings are not lost.
2022-05-25 11:26:15 +02:00
klementtan
a8290649a6
logging: Add severity level to logs. 2022-05-19 21:05:35 +08:00
Jon Atack
39a34b6877
Put lock logging behind DEBUG_LOCKCONTENTION preprocessor directive 2022-04-05 12:49:48 +02:00
Kiminuo
41d7166c8a
refactor: replace boost::filesystem with std::filesystem
Warning: Replacing fs::system_complete calls with fs::absolute calls
in this commit may cause minor changes in behaviour because fs::absolute
no longer strips trailing slashes; however these changes are believed to
be safe.

Co-authored-by: Russell Yanofsky <russ@yanofsky.org>
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
2022-02-03 18:35:52 +08:00
Hennadii Stepanov
f47dda2c58
scripted-diff: Bump copyright headers
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-

Commits of previous years:
* 2020: fa0074e2d8
* 2019: aaaaad6ac9
2021-12-30 19:36:57 +02:00
Anthony Towns
31b2b802b5 blockstorage: use debug log category 2021-10-11 21:45:49 +10:00
practicalswift
4747da3a5b Add syscall sandboxing (seccomp-bpf) 2021-10-01 13:51:10 +00:00
Jon Atack
b7a17444e0
log, sync: add LOCK logging category, apply it to lock contention 2021-08-18 19:57:15 +02:00
Jon Atack
7c57297319
log: sort LogCategoriesList and LogCategoriesString alphabetically 2021-07-22 23:09:42 +02:00
Russell Yanofsky
10afdf0280 multiprocess: Add Ipc interface implementation 2021-04-23 03:02:50 -05:00
Vasil Dimov
c22daa2ecf
net: implement the necessary parts of the I2P SAM protocol
Implement the following commands from the I2P SAM protocol:

* HELLO: needed for all of the remaining ones
* DEST GENERATE: to generate our private key and destination
* NAMING LOOKUP: to convert .i2p addresses to destinations
* SESSION CREATE: needed for STREAM CONNECT and STREAM ACCEPT
* STREAM CONNECT: to make outgoing connections
* STREAM ACCEPT: to accept incoming connections
2021-03-01 18:19:37 +01:00
practicalswift
b4511e2e2e log: Prefix log messages with function name if -logsourcelocations is set 2021-01-15 09:57:32 +00:00
practicalswift
1c65c075ee Don't declare de facto const member functions as non-const 2020-12-06 18:44:25 +00:00
Hennadii Stepanov
dfb75ae49d
refactor: Rename LockGuard to StdLockGuard for consistency with StdMutex 2020-05-28 09:54:24 +03:00
Hennadii Stepanov
79be487420
Add thread safety annotated wrapper for std::mutex
Co-authored-by: Anthony Towns <aj@erisian.com.au>
2020-05-28 09:54:09 +03:00
Anthony Towns
5478d6c099 logging: thread safety annotations
Adds LockGuard helper in threadsafety.h to replace lock_guard<mutex>
when LOCK(Mutex) isn't available for use.
2020-05-27 01:31:51 +10:00
MarcoFalke
faec063887
log: Use Join() helper when listing log categories 2020-04-16 11:08:46 -04:00
MarcoFalke
e09c701e01 scripted-diff: Bump copyright of files changed in 2020
-BEGIN VERIFY SCRIPT-
./contrib/devtools/copyright_header.py update ./
-END VERIFY SCRIPT-
2020-01-15 02:18:00 +07:00