diff options
| author | Carl Hetherington <cth@carlh.net> | 2014-11-06 21:41:43 +0000 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2014-11-06 21:41:43 +0000 |
| commit | 90ec60c9e5b45453525368842345ad1a6498fa61 (patch) | |
| tree | 720e97d855e98c4c62ffecfe4e2945a32ab27dc9 /src/lib/log.cc | |
| parent | b17b68bb8e564601c7ea80ceea853fa564998c39 (diff) | |
Basic support for emailing a report of a problem (#43).
Diffstat (limited to 'src/lib/log.cc')
| -rw-r--r-- | src/lib/log.cc | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/lib/log.cc b/src/lib/log.cc index 5e8277a23..156f8cf8b 100644 --- a/src/lib/log.cc +++ b/src/lib/log.cc @@ -123,3 +123,42 @@ FileLog::do_log (string m) fclose (f); } +string +FileLog::head_and_tail () const +{ + boost::mutex::scoped_lock lm (_mutex); + + uintmax_t head_amount = 1024; + uintmax_t tail_amount = 1024; + uintmax_t size = boost::filesystem::file_size (_file); + + if (size < (head_amount + tail_amount)) { + head_amount = size; + tail_amount = 0; + } + + FILE* f = fopen_boost (_file, "r"); + if (!f) { + return ""; + } + + string out; + + char* buffer = new char[max(head_amount, tail_amount) + 1]; + + int N = fread (buffer, 1, head_amount, f); + buffer[N] = '\0'; + out += buffer; + + fseek (f, tail_amount, SEEK_END); + + N = fread (buffer, 1, tail_amount, f); + buffer[N] = '\0'; + out += buffer; + + delete[] buffer; + + fclose (f); + + return out; +} |
