Skip to content

logrus_syslog ignoring log level #1369

@tommyblue

Description

@tommyblue

Following the docs at https://github.com/sirupsen/logrus/#hooks I'm trying to use an external syslog server to send only WARNING (and above) logs there, while sending debug to local logs. Unfortunately it doesn't seem to work. The external syslog server receives whatever I setup with log.SetLevel() instead of the priority argument passed to logrus_syslog.NewSyslogHook.

Am I doing anything wrong here? Maybe I misinterpreted the docs?

package main

import (
	log "github.com/sirupsen/logrus"
	logrus_syslog "github.com/sirupsen/logrus/hooks/syslog"
)

func main() {
	log.SetLevel(log.DebugLevel)

	hook, err := logrus_syslog.NewSyslogHook("tcp", "localhost:5140", syslog.LOG_WARNING, "test")
	if err != nil {
		panic(err)
	}
	log.AddHook(hook)

	// These 2 should go both to local and remote logs
	log.Warn("ciao with warn")
	log.Error("ciao with error")
	
	// These should only go to local logs and not to external syslog,
	// but instead they're shown there too :(
	log.Debug("ciao with debug")
	log.Info("ciao with info")
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions