Author

Topic: Don't forget to rotate your logs... (Read 13098 times)

legendary
Activity: 1008
Merit: 1000
Let the chips fall where they may.
February 23, 2014, 03:08:04 PM
#11
FreeBSD uses a log rotator called newsyslog.

The following line in /etc/newsyslog.conf appears to do the right thing:
Code:
/home/bitcoin/debug.log bitcoin:bitcoin 644  5     100  *  JR /home/bitcoin/sighup.sh

The fields are separated by white-space. They are: 'logfile_name', 'owner:group', 'mode', 'count' (number of archives to keep), 'size' (in kb), 'when' (chose anytime), 'flags' (J->Bzip2, R-> Treat next field as as shell command to run), 'path_to_pid_cmd_file' (filename containing daemon's PID, must start with /), 'signal_number' (optional, omitted in example).

I first tried appending "killall -HUP bitcoind" directly, but the arguments were interpreted as an invalid signal number. With the size limited to 100 kB, the logs get rotated every hour (because they they grow faster than that).

sighup.sh is just a simple shell-script:
Code:
#!/bin/sh
#Sends bitcoind a Sighup.
killall -HUP bitcoind


I was not able to find any 'copytruncate', setting, but it appears to do the right thing.
hero member
Activity: 588
Merit: 500
July 27, 2011, 04:47:40 PM
#10
Or perhaps reopen the log on SIGHUP, like most other services?
hero member
Activity: 607
Merit: 500
April 12, 2011, 06:35:36 PM
#9
Yes, mine was around 100 MB after a longer while. Thanks for the logrotate tip, now it's back to normal Smiley.
administrator
Activity: 4228
Merit: 8647
April 12, 2011, 07:57:19 AM
#8
It only does it on startup, so the file might actually get bigger than 10MB.
member
Activity: 69
Merit: 10
April 11, 2011, 10:05:08 AM
#7
Nevermind, I think I found it.  It looks like 10 MB is when Bitcoin decides to reset the debug.log.

Code:
void ShrinkDebugFile()
{
    // Scroll debug.log if it's getting too big
    string strFile = GetDataDir() + "/debug.log";
    FILE* file = fopen(strFile.c_str(), "r");
    if (file && GetFilesize(file) > 10 * 1000000)
    { 
        // Restart the file with some of the end
        char pch[200000];
        fseek(file, -sizeof(pch), SEEK_END);
        int nBytes = fread(pch, 1, sizeof(pch), file);
        fclose(file);
        if (file = fopen(strFile.c_str(), "w"))
        { 
            fwrite(pch, 1, nBytes, file);
            fclose(file);
        }
    }
}
member
Activity: 69
Merit: 10
April 11, 2011, 09:26:24 AM
#6
Bitcoin already limits the size of debug.log.

What does Bitcoin limit the log size to?  I keep losing most of my log data and I'm wondering if Bitcoin keeps deleting it and starting over.
full member
Activity: 158
Merit: 100
November 18, 2010, 04:07:09 AM
#5
I just committed a change to svn to the way debug.log is written that means you need to change your logrotate configuration.

Why the change:  before, bitcoin was opening and closing debug.log on every print.  That caused it to be unusable on Macs running FileVault (and slower than it aught to be on various other systems).

After subversion rev 183, bitcoin will keep debug.log open and just append to it.

If you're rotating logs using the unix logrotate command, just add 'copytruncate' to its configuration file and the right thing will happen.  I changed the example in my post above.

Oh, my dear, why not you just haven't invented some new rpc command, like "reopenlogs" ?
administrator
Activity: 4228
Merit: 8647
November 17, 2010, 08:27:37 PM
#4
Bitcoin already limits the size of debug.log.
legendary
Activity: 1652
Merit: 1186
Chief Scientist
November 17, 2010, 08:18:11 PM
#3
I just committed a change to svn to the way debug.log is written that means you need to change your logrotate configuration.

Why the change:  before, bitcoin was opening and closing debug.log on every print.  That caused it to be unusable on Macs running FileVault (and slower than it aught to be on various other systems).

After subversion rev 183, bitcoin will keep debug.log open and just append to it.

If you're rotating logs using the unix logrotate command, just add 'copytruncate' to its configuration file and the right thing will happen.  I changed the example in my post above.
full member
Activity: 210
Merit: 100
July 12, 2010, 06:15:33 PM
#2
Great idea, Gavin. Thanks for the code; I'll copy that exactly (except for the gavin part Smiley)
legendary
Activity: 1652
Merit: 1186
Chief Scientist
July 12, 2010, 12:39:47 PM
#1
Reminder to anybody running a bitcoind server:   be sure the debug.log isn't filling up your server's disk.  With the slashdotting, now might be a good time to setup a debug.log housekeeping system.

I'm doing this on my Debian server:

My crontab:
Code:
# Rotate bitcoin logs
0 8 * * * /usr/sbin/logrotate --state /home/gavin/.bitcoin/logrotate.state /home/gavin/bc_logrotate.conf
My bc_logrotate.conf file:
Code:
#
# Rotate the bitcoin debug.log file
#
# This should be added to crontab to be run every day:
#  /usr/sbin/logrotate /path/to/bc_logrotate.conf
#
compress
copytruncate

/home/gavin/.bitcoin/debug.log {
rotate 5
}
Jump to: