Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda