1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-04 03:48:07 +02:00

generalised logs

This commit is contained in:
Jesse Duffield 2018-06-05 19:30:55 +10:00
parent 68a23f14e8
commit 0d2076c57c
3 changed files with 30 additions and 9 deletions

View File

@ -5,8 +5,10 @@ import (
// "log"
"errors"
"fmt"
"log"
"os"
"os/exec"
"os/user"
"strings"
"time"
@ -48,19 +50,30 @@ type StashEntry struct {
DisplayString string
}
func homeDirectory() string {
usr, err := user.Current()
if err != nil {
log.Fatal(err)
}
return usr.HomeDir
}
func devLog(objects ...interface{}) {
localLog(color.FgWhite, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/development.log", objects...)
localLog(color.FgWhite, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/development.log", objects...)
}
func colorLog(colour color.Attribute, objects ...interface{}) {
localLog(colour, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/development.log", objects...)
localLog(colour, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/development.log", objects...)
}
func commandLog(objects ...interface{}) {
localLog(color.FgWhite, "/Users/jesseduffieldduffield/go/src/github.com/jesseduffield/gitgot/commands.log", objects...)
localLog(color.FgWhite, homeDirectory()+"/go/src/github.com/jesseduffield/lazygit/commands.log", objects...)
}
func localLog(colour color.Attribute, path string, objects ...interface{}) {
if !debugging {
return
}
f, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
defer f.Close()
for _, object := range objects {
@ -263,11 +276,11 @@ func gitCheckout(branch string, force bool) (string, error) {
}
func runCommand(command string) (string, error) {
startTime := time.Now()
commandStartTime := time.Now()
commandLog(command)
splitCmd := strings.Split(command, " ")
cmdOut, err := exec.Command(splitCmd[0], splitCmd[1:]...).CombinedOutput()
devLog("run command time: ", time.Now().Sub(startTime))
devLog("run command time: ", time.Now().Sub(commandStartTime))
return string(cmdOut), err
}

14
main.go
View File

@ -1,15 +1,23 @@
package main
import (
"flag"
"fmt"
"time"
)
// StartTime : The starting time of the app
var StartTime time.Time
var (
startTime time.Time
debugging bool
)
func main() {
debuggingPointer := flag.Bool("debug", false, "a boolean")
flag.Parse()
debugging = *debuggingPointer
fmt.Println(homeDirectory() + "/go/src/github.com/jesseduffield/lazygit/development.log")
devLog("\n\n\n\n\n\n\n\n\n\n")
StartTime = time.Now()
startTime = time.Now()
verifyInGitRepo()
run()
}

View File

@ -28,7 +28,7 @@ func refreshStatus(g *gocui.Gui) error {
// utilising the fact these all have padding to only grab the name
// from the display string with the existing coloring applied
fmt.Fprint(v, " "+branch.DisplayString[4:])
colorLog(color.FgCyan, time.Now().Sub(StartTime))
colorLog(color.FgCyan, time.Now().Sub(startTime))
return nil
})