Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Logging to syslog #104

Open
barsema opened this issue Apr 24, 2015 · 9 comments
Open

Logging to syslog #104

barsema opened this issue Apr 24, 2015 · 9 comments
Milestone

Comments

@barsema
Copy link

barsema commented Apr 24, 2015

It would be great if we could log directly to (a remote) syslog.

@martindsouza
Copy link
Member

By remote, do you mean on the filesystem or to a 3rd party site (i.e. remove via https etc?)

What sort of output would you want to see? JSON?

@barsema
Copy link
Author

barsema commented Apr 28, 2015

We are consolidating all our logging and we are using syslog. So we have a central immutable store for logging.

http://en.wikipedia.org/wiki/Syslog

logging to the local syslog would work, because its easy to have that forwarded tot the remote syslog. But best would be to be able to use remote syslog directly.

It could work like the syslogappender of log4j

@martindsouza
Copy link
Member

Fair enough. Do you have some sample code to work off to do this?

On a side note, if we aren't able to integrate it we can always expand the plugins to all the different logging methods so you can integrate syslog logging on your specific system.

@barsema
Copy link
Author

barsema commented May 1, 2015

I found this python implementation, looks pretty straight forward... only thing im not sure about is sending UDP from oracle but i doubt that is a problem ;-)

https://liftoff.github.io/GateOne/_modules/remote_syslog.html#syslog

@martindsouza
Copy link
Member

Can you please put together a proof of concept on it?

@barsema
Copy link
Author

barsema commented May 1, 2015

Ok apparently PL/SQL does not do UDP natively, but using Java it can be done.

I've put this together something that works in my setup,
If you want to test it yourself , remember to setup the syslog server to allow remote logging

For reference these are the facilities and levels supported by syslog:

FACILITY = {
    'kern': 0, 'user': 1, 'mail': 2, 'daemon': 3,
    'auth': 4, 'syslog': 5, 'lpr': 6, 'news': 7,
    'uucp': 8, 'cron': 9, 'authpriv': 10, 'ftp': 11,
    'local0': 16, 'local1': 17, 'local2': 18, 'local3': 19,
    'local4': 20, 'local5': 21, 'local6': 22, 'local7': 23,
}

LEVEL = {
    'emerg': 0, 'alert':1, 'crit': 2, 'err': 3,
    'warning': 4, 'notice': 5, 'info': 6, 'debug': 7
}

This is my POC

create or replace and compile java source named "Syslog" as

import java.net.DatagramSocket;
import java.net.DatagramPacket;
import java.net.InetAddress;

public class Syslog {

    public static void send (String host,int port, int facility, int level,String message)
        throws java.net.SocketException, java.io.IOException {

        int pri = level + facility*8;
        String data = String.format("<%d> %s",pri, message);
        DatagramSocket s = new DatagramSocket();
        DatagramPacket p = new DatagramPacket(new byte[data.length()], data.length(), InetAddress.getByName(host), port);

        p.setData(data.getBytes());
        s.send(p);

    }

};

/

create or replace
    procedure syslog( p_host in varchar2,
                      p_port in number,
                      p_facility number, 
                      p_level number, 
                      p_message varchar2)
    as language java
    name 'Syslog.send( java.lang.String,int,int,int,java.lang.String )';
    /

-- to test    
begin

   syslog('localhost'
          ,514
          ,3 --deamon
          ,1 -- alert
          ,'Test 123');
end;
/

@barsema
Copy link
Author

barsema commented Jun 4, 2015

I created a plugin that uses the above mechanism to log to a remote syslog server, i made a pull request so you can take a look at it.

@martindsouza martindsouza added this to the Release 3.2.0 milestone Jun 4, 2015
@martindsouza
Copy link
Member

@barsema This is great! I haven't accepted your pull request yet. I want to think of some standards for 3rd party plugins. This will mainly involve preference names and function/procedure names.

As part of 3.1 we launched the set_cust_pref to store preferences with the prefix CUST_. I don't think 3rd party plugins should overload that option as CUST_ prefs should have no conflict with anything Logger sets in the logger_prefs table.

Odds are we may choose something like PLUGIN_... but don't wan to conflict with native Logger plugin settings.

I've schedule this for the 3.2 release however I will probably rename the set_cust_pref and del_cust_pref to just set_pref and del_pref with a p_pref_type parameter which will handle CUST or <3rd party plugin prefix> in the 3.1 release (#127)

@barsema
Copy link
Author

barsema commented Jun 4, 2015

That's sound terrific.

@martindsouza martindsouza modified the milestones: Release 3.2.0, 3.3.0 May 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants