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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMPROVEMENT] Unify logs with extra static info like module/method/function/line #5509

Closed
innobead opened this issue Mar 8, 2023 · 3 comments
Assignees
Labels
area/troubleshoot Troubleshoot related backport/1.4.4 backport/1.5.2 kind/improvement Request for improvement of existing function priority/0 Must be fixed in this release (managed by PO)
Milestone

Comments

@innobead
Copy link
Member

innobead commented Mar 8, 2023

Is your improvement request related to a feature? Please describe (馃憤 if you like this request)

Currently, in longhorn components' logs, there is no module, function, or line info to quickly identify the code. Usually, we will rely on the message to look up the potential code place. It's better to have logs with that info for troubleshooting purposes.

Describe the solution you'd like

Can leverage CallerPrettyfier to achieve the goal, and apply to all components and libraries.

package log
import (
 "fmt"
 "runtime"
 "strings"
"github.com/sirupsen/logrus"
)
func init() {
 logrus.SetReportCaller(true)
 formatter := &logrus.TextFormatter{
  TimestampFormat:        "02-01-2006 15:04:05", // the "time" field configuratiom
  FullTimestamp:          true, 
  DisableLevelTruncation: true, // log level field configuration
  CallerPrettyfier: func(f *runtime.Frame) (string, string) { 
   return "", fmt.Sprintf("%s:%d", formatFilePath(f.File), f.Line)
  },
 }
 logrus.SetFormatter(formatter)
}
func formatFilePath(path string) string {
 arr := strings.Split(path, "/")
 return arr[len(arr)-1]
}

Additional context

N/A

@innobead innobead added kind/improvement Request for improvement of existing function area/troubleshoot Troubleshoot related labels Mar 8, 2023
@innobead innobead added this to the v1.5.0 milestone Mar 8, 2023
@innobead innobead added the priority/2 Nice to fix in this release (managed by PO) label Mar 8, 2023
@innobead innobead added priority/0 Must be fixed in this release (managed by PO) and removed priority/2 Nice to fix in this release (managed by PO) labels Apr 13, 2023
@innobead innobead modified the milestones: v1.5.0, v1.6.0 May 3, 2023
@longhorn-io-github-bot
Copy link

longhorn-io-github-bot commented Oct 19, 2023

Pre Ready-For-Testing Checklist

@innobead
Copy link
Member Author

@ChanYiLin let's apply this to all components.

@roger-ryao
Copy link

Verified on master-head 20231024

The test steps

#5509 (comment)

Result Passed

  • We can see that there are two additional fields in the log: func, file

Screenshot_20231024_113633

@innobead innobead mentioned this issue Oct 24, 2023
14 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/troubleshoot Troubleshoot related backport/1.4.4 backport/1.5.2 kind/improvement Request for improvement of existing function priority/0 Must be fixed in this release (managed by PO)
Projects
None yet
Development

No branches or pull requests

4 participants