<p>Add <code>-shrinkdebuglog</code> to the options you use to start bitcoin, or add <code>shrinkdebuglog=1</code> to your <code>bitcoin.conf</code>.</p>

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

CC BY-SA 3.0
2015-01-28T04:07:41.543Z
2015-01-28T04:07:41.543Z
Nick ODell
<p>As I don't have enough reputation to add a comment to hsmiths (correct!) answer above:</p>

<p>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: <code>su - $user $group</code>. Also as I installed the systemd service  as per the bitcoin github <a href="https://github.com/bitcoin/bitcoin/blob/master/contrib/init/bitcoind.service" rel="nofollow noreferrer">example</a> I had a different PID location. This resulted in the following <code>/etc/logrotate.d/bitcoin-debug</code> file:</p>

<pre><code>/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
}
</code></pre>

<p>You can restart logrotate with <code>sudo systemctl restart logrotate.service</code> and then check the status for errors with <code>sudo systemctl status logrotate.service</code></p>

CC BY-SA 4.0
2020-05-06T10:01:04.820Z
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
CC BY-SA 4.0
2020-05-06T09:46:19.483Z
2020-05-06T09:46:19.483Z
willcl_ark
<p>Alternatively, you can use <code>printtoconsole</code> to redirect the debug output to the console instead of the <code>debug.log</code> file.</p>

CC BY-SA 4.0
2020-01-14T01:13:00.710Z
2020-01-14T01:13:00.710Z
Murch
<p>You can use logrotate.<br>
Create a file named bitcoin-debug in /etc/logrotate.d.  </p>

<p>This is the contents:</p>

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

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

<p>The full logrotate manpage is here: <a href="http://manpages.ubuntu.com/manpages/jaunty/man8/logrotate.8.html" rel="nofollow noreferrer">http://manpages.ubuntu.com/manpages/jaunty/man8/logrotate.8.html</a></p>

<p>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. </p>

<p>I originally found out about logrotate from this thread: <a href="https://bitcointalk.org/index.php?topic=130533.0" rel="nofollow noreferrer">https://bitcointalk.org/index.php?topic=130533.0</a></p>

<p>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: <pre>gdb $HOME/.bitcoin/bitcoin-qt -ex 'handle SIGHUP nostop' -ex run</pre></p>

CC BY-SA 3.0
2013-12-17T17:46:50.220Z
i dont get how this works. can you explain. thanks!
Patoshi パトシ
CC BY-SA 3.0
2018-04-05T20:25:02.800Z
do i need to do anything to kick off the daemon, or does it automatically start doing it?
tofutim
CC BY-SA 4.0
2018-05-12T18:52:07.907Z
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
CC BY-SA 4.0
2013-12-17T05:04:37.023Z
2020-02-24T13:48:45.010Z
2020-02-24T13:48:45.010Z
hsmiths
<p>The <code>debug.log</code> file is getting pretty big on <code>bitcoind</code>. How do you limit the size of the file? I'm on Ubuntu 12.</p>

<bitcoind><debugging><logging>
How to limit the debug.log file while running bitcoind?
Patoshi パトシ
# How to limit the debug.log file while running bitcoind?

(Asked by: username_0 on 2013-12-16)

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

**Tags:** bitcoind, debugging, logging


---

## 4 answers

### Answer by username_5 on 2013-12-17. Score: 9 | Accepted answer

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

> **Comments:**
> **username_0**: i dont get how this works. can you explain. thanks!  
> **username_6**: do i need to do anything to kick off the daemon, or does it automatically start doing it?  
> **username_5**: logrotate runs by default in ubuntu so you don't need to do anything other than adding files to the /etc/logrotate.d folder.  

---

### Answer by username_1 on 2015-01-28. Score: 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.


---

### Answer by username_2 on 2020-05-06. Score: 3

As I don't have enough reputation to add a comment to username_5 (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

> **Comments:**
> **username_3**: 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.  

---

### Answer by username_4 on 2020-01-14. Score: 1

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


---

