Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syslog hook doesn't log anything #82

Closed
vincentbernat opened this issue Nov 18, 2014 · 6 comments · Fixed by #84
Closed

Syslog hook doesn't log anything #82

vincentbernat opened this issue Nov 18, 2014 · 6 comments · Fixed by #84

Comments

@vincentbernat
Copy link
Contributor

Hi!

The syslog hook doesn't log anything unless a field "level" is set by the user.

It can be corrected by using entry.Level.String() in syslog.go. However, in this case, logging is done with ANSI codes (I get something like this: #033[34mINFO#033[0m[0000] proxy: start serving requests).

@sirupsen
Copy link
Owner

Quite true. The default formatters set this. The hook then switches on the level. Did you write your own?

@vincentbernat
Copy link
Contributor Author

I didn't set a customer formatter. I am doing that:

log.SetOutput(os.Stderr)
log.SetLevel(log.WarnLevel)
log.SetLevel(log.DebugLevel)
log.WithField("file", "something").
                Debug("main: parsing configuration file")
syslogOutput, err := logrus_syslog.NewSyslogHook("", "",
                 syslog.LOG_INFO|syslog.LOG_DAEMON, "")
if err != nil {
                  log.Fatal("main: unable to setup syslog output")
}
log.AddHook(syslogOutput)
log.WithField("listen", "something").
                Info("proxy: start serving requests")

@sirupsen
Copy link
Owner

Did you try debugging it from the hook? That seems strange.

@vincentbernat
Copy link
Contributor Author

❦ 23 novembre 2014 07:14 -0800, Simon Eskildsen notifications@github.com :

Why are you setting the level twice?

That's a partial code. I am checking if user asked for more debug and
then check to debug. It was just to show you that I may doing
"inappropriate" stuff like start logging stuff before setting the syslog

hook.

/* Thanks to Rob `CmdrTaco' Malda for not influencing this code in any

  • way.
    */
    2.4.3 linux/net/core/netfilter.c

@vincentbernat
Copy link
Contributor Author

Here is a self contained example:

package main

import (
        log "github.com/Sirupsen/logrus"
        "github.com/Sirupsen/logrus/hooks/syslog"
        "log/syslog"
    "os"
)

func main() {
        /* Setup initial logging */
        log.SetOutput(os.Stderr)
    log.SetLevel(log.DebugLevel)
    syslogOutput, err := logrus_syslog.NewSyslogHook("", "",
        syslog.LOG_INFO|syslog.LOG_DAEMON, "")
    if err != nil {
        log.Fatal("main: unable to setup syslog output")
    }
    log.AddHook(syslogOutput)
    log.Debug("main: this should go to syslog")
}

If I leave syslog.go unchanged, nothing gets logged to syslog. It seems that this is the same problem as with #72. I'll do a pull request for that in a few minutes.

Once fixed, I still have that in syslog:

Nov 23 17:53:23 neo ./test1[31584]: #033[34mDEBU#033[0m[0000] main: this should go to syslog

I wouldn't expect the formatter to be attached only to a given output.

vincentbernat added a commit to vincentbernat/logrus that referenced this issue Nov 23, 2014
Log level has moved from `entry.Data["level"]` to `entry.Level`. Use
that to get the right level.

Fix: sirupsen#82
@sirupsen
Copy link
Owner

Fixed by #84

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants