Commit 162ab39
committed
Implement poorman's log rotating
This implements a very simple circular buffer that will take the last N
lines in a log file, and keep those instead. Right now the maximum N is
hardcoded, but the code is written in a fashion that we can revisit some
of this, and add toggles where we see fit (for example in a settings
dialog or so).
I tested out the functionality this way:
$ yes some-log-line | nl | head -5000 > log.txt
And then running PTE2 with a max log size of 1000, I noticed the logfile
like so:
$ head -10 log.txt
4001 some-log-line
4002 some-log-line
4003 some-log-line
4004 some-log-line
4005 some-log-line
4006 some-log-line
4007 some-log-line
4008 some-log-line
4009 some-log-line
4010 some-log-line
and the bottom:
$ tail -10 log.txt
2023-12-30T14:38:32Z: [debug]: finding translations for locale:
2023-12-30T14:38:32Z: [debug]: locale: en-US
2023-12-30T14:38:32Z: [debug]: locale: en
2023-12-30T14:38:32Z: [debug]: locale: en-Latn-US
2023-12-30T14:38:32Z: [debug]: - checking: /home/psyomn/.local/share/powertab/powertabeditor/translations
2023-12-30T14:38:32Z: [debug]: - checking: /usr/local/share/powertab/powertabeditor/translations
2023-12-30T14:38:32Z: [debug]: - checking: /usr/share/powertab/powertabeditor/translations
2023-12-30T14:38:32Z: [debug]: - checking: /home/psyomn/programming/cc/fork/powertabeditor/build/bin/data/translations
2023-12-30T14:38:32Z: [debug]: - checking: /usr/share/qt/translations
2023-12-30T14:38:32Z: [debug]: loaded qt base translations from /usr/share/qt/translations/qtbase_en.qm
and last checks:
$ nl log.txt | head -1
1 4001 some-log-line
$ nl log.txt | tail -1
1011 2023-12-30T14:38:32Z: [debug]: loaded qt base translations from /usr/share/qt/translations/qtbase_en.qm1 parent 3bd7772 commit 162ab39
2 files changed
Lines changed: 36 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
28 | 54 | | |
29 | 55 | | |
30 | 56 | | |
31 | 57 | | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
32 | 66 | | |
33 | 67 | | |
34 | 68 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | 27 | | |
| 28 | + | |
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | | - | |
102 | 98 | | |
103 | 99 | | |
104 | 100 | | |
| |||
0 commit comments