1

This is my first question on StackOverflow so forgive me if I accidentally break some rules.

What I am trying to do is have a program write a simple log and have syslog-ng read that log and then write to another file.

This input log file is a file containing random numbers.

Here is the content of my syslog-ng.conf file.

source s_file
{
        file("/home/vagrant/test1.log" follow-freq(1) flags(no_parse));
};

destination d_file
{
        file("/home/vagrant/poc.db");
};

log
{
        source(s_file);
        destination(d_file);
}

Here is the source of the program generating the random number.

import java.util.*;
import java.io.*;

public class loggerSpam{

    PrintWriter out;

    public loggerSpam() {
            try {
                    out = new PrintWriter(new FileWriter("test1.log"));
            } catch (Exception e) {
                    System.out.println("Caught");
            }finally {
                    System.out.println("Constructor");
            }
     }

     public void spam() {
            Random rand = new Random();

            try {
                    for (int i = 0; i < 10; i++) {
                            int num = rand.nextInt(10);
                            String msg = Integer.toString(num) + "\n";
                            System.out.print(msg);
                            out.write(msg);
                    }
                    out.close();

            } catch (Exception e) {
                    System.out.println(e.toString());
            }
                    }

    public static void main(String args[]){

            //Create spammer object
            loggerSpam testObj = new loggerSpam();
            //spam test.log
            testObj.spam();

    }
}

My understanding is that if I place my config file in /etc/syslog-ng/ then restart syslog-ng service, all I need to do is run my program and syslog-ng should be able to detect that there was a log file generated. Once the log file is generated syslog will read the log and write to my destination file poc.db.

However, my issue is that syslog-ng is not reading test1.log nor is it generating poc.db. Can someone explain why this is? What can I change? From the guides on syslog-ng's website, I need to be able to write files locally so I can debug other issues.

Thank you for any help!

  • Hi, try to run 'syslog-ng -Fevd' to see if there are any error messages or warnings. My guess is that since you are not writing proper syslog messages into the file, only some random strings, syslog-ng does not recognize them as log messages and ignores them. If that's the case, add the flags(no-parse) option to your source. – Robert Fekete Oct 05 '16 at 06:58
  • I have removed all .conf except this one. It seems I have a few syntax error. All the other conf files were drowning my cmd with messages and I was not able to see those errors. Thanks Robert. – Bandith Phommounivong Oct 05 '16 at 18:30
  • You're welcome! I'm glad that it worked. – Robert Fekete Oct 06 '16 at 06:21

1 Answers1

0

Try this :

First create empty test1.log file with all (read/write/exec) permission because while starting syslog-ng server first it checks source file for fetching log.

After that if you append text in file, syslog-ng will treat it as logs..

Nirav Mistry
  • 949
  • 5
  • 15