Add -logdir option to control where debug.log lives #11741

pull eklitzke wants to merge 1 commits into bitcoin:master from eklitzke:logdir changing 2 files +15 −1
  1. eklitzke commented at 10:05 PM on November 20, 2017: contributor

    I would like bitcoind to put its log file in /var/log/bitcoin. This PR adds a new -logdir option that controls where the debug.log file is put.

    Note: This flag affects bitcoind and bitcoin-qt. There appears to be a db.log file that is used for wallets, but I didn't update that code path. It would be a minor change to update that as well.

  2. add -logdir option 7832efab36
  3. fanquake added the label Docs and Output on Nov 20, 2017
  4. meshcollider commented at 10:44 PM on November 20, 2017: contributor

    Concept ACK If only one file moves, I'd prefer just -log rather than logdir though

  5. in src/util.cpp:198 in 7832efab36
     193 | +static fs::path GetLogDir()
     194 | +{
     195 | +  if (gArgs.IsArgSet("-logdir")) {
     196 | +    fs::path logdirPath = fs::system_complete(gArgs.GetArg("-logdir", ""));
     197 | +    if (!logdirPath.empty()) {
     198 | +      fs::create_directories(logdirPath);
    


    jonasschnelli commented at 10:51 PM on November 20, 2017:

    Not sure if it should create directories,.. though if it does, in case the creation failed, it should not return an empty path, should rather return GetDataDir() in any failed case.


    eklitzke commented at 11:51 PM on November 20, 2017:

    I don't think the code (as written) can return an empty path. If -logdir is unset the outer if statement is skipped completely, the inner if statement is to handle the case where -logdir is set to the empty string. As I understand the boost::filesystem docs, if the mkdir fails then fs::create_directories will actually throw an exception.

    I'm OK with removing the fs::create_directories call, the precedent I was following is that GetDataDir() creates its directory, although that's a bit different.


    jonasschnelli commented at 12:04 AM on November 21, 2017:

    Hmm.. not sure. I just found this in the docs: Returns: true if a new directory was created, otherwise false.


    eklitzke commented at 4:18 AM on November 21, 2017:

    As I understand the documentation: fs::create_directories returns true if it actually had to issue a mkdir(2) call, and returns false if it did not (because the directory already existed). If the directory needs to be created and the underlying mkdir(2) call failed, then an exception is raised.


    jonasschnelli commented at 6:10 AM on November 21, 2017:

    Oh.. yes.. your completely right. Nevermind then.

  6. eklitzke commented at 11:55 PM on November 20, 2017: contributor

    @MeshCollider Do you think it's possible there would be other log files in the future? I'm interested in the future on working on a multi-process architecture for bitcoind, so that parts of the process could be sandboxed on Linux using seccomp(). In that world I'd want a log directory so there could be a log file per process, but maybe I'm overthinking things since there's just one log file today.

  7. promag commented at 12:00 AM on November 21, 2017: member

    Running regtest and testnet will use the same log file?

  8. eklitzke commented at 4:19 AM on November 21, 2017: contributor

    @promag Can you explain further? That may be the case, but I am somewhat new and don't understand the issue you're describing.

  9. jonasschnelli commented at 6:12 AM on November 21, 2017: contributor

    @eklitzke. I think what @promag means is, that in the default configuration (without the PR), the debug.log file is placed in <datadir>/testnet/ or <datadir>/regtest/ in case of testnet / regtest. Your logdir command would required one to switch the logdir when switching to -regtest, etc. Not sure if it's a real problem...

  10. laanwj commented at 7:34 AM on November 21, 2017: member

    If only one file moves, I'd prefer just -log rather than logdir though

    Would prefer just -logfile or such too. The log is just a text file, it needs to claim no environment, and a directory is not a good abstraction for it. If someone wants bitcoin to log to an existing directory with other log files e.g. /var/log/bitcoinlog that should be possible. The only requirement is write access.

    so that parts of the process could be sandboxed on Linux using seccomp().

    FWIW in my experiments with running bitcoin with CloudABI I've used -printtoconsole to log to a stream instead. This is much easier in restricted environments, and the stream can be processed and stored anywhere desired by an external process. I usually recommend that for more advanced logging setups.

    Do you think it's possible there would be other log files in the future?

    Possible - maybe an auditing / RPC log instead of a debug log. However there is no reason it'd need to be in the same directory, this could have a new option to place it.

    There appears to be a db.log file that is used for wallets, but I didn't update that code path. It would be a minor change to update that as well.

    db.log belongs with the wallet directory, no need to touch it here.

  11. promag commented at 3:37 PM on November 21, 2017: member

    it needs to claim no environment @laanwj what do you mean? Currently there is debug.log, testnet3/debug.log and regtest/debug.log.

  12. laanwj commented at 3:47 PM on November 21, 2017: member

    @laanwj what do you mean? Currently there is debug.log, testnet3/debug.log and regtest/debug.log.

    Yes, the regtest/testnet edge case again. It really sucks that we have these configuration options shared between networks. It's not clear that users even want that layout when they manually specify the logfile! A similar issue to #11726. If we can get per-network configuration in (e.g. #10996) then most of this nonsense will go away.

  13. ajtowns commented at 3:43 AM on November 23, 2017: member

    I'm not sure per-network configuration gets the nonsense to go away :( There's three ways that it could work, I think:

    • logs always go in -logdir, if you start a regtest/testnet instance having specified it in bitcoin.conf, your logs get messy, you get told to RTFM, and cry bitter tears
    • if specified in bitcoin.conf, logdir only affects mainnet; but you can specify logdir via network.conf to choose different locations. (or logdir in bitcoin.conf is an error/ignored)
    • -logdir only has an effect on mainnet, you have to use -regtest-logdir or -testnet-logdir or similar to have debug.log go elsewhere

    I think the last one seems like it might be the least surprising behaviour? I've got some draft patches for both the latter options though.

  14. meshcollider commented at 10:47 AM on November 23, 2017: contributor

    @ajtowns I definitely prefer the first or second of those 3 options, I don't want to see a -regtest-logdir and -testnet-logdir argument as well, I think that's much too messy. Alternatively if we stick with -logdir instead of -logfile, we just call the log chain.log e.g. regtest.log, testnet3.log

  15. laanwj commented at 9:09 AM on November 28, 2017: member

    logs always go in -logdir, if you start a regtest/testnet instance having specified it in bitcoin.conf, your logs get messy, you get told to RTFM, and cry bitter tears

    For the log it'd be remotely acceptable, but you'd never want a similar thing to happen for wallets.

    This is nothing new, by the way!

    -port -bind -rpcport -rpcbind already suffer from this. They are really options that one would want to specify per network.

    -logdir only has an effect on mainnet, you have to use -regtest-logdir or -testnet-logdir or similar to have debug.log go elsewhere

    I'm starting to like this as this is explicit, they don't depend on context, e.g., what file something was specified it. It works as well with -conf=<file> as with the automatic way of finding configuration files. But it's a major change to argument handling nevertheless...

  16. laanwj added the label Utils/logging/libs on Nov 30, 2017
  17. laanwj removed the label Docs and Output on Nov 30, 2017
  18. laanwj referenced this in commit 24df9af816 on Dec 4, 2017
  19. laanwj commented at 2:16 PM on December 6, 2017: member

    Closing because #11781 was merged which covers this.

  20. laanwj closed this on Dec 6, 2017

  21. PastaPastaPasta referenced this in commit 49345744c7 on Jan 17, 2020
  22. PastaPastaPasta referenced this in commit a1c71b4cde on Jan 22, 2020
  23. PastaPastaPasta referenced this in commit 3770ad9ab2 on Jan 22, 2020
  24. PastaPastaPasta referenced this in commit 83ce3bf78d on Jan 29, 2020
  25. PastaPastaPasta referenced this in commit 9634b5f32c on Jan 29, 2020
  26. PastaPastaPasta referenced this in commit 68bc3f31da on Jan 29, 2020
  27. PastaPastaPasta referenced this in commit 608fad56a0 on Jan 30, 2020
  28. ckti referenced this in commit dd03301e1b on Mar 28, 2021
  29. gades referenced this in commit 05fe2d7eee on Jun 30, 2021
  30. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 15:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me