-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Smarter default behavior for -printtoconsole #12689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Concept ACK. Tested on macOS. Needs update for |
src/util.cpp
Outdated
|
|
||
| bool IsStdoutTty() | ||
| { | ||
| return isatty(STDOUT_FILENO); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know you said that MingW includes a compatible unistd.h version for Windows but on Visual Studio/msvc isatty is deprecated and replaced by _isatty. Also STDOUT_FILENO (1) is not defined. There's currently some PRs for msvc support so just a heads up that this will likely break things there. #11526 and #11873
|
Strong concept ACK. Very nice usability improvement! I'm also running What about reducing the number of |
|
Just a few concerns (Mainly on Windows)
BTW fPrintToDebugLog is set to true and not changed ever so the code can be simplified. |
|
Concept ACK, cool 👍. |
|
Now that I've thought about this more I don't think the # stdout is a pipe, not a TTY.
bitcoind | less
# stdout is a file, not a TTY.
bitcoind > redundantcopyofdebug.logI don't think either of these are things people are going to actually run, but if they did they would probably expect to see output printed. The usual use of |
|
New version (with squashed commit) removes the |
|
My understanding is now logging will not be sent to the log file unless -daemon is passed via command line. If that's the case won't this be unexpected and annoying behavior? LogPrintStr only prints to one or the other. I'm on the phone so it's difficult to check |
|
Not sure this makes sense. I don't know of any other software that guesses stdout vs log based on whether stdout is a tty. It seems likely to break users who do Why not just put |
|
@lukejr The code no longer uses We should probably change the |
|
@donaloconnor I also just noticed that which I think is bad behavior. Updated to make these flags independent (printing to console will not affect logging to debug.log). |
|
utACK 23bc0aa |
src/util.cpp
Outdated
| fflush(stdout); | ||
| } | ||
| else if (fPrintToDebugLog) | ||
| if (fPrintToDebugLog) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with making these non-exclusive, however we still need a way to disable logging to debug.log. Some logging setups (e.g. when using systemd) process the -printtoconsole output, and don't need a duplicate logging to disk.
Maybe -nodebuglogfile?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe -debuglogfile=0 as a special case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about -debuglogfile=/dev/null as a special case .-)
If we are to add a separate option, then perhaps something starting with -disable to make it consistent with -disablewallet? We don't have any bitcoind command-line options starting with -no AFAIK.
Also -nodebuglogfile can be parsed as "node bug logfile" :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| // Add newlines to the logfile to distinguish this execution from the last | ||
| // one; called before console logging is set up, so this is only sent to | ||
| // debug.log. | ||
| LogPrintf("\n\n\n\n\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
std::string(NUMBER_OF_BLANK_LINES_BETWEEN_SESSIONS_IN_LOG_TO_PREEMPT_BIKESHEDDING, '\n')? :-P
src/util.cpp
Outdated
| fflush(stdout); | ||
| } | ||
| else if (fPrintToDebugLog) | ||
| if (fPrintToDebugLog) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: move brackets to same line?
|
I could not resist the temptation to add Interestingly, before this change One question I have about this change: I was originally going to update the |
|
I tested and you actually can use a named pipe, because the operation that's failing is a file size check in boost. But you can't use other special files, e.g. # this is allowed
$ echo foo > /dev/zero
# yep, it worked
$ echo $?
0
# this fails
$ ./src/bitcoind -debuglogfile=/dev/zero
************************
EXCEPTION: N5boost10filesystem16filesystem_errorE
boost::filesystem::file_size: Operation not permitted: "/dev/zero"
bitcoin in AppInit() Something to fix another day I guess. |
Right, what bothered me about /dev/null is that it's OS-specific. I don't think providing arbitrary device files as debug log files (such as |
|
I spent way longer on this than I'd like to admit, due to strange behavior in the Bitcoin option parser. There's a little-known feature in the option parser where Nope, doesn't work. I digged in and here's where it gets really weird. The option parser uses Here's where it gets kind of weird. We had a test in class ResendWalletTransactionsTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
self.extra_args = [['--walletbroadcast=false']]So what happens when the option parser sees this... is it calls Since there's a test case in Bitcoin that was using a "false" flag, I think it's possible that there are other people in the wild relying on this behavior. So now the option parser treasts only I also made it so if you use A lot yak shaving, but it makes the option parser more robust so probably worth it. ** Technically this means that |
|
Actually it looks like I can add C++ test for the option parser, I'm going to put up another commit adding that. |
|
|
|
Interesting, that's not documented in the man pages on my system, but cppreference.com agrees that it must return 0 in such a case. |
|
utACK - looks good |
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test/functional/feature_logging.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In commit "stop printing to console in test runner"
This change looks like it should go in the previous commit ("Enable -printtoconsole by default if bitcoind is not a daemon").
|
utACK 60086ad871cb1a756c152a3d3e19fcea52660123. I think that commit can be squashed with the previous. |
2bbe9ff to
7cbf03d
Compare
This is meant to be an intermediate commit to prove that the next does not introduce any changes in the semantics of boolean option parsing.
This commit adds tracking for negated arguments. This change will be used in a future commit that allows disabling the debug.log file using -nodebuglogfile.
Printing to the debug log file can be disabled with -nodebulogfile
f7683cb Track negated arguments in the argument paser. (Evan Klitzke) 4f872b2 Add additional tests for GetBoolArg() (Evan Klitzke) Pull request description: This change explicitly enable tracking negated options in the option parser. A negated option is one passed with a `-no` prefix. For example, `-nofoo` is the negated form of `-foo`. Negated options were originally added in the 0.6 release. The change here allows code to explicitly distinguish between cases like `-nofoo` and `-foo=0`, which was not possible previously. The option parser does not have any changed semantics as a result of this change, and existing code will parse options just as it did before. The motivation for this change is to provide a way to disable options that are otherwise not boolean options. For example, the `-debuglogfile` option is normally interpreted as a string, where the value is the log file name. With this change a user can pass in `-nodebuglogfile` and the code can see that it was explicitly negated, and use that to disable the log file. This change originally split out from #12689. Tree-SHA512: cd5a7354eb03d2d402863c7b69e512cad382781d9b8f18c1ab104fc46d45a712530818d665203082da39572c8a42313c5be09306dc2a7227cdedb20ef7314823
|
Needs rebase to get rid of the already-merged diff. |
|
Marked "up for grabs" |
|
./contrib/devtools/clang-format-diff.py:74:1: F401 'string' imported but unused |
ryanofsky
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
6a3b0d3 Print to console by default when not run with -daemon (Evan Klitzke) Pull request description: Cherry-picked ef6fa1c from the "up for grabs" PR: "Smarter default behavior for -printtoconsole" (#12689). See previous review in #12689. Tree-SHA512: 8923a89b9c8973286d53e960d3c464b1cd026cd5a5911ba62f9f972c83684417dc4004101815dfe987fc1e1baaec1fdd90748a0866bb5548e974d77b3135d43b
f7683cb Track negated arguments in the argument paser. (Evan Klitzke) 4f872b2 Add additional tests for GetBoolArg() (Evan Klitzke) Pull request description: This change explicitly enable tracking negated options in the option parser. A negated option is one passed with a `-no` prefix. For example, `-nofoo` is the negated form of `-foo`. Negated options were originally added in the 0.6 release. The change here allows code to explicitly distinguish between cases like `-nofoo` and `-foo=0`, which was not possible previously. The option parser does not have any changed semantics as a result of this change, and existing code will parse options just as it did before. The motivation for this change is to provide a way to disable options that are otherwise not boolean options. For example, the `-debuglogfile` option is normally interpreted as a string, where the value is the log file name. With this change a user can pass in `-nodebuglogfile` and the code can see that it was explicitly negated, and use that to disable the log file. This change originally split out from bitcoin#12689. Tree-SHA512: cd5a7354eb03d2d402863c7b69e512cad382781d9b8f18c1ab104fc46d45a712530818d665203082da39572c8a42313c5be09306dc2a7227cdedb20ef7314823
…aemon 6a3b0d3 Print to console by default when not run with -daemon (Evan Klitzke) Pull request description: Cherry-picked ef6fa1c from the "up for grabs" PR: "Smarter default behavior for -printtoconsole" (bitcoin#12689). See previous review in bitcoin#12689. Tree-SHA512: 8923a89b9c8973286d53e960d3c464b1cd026cd5a5911ba62f9f972c83684417dc4004101815dfe987fc1e1baaec1fdd90748a0866bb5548e974d77b3135d43b
…aemon 6a3b0d3 Print to console by default when not run with -daemon (Evan Klitzke) Pull request description: Cherry-picked ef6fa1c from the "up for grabs" PR: "Smarter default behavior for -printtoconsole" (bitcoin#12689). See previous review in bitcoin#12689. Tree-SHA512: 8923a89b9c8973286d53e960d3c464b1cd026cd5a5911ba62f9f972c83684417dc4004101815dfe987fc1e1baaec1fdd90748a0866bb5548e974d77b3135d43b
f7683cb Track negated arguments in the argument paser. (Evan Klitzke) 4f872b2 Add additional tests for GetBoolArg() (Evan Klitzke) Pull request description: This change explicitly enable tracking negated options in the option parser. A negated option is one passed with a `-no` prefix. For example, `-nofoo` is the negated form of `-foo`. Negated options were originally added in the 0.6 release. The change here allows code to explicitly distinguish between cases like `-nofoo` and `-foo=0`, which was not possible previously. The option parser does not have any changed semantics as a result of this change, and existing code will parse options just as it did before. The motivation for this change is to provide a way to disable options that are otherwise not boolean options. For example, the `-debuglogfile` option is normally interpreted as a string, where the value is the log file name. With this change a user can pass in `-nodebuglogfile` and the code can see that it was explicitly negated, and use that to disable the log file. This change originally split out from bitcoin#12689. Tree-SHA512: cd5a7354eb03d2d402863c7b69e512cad382781d9b8f18c1ab104fc46d45a712530818d665203082da39572c8a42313c5be09306dc2a7227cdedb20ef7314823
This makes console printing smarter when
-printtoconsoleis not explicitly set. The new behavior:debug.log, never to stdout.The motivation for this change is that I almost always run bitcoind in foreground mode when I'm debugging or doing development work, and the new behavior makes checking log statements a lot easier in that situation. I think these semantics are also more similar to the default behavior of many other Unix programs.