sirupsen / logrus

Structured, pluggable logging for Go.
MIT License
24.8k stars 2.27k forks source link

Running logrus in goland does not display properly #1335

Closed hkhk367 closed 2 years ago

hkhk367 commented 2 years ago

I'm not sure if this is a logrus problem, but if not I'll report the bug on goland.

After clicking the run button on goland, there is a lot of blank space on the right side of the output window, whereas this problem does not occur with fmt.Println() or other libraries.

When I run with "go run .", logrus does not have this problem.

Is this a logrus problem or a goland problem? Thank you. image image

The following are parts of my codes.

package main

import (
    "github.com/mattn/go-colorable"
    "github.com/sirupsen/logrus"
    "github.com/snowzach/rotatefilehook"
    "stress_test/rotatefilehooksinglelevel"
    "time"
)

func InitLogger() {
    var logLevel = logrus.InfoLevel

    rotateFileHook, err := rotatefilehook.NewRotateFileHook(rotatefilehook.RotateFileConfig{
        Filename:   "logs/log.log",
        MaxSize:    2000, // megabytes
        MaxBackups: 3,
        MaxAge:     28, //days
        Level:      logLevel,
        Formatter: &logrus.JSONFormatter{
            TimestampFormat: time.RFC822,
        },
    })

    if err != nil {
        logrus.Fatalf("Failed to initialize file rotate hook: %v", err)
    }

    logrus.SetLevel(logLevel)
    logrus.SetOutput(colorable.NewColorableStdout())
    logrus.SetFormatter(&logrus.TextFormatter{
        ForceColors:     true,
        FullTimestamp:   true,
        TimestampFormat: time.RFC822,
    })
    logrus.SetReportCaller(true)
    logrus.AddHook(rotateFileHook)

}
func init() {
    InitLogger()
}
func main() {
    logrus.Info("info")
    logrus.Debug("Debug")
    logrus.Warn("warning")
    logrus.Error("error")
}
wgd-ah commented 2 years ago

Similarly, we've noticed problems running logrus in K8S/Docker environments, where the error is generated from logrus, not from the file/location where the error apparently occurred. I say, "similarly", since GoLand runs in a mock env.

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed because it has been inactive for 14 days since being marked as stale.