Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Send log to Rsyslog server with go

I write a code to send log to rsyslog server on ubuntu, the code has below content. In the file ryslogd.conf I have configured local7.* /var/log/test.log.*But when running, the log is not written to the test.log *

package main
import (
        "errors"
        "fmt"
        "log/syslog"
        "os"
        "path/filepath"
)

func main() {
        programName := filepath.Base(os.Args[0])
        fmt.Println(programName)
        syslog_pointer, err := syslog.Dial("udp", "localhost:514", syslog.LOG_WARNING|syslog.LOG_LOCAL7, "test")
        if err != nil {
                err_exception := errors.New("Can't connect to syslog server localhost:514")
                fmt.Println(err_exception)
                os.Exit(1)
        } else {
                syslog_pointer.Emerg("This is log test")
        }
}

I want the log line: this is test log to be written to the file /var/log/test.log

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Local logging is typically via a Unix socket. UDP logging typically needs to be explicitly enabled for the Syslog server.

Creating the syslog.Writer via syslog.New will attempt to connect via common Unix sockets first, then attempt UDP via localhost:

package main

import (
    "log"
    "log/syslog"
)

func main() {
    s, err := syslog.New(syslog.LOG_WARNING|syslog.LOG_LOCAL7, "test")
    if err != nil {
        log.Fatal(err)
    }
    
    s.Emerg("log test")
}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!