14

The debug.log file is getting pretty big on bitcoind. How do you limit the size of the file? I'm on Ubuntu 12.

4 Answers 4

9

You can use logrotate.
Create a file named bitcoin-debug in /etc/logrotate.d.

This is the contents:

/home/bitcoin/.bitcoin/debug.log
{
        rotate 36
        monthly
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        postrotate
                kill -HUP `cat /home/bitcoin/.bitcoin/bitcoind.pid`
        endscript
}

Replace /home/bitcoin/.bitcoin with the actual path to your bitcoin directory.

The full logrotate manpage is here: http://manpages.ubuntu.com/manpages/jaunty/man8/logrotate.8.html

In ubuntu the logrotate daemon manages many different log files. In the /etc/logrotate.d folder, each file contains instructions for the logrotate deamon. Adding this file tells logrotate that you want to start a new log file once a month. The other options tell it to compress the old logs after a day and to keep only 36 months worth (3 years) of logs.

I originally found out about logrotate from this thread: https://bitcointalk.org/index.php?topic=130533.0

Another thing to bear in mind is that given this sends the SIGHUP signal to the bitcoin server, if you happen to be running bitcoin within gdb, it becomes necessary to tell gdb to ignore the SIGHUP signal, so far example, bitcoind can be run using:

gdb $HOME/.bitcoin/bitcoin-qt -ex 'handle SIGHUP nostop' -ex run

3
  • i dont get how this works. can you explain. thanks! Commented Dec 17, 2013 at 17:46
  • do i need to do anything to kick off the daemon, or does it automatically start doing it?
    – tofutim
    Commented Apr 5, 2018 at 20:25
  • logrotate runs by default in ubuntu so you don't need to do anything other than adding files to the /etc/logrotate.d folder.
    – hsmiths
    Commented May 12, 2018 at 18:52
10

Add -shrinkdebuglog to the options you use to start bitcoin, or add shrinkdebuglog=1 to your bitcoin.conf.

Every startup, if the log is larger than 1MB, it will shrink it to 200KB.

3

As I don't have enough reputation to add a comment to hsmiths (correct!) answer above:

I found I had to also add a line to tell logrotate to switch users to the bitcoin user (as I run bitcoind as its own user) using the format: su - $user $group. Also as I installed the systemd service as per the bitcoin github example I had a different PID location. This resulted in the following /etc/logrotate.d/bitcoin-debug file:

/home/bitcoin/.bitcoin/debug.log
{
        rotate 36
        monthly
        missingok
        notifempty
        compress
        delaycompress
        sharedscripts
        postrotate
                kill -HUP `cat /run/bitcoind/bitcoind.pid`
        endscript
        su - bitcoin bitcoin
}

You can restart logrotate with sudo systemctl restart logrotate.service and then check the status for errors with sudo systemctl status logrotate.service

1
  • Comments are not allowed as separated answers even if you don't have enough reputation but an addition to an answer can be posted as an answer - I think.
    – MCCCS
    Commented May 6, 2020 at 10:01
1

Alternatively, you can use printtoconsole to redirect the debug output to the console instead of the debug.log file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.