diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0b9a6ee5d..33dbbbfbf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -73,12 +73,34 @@ Boy that's a hard word to spell. Anyway, lazygit is translated into several lang The easiest way to debug lazygit is to have two terminal tabs open at once: one for running lazygit (via `go run main.go -debug` in the project root) and one for viewing lazygit's logs (which can be done via `go run main.go --logs` or just `lazygit --logs`). -From most places in the codebase you have access to a logger e.g. `gui.Log.Warn("blah")` +From most places in the codebase you have access to a logger e.g. `gui.Log.Warn("blah")`. If you find that the existing logs are too noisy, you can set the log level with e.g. `LOG_LEVEL=warn go run main.go -debug` and then only use `Warn` logs yourself. +If you need to log from code in the vendor directory (e.g. the `gocui` package), you won't have access to the logger, but you can easily add logging support by adding the following: +```go +func newLogger() *logrus.Entry { + // REPLACE THE BELOW PATH WITH YOUR ACTUAL LOG PATH (YOU'LL SEE THIS PRINTED WHEN YOU RUN `lazygit --logs` + logPath := "/Users/jesseduffield/Library/Application Support/jesseduffield/lazygit/development.log" + file, err := os.OpenFile(logPath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) + if err != nil { + panic("unable to log to file") + } + logger := logrus.New() + logger.SetLevel(logrus.WarnLevel) + logger.SetOutput(file) + return logger.WithFields(logrus.Fields{}) +} + +var Log = newLogger() +... +Log.Warn("blah") +``` + If you keep having to do some setup steps to reproduce an issue, read the Testing section below to see how to create an integration test by recording a lazygit session. It's pretty easy! +### VSCode debugger + If you want to trigger a debug session from VSCode, you can use the following snippet. Note that the `console` key is, at the time of writing, still an experimental feature. ```jsonc