logrus icon indicating copy to clipboard operation
logrus copied to clipboard

`entry.Log(logrus.FatalLevel, "fatal level")` doesn't call `logger.Exit(1)`

Open dlsrb6342 opened this issue 2 years ago • 5 comments

  • I found a bug that entry.Log doesn't call logger.Exit(1).
  • If I call entry.Log with logrus.FatalLevel, system doesn't exit.

dlsrb6342 avatar Aug 02 '22 03:08 dlsrb6342

in entry.log only level <= PanicLevel will lead to panic

image

FatalLevel is bigger than PanicLevel

image

fatelei avatar Aug 09 '22 05:08 fatelei

I mean System.Exit(1) not panic. As second picture that you attatched, FatalLevel should calls logger.Exit(1)

dlsrb6342 avatar Aug 09 '22 05:08 dlsrb6342

I mean System.Exit(1) not panic. As second picture that you attatched, FatalLevel should calls logger.Exit(1)

I have check the code,this is a demo,work as expect.

fatelei avatar Aug 09 '22 07:08 fatelei

check this demo. As I described in issue, I call entry.Log(log.FatalLevel, "fatal") but it didn't call System.Exit(1)

dlsrb6342 avatar Aug 09 '22 08:08 dlsrb6342

i read the code

  • call entry.Fatal this function will call entry.logger.Exit
  • call entry.Log, this function only panic when level <= PanicLevel, so it with FatalLevel will not exit program.

Maybe this is by design @sirupsen

Anyway, if this is a bug, i can fix it

fatelei avatar Aug 09 '22 08:08 fatelei

This is not a bug. It works as documented:

~/src/logrus$ go doc . Entry.Log
package logrus // import "github.com/sirupsen/logrus"

func (entry *Entry) Log(level Level, args ...interface{})
    Log will log a message at the level given as parameter. Warning: using Log
    at Panic or Fatal level will not respectively Panic nor Exit. For this
    behaviour Entry.Panic or Entry.Fatal should be used instead.

dgsb avatar Aug 12 '22 12:08 dgsb