[syslog-ng]log rotation feature - patch

klaas.vangend@philips.com klaas.vangend@philips.com
Fri, 1 Feb 2002 14:30:15 +0100


--=_mixed 004A75D7C1256B53_=
Content-Type: text/plain; charset="us-ascii"

Gentlemen,

As stated last friday, 
I'd like enhance syslog-ng with some features in order to get rid of some 
log rotation scripts:

"For some of our systems, we log to a centralised system, but also store 
the logs locally.
These local logs only need limited availability, say a week or so.
The file() destination currently is already able to use the target 
$WEEKDAYS,
but in that case, logs from both Jan 17 and Jan 24 are logged in 
messages.Thu.log
Therefore, I'd like to add a new option   remove_if_older(X)    which 
removes a logfile 
with a timestamp older than X days prior to writing the new message to 
that file.
(default should be 0 (=never), which means that for a disabled feauture 
only one C 'if' statement additional overhead is caused)"

I've finished implementing the above feature, which is attached as a 
patch.
I patched against 1.4.14, the latest stable version, and it probably will 
work for the unstable tree, too.
The patch compiles and is verified to work for SuSE Linux 6.4 (Linux 
2.2.19 kernel, gcc 2.95.2, libc 2.1.3 ).

I hope everybody thinks it's a nice feature and that this patch is soon 
added to a new stable syslog-ng release...
(Please, Balazs???)

Groetjes,

Klaas van Gend



--=_mixed 004A75D7C1256B53_=
Content-Type: application/octet-stream; name="patch_remove_if_older.diff"
Content-Disposition: attachment; filename="patch_remove_if_older.diff"
Content-Transfer-Encoding: base64

ZGlmZiAtTnVydyBzeXNsb2ctbmctMS40LjE0L2RvYy9zZ21sL3N5c2xvZy1uZy5zZ21sIHN5c2xv
Zy1uZy0xLjQuMTQua3ZnL2RvYy9zZ21sL3N5c2xvZy1uZy5zZ21sCi0tLSBzeXNsb2ctbmctMS40
LjE0L2RvYy9zZ21sL3N5c2xvZy1uZy5zZ21sCU1vbiBOb3YgIDYgMTA6MzA6NTggMjAwMAorKysg
c3lzbG9nLW5nLTEuNC4xNC5rdmcvZG9jL3NnbWwvc3lzbG9nLW5nLnNnbWwJRnJpIEZlYiAgMSAx
MDowOTo1MSAyMDAyCkBAIC04ODUsNiArODg1LDEyIEBACiAJCTwvZW50cnk+CiAJIC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i0+b3duZXItPnJlbW92ZV9pZl9vbGRl
ciA+IDApIHsKKyAgICAgICAgCS8qIHJlbW92ZSAoPXVubGluaykgaWYgZmlsZSBpcyBtb3JlIHRo
YW4gWFhYIGRheXMgb2xkICovCisgICAgICAgIAlzdHJ1Y3Qgc3RhdCAgbXlzdGF0OworICAgICAg
ICAJdGltZV90ICBteWN1cnJlbnR0aW1lID0gdGltZShOVUxMKTsKKyAgICAgICAgCWlmIChzdGF0
KHNlbGYtPmV4cGFuZGVkX2ZuYW1lLT5kYXRhLCAmbXlzdGF0KSA9PSAwKSB7CisgICAgICAgICAg
ICAgICAgCWlmICgobXljdXJyZW50dGltZS1teXN0YXQuc3RfbXRpbWUpID49CisgICAgICAgICAg
ICAgICAgICAgIAkoMjQqNjAqNjAqKHNlbGYtPm93bmVyLT5yZW1vdmVfaWZfb2xkZXIpKSkgewor
ICAgICAgICAgICAgICAgICAgICAgICAgCXVubGluayhzZWxmLT5leHBhbmRlZF9mbmFtZS0+ZGF0
YSk7CisgICAgICAgICAgICAgICAgCX0KKyAgICAgICAgCX0KKwl9CisKIAlpZiAoZG9fb3Blbl9m
aWxlKHNlbGYtPmV4cGFuZGVkX2ZuYW1lLCBmbGFncywgCiAJICAgICAgICAgICAgICAgICBzZWxm
LT5vd25lci0+dWlkLCBzZWxmLT5vd25lci0+Z2lkLCBzZWxmLT5vd25lci0+cGVybSwgCiAJICAg
ICAgICAgICAgICAgICBzZWxmLT5vd25lci0+ZGlyX3VpZCwgc2VsZi0+b3duZXItPmRpcl9naWQs
IHNlbGYtPm93bmVyLT5kaXJfcGVybSwKQEAgLTI2NCw2ICsyNzgsNyBAQAogCSAoZGlyX2dpZCAu
IGludCkKIAkgKGRpcl9wZXJtIC4gaW50KQogICAgICAgICAgKGZsYWdzIHNpbXBsZSBpbnQpCisg
ICAgICAgICAocmVtb3ZlX2lmX29sZGVyIC4gaW50KQogCSAoc3luY19mcmVxIHNpbXBsZSBVSU5U
MzIpCiAJICh0ZW1wbG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