[syslog-ng] How to log messages generated by C program and log file rotation

Balazs Scheidler bazsi77 at gmail.com
Wed Aug 6 16:49:18 CEST 2014


Hi,

You seem to have defined the source as a named pipe whereas the libc
usually uses a UNIX domain socket to send messages.

Why don't you simply use the system() source? Or at least define use
unix-dgram("/dev/log")
 On Aug 6, 2014 11:11 AM, "Jean Faye" <ismael.faye at yahoo.fr> wrote:

>
>
> Hi all,
> I want to use syslog-ng to log the messages generated by my application
> implemented in C language. I added this in the code:
>
>     char    *log="rtcd";
>     printf("[%s] RTC adjustement\n",__func__);
>     openlog(log, LOG_PID, LOG_LOCAL0);
>     syslog(LOG_DEBUG, "[FIJ] RTC adjustement");
>     closelog();
>
>
> For me, according to the syslog-ng file, the files
> /var/log/ldb/GENTrace.log, /var/log/ldb/SUTrace.log,
> /var/log/ldb/WANTrace.log and /var/log/ldb/CPLTrace.log must be created and
> must contain the syslog message.
> But I got no messages in my destination files. You can see the content of
> my syslog-ng.conf file bellow.
>
> Is it the right way to log the messages sent by C program? What can
> explain that I got no messages in the destinations files?
>
> I am using syslog-ng 3.5.4.1 provided by yocto. And in the script which
> run the binary (initscript file) I remove the line below:
>
> . /etc/init.d/functions
>
> Why are you using the line? Is it necessary to use it?
>
> Concerning log file rotation, How can we manage it using syslog-ng? For
> example I want to have a destination file with a size maximum = 2Mo and if
> the size is greater than the max size, I have to save the current one and
> create a new one. On my system I can have max 4 files (4 x 2Mo). How can I
> manage this kind of rotation?
>
> Thanks in advance.
> Best regards,
> Ismael Jean FAYE
>
> @version: 3.5
> #
> # Syslog-ng configuration file, compatible with default Debian syslogd
> # installation. Originally written by anonymous (I can't find his name)
> # Revised, and rewrited by me (SZALAY Attila <sasa at debian.org>)
>
> # First, set some global options.
> options { chain_hostnames(off); flush_lines(0); use_dns(no); use_fqdn(no);
>       owner("root"); group("adm"); perm(0640); stats_freq(0);
>       bad_hostname("^gconfd$");create_dirs(yes);
> };
>
> ########################
> # Sources
> ########################
>
> source s_mysource {
>     pipe("/tmp/pipe" pad_size(2048));
> };
>
> ########################
> # Destinations
> ########################
>
> destination d_GEN {
>                 file("/var/log/ldb/GENTrace.log");
> };
>
> destination d_SU {
>                 file("/var/log/ldb/SUTrace.log");
> };
>
> destination d_WAN {
>                 file("/var/log/ldb/WANTrace.log");
> };
>
> destination d_CPL {
>                 file("/var/log/ldb/CPLTrace.log");
> };
>
> ########################
> # Filters
> ########################
>
> filter f_GEN {
>                 #facility(local0) and filter(nom_du_composant_applicatif);
>                 #facility(local0) and filter(f_debug);
>                 facility(local0);
> };
>
> filter f_SU {
>                 #facility(local0) and filter(nom_du_composant_applicatif);
>                 #facility(local0) and filter(f_debug);
>                 facility(local0);
> };
>
> filter f_WAN {
>                 #facility(local0) and filter(nom_du_composant_applicatif);
>                 #facility(local0) and filter(f_debug);
>                 facility(local0);
> };
>
> filter f_CPL {
>                 #facility(local0) and filter(nom_du_composant_applicatif);
>                 #facility(local0) and filter(f_debug);
>                 facility(local0);
> };
>
> ########################
> # Log paths
> ########################
>
> log { source(s_mysource); filter(f_GEN); destination(d_GEN); };
> log { source(s_mysource); filter(f_SU); destination(d_SU); };
> log { source(s_mysource); filter(f_WAN); destination(d_WAN); };
> log { source(s_mysource); filter(f_CPL); destination(d_CPL); };
>
>
>
>
>   Le Mardi 5 août 2014 16h05, Jean Faye <ismael.faye at yahoo.fr> a écrit :
>
>
> confirm a6d843f7ad7d1dbf1fefb6f12432e54941a680a9
>
> Hi all,
> I want to use syslog-ng to log the messages generated by my application
> implemented in C language. I added this in the code:
>
>     char    *log="rtcd";
>     printf("[%s] RTC adjustement\n",__func__);
>     openlog(log, LOG_PID, LOG_LOCAL0);
>     syslog(LOG_DEBUG, "[FIJ] RTC adjustement");
>     closelog();
>
>
> For me, according to the syslog-ng file, the files
> /var/log/ldb/GENTrace.log, /var/log/ldb/SUTrace.log,
> /var/log/ldb/WANTrace.log and /var/log/ldb/CPLTrace.log must be created and
> must contain the syslog message.
> But I got no messages in my destination files. You can see the content of
> my syslog-ng.conf file bellow.
>
> Is it the right way to log the messages sent by C program? What can
> explain that I got no messages in the destinations files?
>
> Concerning log file rotation, How can we manage it using syslog-ng? For
> example I want to have a destination file with a size maximum = 2Mo and if
> the size is greater than the max size, I have to save the current one and
> create a new one. On my system I can have max 4 files (4 x 2Mo). How can I
> manage this kind of rotation?
>
> Thanks in advance.
> Best regards,
> Ismael Jean FAYE
>
> @version: 3.5
> #
> # Syslog-ng configuration file, compatible with default Debian syslogd
> # installation. Originally written by anonymous (I can't find his name)
> # Revised, and rewrited by me (SZALAY Attila <sasa at debian.org>)
>
> # First, set some global options.
> options { chain_hostnames(off); flush_lines(0); use_dns(no); use_fqdn(no);
>       owner("root"); group("adm"); perm(0640); stats_freq(0);
>       bad_hostname("^gconfd$");create_dirs(yes);
> };
>
> ########################
> # Sources
> ########################
>
> source s_mysource {
>     pipe("/tmp/pipe" pad_size(2048));
> };
>
> ########################
> # Destinations
> ########################
>
> destination d_GEN {
>                 file("/var/log/ldb/GENTrace.log");
> };
>
> destination d_SU {
>                 file("/var/log/ldb/SUTrace.log");
> };
>
> destination d_WAN {
>                 file("/var/log/ldb/WANTrace.log");
> };
>
> destination d_CPL {
>                 file("/var/log/ldb/CPLTrace.log");
> };
>
> ########################
> # Filters
> ########################
>
> #filter f_GEN {
>                 #facility(local0) and filter(nom_du_composant_applicatif);
>                 #facility(local0) and filter(f_debug);
>                 #facility(local0);
> #};
>
> filter f_SU {
>                 #facility(local0) and filter(nom_du_composant_applicatif);
>                 #facility(local0) and filter(f_debug);
>                 facility(local0);
> };
>
> filter f_WAN {
>                 #facility(local0) and filter(nom_du_composant_applicatif);
>                 #facility(local0) and filter(f_debug);
>                 facility(local0);
> };
>
> filter f_CPL {
>                 #facility(local0) and filter(nom_du_composant_applicatif);
>                 #facility(local0) and filter(f_debug);
>                 facility(local0);
> };
>
> ########################
> # Log paths
> ########################
>
> #log { source(s_mysource); filter(f_GEN); destination(d_GEN); };
> log { source(s_mysource); filter(f_SU); destination(d_SU); };
> log { source(s_mysource); filter(f_WAN); destination(d_WAN); };
> log { source(s_mysource); filter(f_CPL); destination(d_CPL); };
>
>
>
>
>
> ______________________________________________________________________________
> Member info: https://lists.balabit.hu/mailman/listinfo/syslog-ng
> Documentation:
> http://www.balabit.com/support/documentation/?product=syslog-ng
> FAQ: http://www.balabit.com/wiki/syslog-ng-faq
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.balabit.hu/pipermail/syslog-ng/attachments/20140806/ceb431df/attachment-0001.htm 


More information about the syslog-ng mailing list