On Wed, Mar 01, 2000 at 11:51:58AM -0800, Alex Schlessinger wrote:
what am i doing or understanding incorrectly?
The file source driver is meant to be used on special files like /proc/kmsg. If you want to forward the contents of a real file, you could write a simple script like:
tail -f <logfile> | logger -p local5.info
understood, this is basically what i ended up doing.
however, the documentation is misleading..
http://www.balabit.hu/products/syslog-ng/doc/reference.html#AEN303
"Of course using this driver you are not limited to special files, you can as well read a continuosly growing simple file, and syslog-ng will "follow" appended lines, just like tail -f does."
ops, this is a docbug. earlier syslog-ng was able to do this, but this maxed out CPU usage. It is not possible to decide whether new data arrived to a file using poll(), since the main loop uses poll to wait for events, it would be difficult to add this feature. (though not impossible) so for now I corrected the documentation, and leave this feature addition for 1.5.x. -- Bazsi PGP info: KeyID 9AF8D0A9 Fingerprint CD27 CFB0 802C 0944 9CFD 804E C82C 8EB1 url: http://www.balabit.hu/pgpkey.txt
On Wed, 1 Mar 2000, Balazs Scheidler wrote:
ops, this is a docbug. earlier syslog-ng was able to do this, but this maxed out CPU usage. It is not possible to decide whether new data arrived to a file using poll()
I do a tail-like operation and sleep a predetermined interval between fgets. If you set the pause high-enough, it doesn't take much CPU (but then, the logfile is processed on bursts, and not so smoothly). char *fileName = "/var/log/syslogfile"; FILE *fileDescriptor; char *ptr; char buffer[510]; /* sleep 30 seconds between log-file reads */ int sleepLength = 30; /* 20 consecutive reads with no data = frozen log file */ int maxReads = 36; int EOFile = 0; /* not yet at the end of the log file */ int whatever_procedure (void) { if ((fileDescriptor = fopen (fileName, "r")) == (FILE *) NULL) { fprintf (stderr, "Couldn't open logfile: %s\n", fileName); return (0); } /* if EOFile == 0, we're not at the end of the log file */ /* if EOFile == 1, we're at the end of the file, and read good data */ /* if EOFile > 1, it is the number of reads with no new data */ for (;;) { while (fgets (buffer, sizeof (buffer), fileDescriptor) != (char *) NULL) { /* skip ahead to the end of the logfile */ if (EOFile != 0) { /* now we're tailing the end of the logfile */ EOFile = 1; /* Now do whatever you want with the buffer[] that was read from the logfile */ } } EOFile++; if (EOFile > maxReads) /* too many reads with no data, try reopening logfile */ { fclose(fileDescriptor); if ((fileDescriptor = fopen (fileName, "r")) == (FILE *) NULL) { fprintf (stderr, "Couldn't open log file: %s\n", fileName); return (0); } EOFile = 0; } sleep (sleepLength); } }
participants (2)
-
Balazs Scheidler
-
Bradley Urberg Carlson