[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] feat(syslogd): implement log rotation by log-age and by
From: Daniel Giritzer <d.giritzer () danube-dynamics ! at>
Date: 2024-04-17 11:25:28
Message-ID: AS8PR10MB47251F963EF6A0C9923C3A2AB50F2 () AS8PR10MB4725 ! EURPRD10 ! PROD ! OUTLOOK ! COM
[Download RAW message or body]
[Attachment #2 (multipart/related)]
[Attachment #4 (multipart/alternative)]
This patch allows syslogd to additionally rotate the log files by age and o=
n a per-day basis. All settings can be configured either mutually exclusive=
or in combination.
Mit freundlichen Gr=FC=DFen | With kind regards
Daniel Giritzer, MSc
Certified Professional for Software Architecture<https://www.certible.com/b=
adge/c7057dd8-7007-4f04-b510-6ec200b05ac7/>
T: +43 732 266277
E: d.giritzer@danube-dynamics.at
L: Let=92s connect on <https://www.linkedin.com/in/nwrkbiz/> LinkedIn<http=
s://www.linkedin.com/in/nwrkbiz/>
[Ein Bild, das Schrift, Grafiken, Text, Screenshot enth=E4lt. Automatisch =
generierte Beschreibung]<http://www.danube-dynamics.at/>
Danube Dynamics Embedded Solutions GmbH
Lastenstra=DFe 38/12. OG | 4020 Linz | Austria
Registry Court: Linz
Reg. No.: FN 536539 d
VAT Reg. No.: ATU75804667
Web: www.danube-dynamics.at<http://www.danube-dynamics.at/>
[Image]<https://www.facebook.com/danubedynamics/> [Image] <https://youtube=
.com/@danubedynamics625> [Image] <https://www.instagram.com/danube_dynami=
cs/> [Image] <https://www.linkedin.com/company/danube-dynamics/>
The information contained in this message may be confidential and legally p=
rotected under applicable law. The message is intended solely for the addre=
ssee(s). If you are not the intended recipient, you are hereby notified tha=
t any use, forwarding, dissemination, or reproduction of this message is st=
rictly prohibited and may be unlawful. If you are not the intended recipien=
t, please contact the sender by return e-mail and destroy all copies of the=
original message.
See our privacy policy: https://www.danube-dynamics.at/datenschutz/
[Attachment #7 (text/html)]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} \
</style> </head>
<body dir="ltr">
<div class="elementToProof" style="font-family: "Segoe UI", "Segoe UI \
Web (West European)", "Segoe UI", -apple-system, BlinkMacSystemFont, \
Roboto, "Helvetica Neue", sans-serif; font-size: 16px; color: rgb(13, 13, \
13);"> <span style="background-color: rgb(255, 255, 255);">This patch allows syslogd \
to additionally rotate the log files by age and on a per-day basis. All settings can \
be configured either mutually exclusive or in combination.</span></div> <div \
style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, \
Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);"> <br>
</div>
<div id="Signature">
<div style="background-color: rgb(255, 255, 255);">
<p style="text-align: left; background-color: rgb(255, 255, 255); margin: 0cm; \
font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(36, 36, 36);"> <span \
style="font-family: "Helvetica Neue"; font-size: 9pt; color: rgb(33, 33, \
33);">Mit freundlichen Grüßen | With kind regards</span></p> <p style="text-align: \
left; background-color: rgb(255, 255, 255); margin: 0cm; font-family: Calibri, \
sans-serif; font-size: 11pt; color: rgb(36, 36, 36);"> <span style="font-family: \
"Helvetica Neue"; font-size: 9pt; color: rgb(33, 33, 33);"><b>Daniel \
Giritzer, MSc</b></span></p> <p style="text-align: left; background-color: rgb(255, \
255, 255); margin: 0cm;"><span style="font-family: "Helvetica Neue"; \
font-size: 12px; color: rgb(33, 33, 33);"><a \
href="https://www.certible.com/badge/c7057dd8-7007-4f04-b510-6ec200b05ac7/" \
title="https://www.certible.com/badge/c7057dd8-7007-4f04-b510-6ec200b05ac7/" \
style="margin-top: 0px; margin-bottom: 0px;">Certified Professional for Software \
Architecture</a></span></p> <p style="text-align: left; background-color: rgb(255, \
255, 255); margin: 0cm; font-family: Calibri, sans-serif; font-size: 11pt; color: \
rgb(36, 36, 36);"> <span style="font-family: "Helvetica Neue"; font-size: \
10pt; color: rgb(33, 33, 33);"> </span></p> <p style="text-align: left; \
background-color: rgb(255, 255, 255); margin: 0cm; font-family: Calibri, sans-serif; \
font-size: 11pt; color: rgb(36, 36, 36);"> <span style="font-family: "Helvetica \
Neue"; font-size: 8pt; color: black;"><b>T</b>: <u>+43 732 \
266277</u></span></p> <p style="text-align: left; background-color: rgb(255, 255, \
255); margin: 0cm; font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(36, \
36, 36);"> <span style="font-family: "Helvetica Neue"; font-size: 8pt; \
color: black;"><b>E</b>: </span><span style="font-family: "Helvetica \
Neue"; font-size: 8pt; color: rgb(5, 99, \
193);"><u>d.giritzer@danube-dynamics.at</u></span></p> <p style="text-align: left; \
background-color: rgb(255, 255, 255); margin: 0cm; font-family: Calibri, sans-serif; \
font-size: 11pt; color: rgb(36, 36, 36);"> <span style="font-family: "Helvetica \
Neue"; font-size: 8pt; color: black;"><b>L:</b> </span><span \
style="font-family: "Helvetica Neue"; font-size: 8pt; color: rgb(5, 99, \
193);"><u><a href="https://www.linkedin.com/in/nwrkbiz/" \
title="https://www.linkedin.com/in/nwrkbiz/" style="margin-top: 0px; margin-bottom: \
0px;">Let’s connect on </a></u><b><u><a href="https://www.linkedin.com/in/nwrkbiz/" \
title="https://www.linkedin.com/in/nwrkbiz/" style="margin-top: 0px; margin-bottom: \
0px;">LinkedIn</a></u></b></span></p> <p style="text-align: left; background-color: \
rgb(255, 255, 255); margin: 0cm 0cm 1.5pt; font-family: Calibri, sans-serif; \
font-size: 11pt; color: rgb(36, 36, 36);"> <span style="font-family: "Helvetica \
Neue"; font-size: 10pt; color: rgb(33, 33, 33);"> </span></p> <p \
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0cm; \
font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(36, 36, 36);"> <span \
style="font-family: "Helvetica Neue"; font-size: 10pt; color: rgb(33, 33, \
33);"><u><a href="http://www.danube-dynamics.at/" target="_blank" \
class="ContentPasted1" rel="noopener noreferrer" data-linkindex="3" \
data-auth="NotApplicable" style="color: rgb(33, 33, 33); margin: 0px;"><img alt="Ein \
Bild, das Schrift, Grafiken, Text, Screenshot enthält.
Automatisch generierte Beschreibung" width="279" height="60" style="width: 2.9166in; \
height: 0.6354in; min-width: auto; min-height: auto; margin: 0px;" \
data-outlook-trace="F:1|T:1" \
src="cid:2aaf6527-774d-4581-b1a5-aa2a205251ba"></a></u></span></p> <p \
style="text-align: left; background-color: white; margin: 0cm; font-family: Calibri, \
sans-serif; font-size: 11pt; color: rgb(36, 36, 36);"> <span style="font-family: \
"Helvetica Neue"; font-size: 9pt; color: black;"><b>Danube Dynamics \
Embedded Solutions GmbH</b></span></p> <p style="text-align: left; background-color: \
white; margin: 0cm; font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(36, \
36, 36);"> <span style="font-family: "Helvetica Neue"; font-size: 9pt; \
color: black;">Lastenstraße 38/12. OG | 4020 Linz | Austria</span></p> <p \
style="text-align: left; background-color: white; margin: 0cm; font-family: Calibri, \
sans-serif; font-size: 11pt; color: rgb(36, 36, 36);"> <span style="font-size: 10pt; \
color: black;"> </span></p> <p style="text-align: left; background-color: white; \
margin: 0cm 0cm 1.5pt; font-family: Calibri, sans-serif; font-size: 11pt; color: \
rgb(36, 36, 36);"> <span style="font-family: "Helvetica Neue"; font-size: \
6.5pt; color: rgb(33, 33, 33);"><b>Registry Court:</b> Linz</span></p> <p \
style="text-align: left; background-color: white; margin: 0cm 0cm 1.5pt; font-family: \
Calibri, sans-serif; font-size: 11pt; color: rgb(36, 36, 36);"> <span \
style="font-family: "Helvetica Neue"; font-size: 6.5pt; color: rgb(33, 33, \
33);"><b>Reg. No.:</b> FN 536539 d</span></p> <p style="text-align: left; \
background-color: white; margin: 0cm 0cm 1.5pt; font-family: Calibri, sans-serif; \
font-size: 11pt; color: rgb(36, 36, 36);"> <span style="font-family: "Helvetica \
Neue"; font-size: 6.5pt; color: rgb(33, 33, 33);"><b>VAT Reg. \
No.:</b> ATU75804667</span></p> <p style="text-align: left; background-color: \
white; margin: 0cm 0cm 1.5pt; font-family: Calibri, sans-serif; font-size: 11pt; \
color: rgb(36, 36, 36);"> <span style="font-family: "Helvetica Neue"; \
font-size: 6.5pt; color: rgb(33, 33, 33);"><b>Web:</b> </span><span \
style="font-family: "Helvetica Neue"; font-size: 6.5pt; color: rgb(0, 120, \
215);"><u><a href="http://www.danube-dynamics.at/" target="_blank" \
class="ContentPasted1" title="http://www.danube-dynamics.at" rel="noopener \
noreferrer" data-linkindex="4" data-auth="NotApplicable" style="color: rgb(0, 120, \
215); margin: 0px;">www.danube-dynamics.at</a></u></span></p> <p style="text-align: \
left; background-color: white; margin: 0cm 0cm 1.5pt; font-family: Calibri, \
sans-serif; font-size: 11pt; color: rgb(36, 36, 36);"> <span style="font-family: \
"Helvetica Neue"; font-size: 6.5pt; color: rgb(33, 33, \
33);"><u> </u></span></p> <p style="text-align: left; background-color: rgb(255, \
255, 255); margin: 0cm; font-family: Calibri, sans-serif; font-size: 11pt; color: \
rgb(36, 36, 36);"> <span style="font-family: "Helvetica Neue"; font-size: \
10pt; color: rgb(33, 33, 33);"><u><a href="https://www.facebook.com/danubedynamics/" \
target="_blank" class="ContentPasted1" rel="noopener noreferrer" data-linkindex="5" \
data-auth="NotApplicable" style="color: rgb(33, 33, 33); margin: 0px;"><img \
alt="Image" width="30" height="30" style="width: 0.3125in; height: 0.3125in; \
min-width: auto; min-height: auto; margin: 0px;" data-outlook-trace="F:1|T:1" \
src="cid:29877545-e35d-46d1-9f9a-dc4e5ccb5c64"></a></u> <u><a \
href="https://youtube.com/@danubedynamics625" target="_blank" class="ContentPasted1" \
rel="noopener noreferrer" data-linkindex="6" data-auth="NotApplicable" style="color: \
rgb(33, 33, 33); margin: 0px;"><img alt="Image" width="30" height="30" style="width: \
0.3125in; height: 0.3125in; min-width: auto; min-height: auto; margin: 0px;" \
data-outlook-trace="F:1|T:1" \
src="cid:d2914f8c-74e8-4449-8657-ec0d3d08c870"></a></u> <u><a \
href="https://www.instagram.com/danube_dynamics/" target="_blank" \
class="ContentPasted1" rel="noopener noreferrer" data-linkindex="7" \
data-auth="NotApplicable" style="color: rgb(33, 33, 33); margin: 0px;"><img \
alt="Image" width="30" height="30" style="width: 0.3125in; height: 0.3125in; \
min-width: auto; min-height: auto; margin: 0px;" data-outlook-trace="F:1|T:1" \
src="cid:4db8c90a-a74e-4202-b2d7-0c873a477e86"></a></u> <u><a \
href="https://www.linkedin.com/company/danube-dynamics/" target="_blank" \
class="ContentPasted1" rel="noopener noreferrer" data-linkindex="8" \
data-auth="NotApplicable" style="color: rgb(33, 33, 33); margin: 0px;"><img \
alt="Image" width="30" height="30" style="width: 0.3125in; height: 0.3125in; \
min-width: auto; min-height: auto; margin: 0px;" data-outlook-trace="F:1|T:1" \
src="cid:6b4adab7-03da-4878-a6d5-d47ad29e55b0"></a></u></span></p> <p \
style="text-align: left; background-color: rgb(255, 255, 255); margin: 0cm; \
font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(36, 36, 36);"> <span \
style="font-family: "Helvetica Neue"; font-size: 6.5pt; color: rgb(33, 33, \
33);"> </span></p> <p style="text-align: left; background-color: rgb(255, 255, \
255); margin: 0cm; font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(36, \
36, 36);"> <span style="font-family: "Helvetica Neue"; font-size: 6.5pt; \
color: rgb(33, 33, 33);">The information contained in this message may be \
confidential and legally protected under applicable law. The message is intended \
solely for the addressee(s). If you are not the intended recipient, you are hereby \
notified that any use, forwarding, dissemination, or reproduction of this message is \
strictly prohibited and may be unlawful. If you are not the intended recipient, \
please contact the sender by return e-mail and destroy all copies of the original \
message.</span></p> <p style="text-align: left; background-color: rgb(255, 255, 255); \
margin: 0cm; font-family: Calibri, sans-serif; font-size: 11pt; color: rgb(36, 36, \
36);"> <span style="font-family: "Helvetica Neue"; font-size: 6.5pt; color: \
rgb(33, 33, 33);"> </span></p> <p style="text-align: left; background-color: \
rgb(255, 255, 255); margin: 0cm; font-family: Calibri, sans-serif; font-size: 11pt; \
color: rgb(36, 36, 36);"> <span style="font-family: "Helvetica Neue"; \
font-size: 6.5pt; color: black;">See our privacy policy: </span><span \
style="font-family: "Helvetica Neue"; font-size: 6.5pt; color: rgb(0, 120, \
215);"><u><a href="https://www.danube-dynamics.at/datenschutz/" target="_blank" \
class="ContentPasted1" title="https://www.danube-dynamics.at/datenschutz/" \
rel="noopener noreferrer" data-linkindex="9" data-auth="NotApplicable" style="color: \
rgb(0, 120, 215); margin: \
0px;">https://www.danube-dynamics.at/datenschutz/</a></u></span></p> </div>
</div>
</body>
</html>
["Outlook-Ein Bild, .png" (image/png)]
["Outlook-Image.png" (image/png)]
["Outlook-Image.png" (image/png)]
["Outlook-Image.png" (image/png)]
["Outlook-Image.png" (image/png)]
["0001-feat-syslogd-implement-log-rotation-by-log-age-and-b.patch" (text/x-patch)]
From c23901cde610e84e36b1513ecdddc56f6f59eb92 Mon Sep 17 00:00:00 2001
From: Daniel Giritzer <d.giritzer@danube-dynamics.at>
Date: Mon, 15 Apr 2024 16:10:33 +0200
Subject: [PATCH 1/1] feat(syslogd): implement log rotation by log-age and by
day
Signed-off-by: Daniel Giritzer <d.giritzer@danube-dynamics.at>
---
sysklogd/syslogd.c | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index 6ddfd771a..8b1241d0c 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -144,6 +144,8 @@
//usage: IF_FEATURE_ROTATE_LOGFILE(
//usage: "\n -s SIZE Max size (KB) before rotation (default 200KB, 0=off)"
//usage: "\n -b N N rotated logs to keep (default 1, max 99, 0=purge)"
+//usage: "\n -T N N seconds to pass since file opening before rotation (default 0, 0=Off)"
+//usage: "\n -d Rotate every day"
//usage: )
//usage: "\n -l N Log only messages more urgent than prio N (1-8)"
//usage: "\n -S Smaller output"
@@ -223,6 +225,7 @@ typedef struct logFile_t {
#if ENABLE_FEATURE_ROTATE_LOGFILE
unsigned size;
uint8_t isRegular;
+ time_t file_first_open_time;
#endif
} logFile_t;
@@ -246,6 +249,8 @@ IF_FEATURE_ROTATE_LOGFILE( \
unsigned logFileSize; \
/* number of rotated message files */ \
unsigned logFileRotate; \
+ /* time to pass until rotation */ \
+ unsigned logFileAge; \
) \
IF_FEATURE_IPC_SYSLOG( \
int shmid; /* ipc shared memory id */ \
@@ -301,6 +306,7 @@ static const struct init_globals init_data = {
#if ENABLE_FEATURE_ROTATE_LOGFILE
.logFileSize = 200 * 1024,
.logFileRotate = 1,
+ .logFileAge = 0,
#endif
#if ENABLE_FEATURE_IPC_SYSLOG
.shmid = -1,
@@ -327,6 +333,8 @@ enum {
OPTBIT_timestamp, // -t
IF_FEATURE_ROTATE_LOGFILE(OPTBIT_filesize ,) // -s
IF_FEATURE_ROTATE_LOGFILE(OPTBIT_rotatecnt ,) // -b
+ IF_FEATURE_ROTATE_LOGFILE(OPTBIT_rotatetime ,) // -T
+ IF_FEATURE_ROTATE_LOGFILE(OPTBIT_rotateday ,) // -d
IF_FEATURE_REMOTE_LOG( OPTBIT_remotelog ,) // -R
IF_FEATURE_REMOTE_LOG( OPTBIT_locallog ,) // -L
IF_FEATURE_IPC_SYSLOG( OPTBIT_circularlog,) // -C
@@ -342,6 +350,8 @@ enum {
OPT_timestamp = 1 << OPTBIT_timestamp,
OPT_filesize = IF_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_filesize )) + 0,
OPT_rotatecnt = IF_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_rotatecnt )) + 0,
+ OPT_rotatetime = IF_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_rotatetime )) + 0,
+ OPT_rotateday = IF_FEATURE_ROTATE_LOGFILE((1 << OPTBIT_rotateday )) + 0,
OPT_remotelog = IF_FEATURE_REMOTE_LOG( (1 << OPTBIT_remotelog )) + 0,
OPT_locallog = IF_FEATURE_REMOTE_LOG( (1 << OPTBIT_locallog )) + 0,
OPT_circularlog = IF_FEATURE_IPC_SYSLOG( (1 << OPTBIT_circularlog)) + 0,
@@ -352,6 +362,8 @@ enum {
#define OPTION_STR "m:nO:l:St" \
IF_FEATURE_ROTATE_LOGFILE("s:" ) \
IF_FEATURE_ROTATE_LOGFILE("b:" ) \
+ IF_FEATURE_ROTATE_LOGFILE("T:" ) \
+ IF_FEATURE_ROTATE_LOGFILE("d" ) \
IF_FEATURE_REMOTE_LOG( "R:*") \
IF_FEATURE_REMOTE_LOG( "L" ) \
IF_FEATURE_IPC_SYSLOG( "C::") \
@@ -361,11 +373,13 @@ enum {
#define OPTION_DECL *opt_m, *opt_l \
IF_FEATURE_ROTATE_LOGFILE(,*opt_s) \
IF_FEATURE_ROTATE_LOGFILE(,*opt_b) \
+ IF_FEATURE_ROTATE_LOGFILE(,*opt_T) \
IF_FEATURE_IPC_SYSLOG( ,*opt_C = NULL) \
IF_FEATURE_SYSLOGD_CFG( ,*opt_f = NULL)
#define OPTION_PARAM &opt_m, &(G.logFile.path), &opt_l \
IF_FEATURE_ROTATE_LOGFILE(,&opt_s) \
IF_FEATURE_ROTATE_LOGFILE(,&opt_b) \
+ IF_FEATURE_ROTATE_LOGFILE(,&opt_T) \
IF_FEATURE_REMOTE_LOG( ,&remoteAddrList) \
IF_FEATURE_IPC_SYSLOG( ,&opt_C) \
IF_FEATURE_SYSLOGD_CFG( ,&opt_f)
@@ -694,6 +708,9 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file)
struct flock fl;
#endif
int len = strlen(msg);
+#if ENABLE_FEATURE_ROTATE_LOGFILE
+ struct tm then_tm, now_tm;
+#endif
/* fd can't be 0 (we connect fd 0 to /dev/log socket) */
/* fd is 1 if "-O -" is in use */
@@ -740,6 +757,9 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file)
log_file->isRegular = (fstat(log_file->fd, &statf) == 0 && S_ISREG(statf.st_mode));
/* bug (mostly harmless): can wrap around if file > 4gb */
log_file->size = statf.st_size;
+ if(log_file->file_first_open_time == 0) {
+ log_file->file_first_open_time = time(NULL);
+ }
}
#endif
}
@@ -754,7 +774,13 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file)
#endif
#if ENABLE_FEATURE_ROTATE_LOGFILE
- if (G.logFileSize && log_file->isRegular && log_file->size > G.logFileSize) {
+ then_tm = *localtime(&log_file->file_first_open_time);
+ now_tm = *localtime(&now);
+ if (log_file->isRegular && (
+ (G.logFileSize && log_file->size > G.logFileSize) || // rotate by size
+ (G.logFileAge && now > G.logFileAge + log_file->file_first_open_time) || // rotate by age
+ ((option_mask32 & OPT_rotateday) && then_tm.tm_mday != now_tm.tm_mday) // rotate by day
+ )) {
if (G.logFileRotate) { /* always 0..99 */
int i = strlen(log_file->path) + 3 + 1;
char oldFile[i];
@@ -782,6 +808,7 @@ static void log_locally(time_t now, char *msg, logFile_t *log_file)
* So ensure old file is gone in any case:
*/
unlink(log_file->path);
+ log_file->file_first_open_time = 0; // will be set on open
#ifdef SYSLOGD_WRLOCK
fl.l_type = F_UNLCK;
fcntl(log_file->fd, F_SETLKW, &fl);
@@ -1163,6 +1190,8 @@ int syslogd_main(int argc UNUSED_PARAM, char **argv)
G.logFileSize = xatou_range(opt_s, 0, INT_MAX/1024) * 1024;
if (opts & OPT_rotatecnt) // -b
G.logFileRotate = xatou_range(opt_b, 0, 99);
+ if (opts & OPT_rotatetime) // -T
+ G.logFileAge = xatou_range(opt_T, 0, INT_MAX);
#endif
#if ENABLE_FEATURE_IPC_SYSLOG
if (opt_C) // -Cn
--
2.39.2
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic