Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda