summaryrefslogtreecommitdiffstats
path: root/CONTRIBUTING.md
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2023-05-25 18:18:35 +1000
committerJesse Duffield <jessedduffield@gmail.com>2023-05-25 18:31:32 +1000
commite0ecc9e835ef56fae7ee58408ba91e29f000344d (patch)
tree94308647a248d326c1e0cdb863623cfe63b7d66b /CONTRIBUTING.md
parent1f8e838052a1bc083cb50560431b2f115df8acb6 (diff)
Allow global logging when developing
I'll be honest, for all I know logging should be global in general: it is a pain to pass a logger to any struct that needs it. But smart people on the internet tell me otherwise, and I do like the idea of not having any global variables lying around. Nonetheless, I often need to log things when locally debugging and that's a different kind of logging than the kind you would include in the actual released binary. For example if I want to log something from gocui, I would rather not have gocui depend on lazygit's logging setup.
Diffstat (limited to 'CONTRIBUTING.md')
-rw-r--r--CONTRIBUTING.md23
1 files changed, 2 insertions, 21 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 0bfee5686..bed0a124a 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -105,30 +105,11 @@ 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")` or `self.c.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 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 setting the `LAZYGIT_LOG_PATH` environment variable and using `logs.Global.Warn("blah")`. This is a global logger that's only intended for development purposes.
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!