Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package syslogclient
- import (
- "os";
- "fmt";
- "net";
- "strings";
- )
- const (
- 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;
- )
- const (
- EMERGENCY = 0;
- ALERT = 1;
- CRITICAL = 2;
- ERROR = 3;
- WARNING = 4;
- NOTICE = 5;
- INFO = 6;
- DEBUG = 7;
- )
- /*
- * Send syslog UDP packet to given host and port.
- */
- func Log(message string, level byte, facility byte, host string, port int16) (err os.Error) {
- var addr *net.UDPAddr;
- var conn *net.UDPConn;
- data := fmt.Sprintf("<%d>%s", level + facility * 8, message);
- buf := strings.Bytes(data);
- if addr, err = net.ResolveUDPAddr(host); err != nil {
- return;
- }
- if conn, err = net.DialUDP("udp", nil, addr); err != nil {
- return;
- }
- if err = conn.SetWriteTimeout(5 * 1000000000); err != nil {
- return;
- }
- if _, err = conn.Write(buf); err != nil {
- return;
- }
- err = conn.Close();
- return;
- }
Add Comment
Please, Sign In to add comment