mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-06-19 00:28:03 +02:00
generalised logs
This commit is contained in:
@ -5,8 +5,10 @@ import (
|
|||||||
// "log"
|
// "log"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"os/user"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -48,19 +50,30 @@ type StashEntry struct {
|
|||||||
DisplayString string
|
DisplayString string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func homeDirectory() string {
|
||||||
|
usr, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
return usr.HomeDir
|
||||||
|
}
|
||||||
|
|
||||||
func devLog(objects ...interface{}) {
|
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{}) {
|
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{}) {
|
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{}) {
|
func localLog(colour color.Attribute, path string, objects ...interface{}) {
|
||||||
|
if !debugging {
|
||||||
|
return
|
||||||
|
}
|
||||||
f, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
|
f, _ := os.OpenFile(path, os.O_APPEND|os.O_WRONLY, 0644)
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
for _, object := range objects {
|
for _, object := range objects {
|
||||||
@ -263,11 +276,11 @@ func gitCheckout(branch string, force bool) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func runCommand(command string) (string, error) {
|
func runCommand(command string) (string, error) {
|
||||||
startTime := time.Now()
|
commandStartTime := time.Now()
|
||||||
commandLog(command)
|
commandLog(command)
|
||||||
splitCmd := strings.Split(command, " ")
|
splitCmd := strings.Split(command, " ")
|
||||||
cmdOut, err := exec.Command(splitCmd[0], splitCmd[1:]...).CombinedOutput()
|
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
|
return string(cmdOut), err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
main.go
14
main.go
@ -1,15 +1,23 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"flag"
|
||||||
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StartTime : The starting time of the app
|
var (
|
||||||
var StartTime time.Time
|
startTime time.Time
|
||||||
|
debugging bool
|
||||||
|
)
|
||||||
|
|
||||||
func main() {
|
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")
|
devLog("\n\n\n\n\n\n\n\n\n\n")
|
||||||
StartTime = time.Now()
|
startTime = time.Now()
|
||||||
verifyInGitRepo()
|
verifyInGitRepo()
|
||||||
run()
|
run()
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ func refreshStatus(g *gocui.Gui) error {
|
|||||||
// utilising the fact these all have padding to only grab the name
|
// utilising the fact these all have padding to only grab the name
|
||||||
// from the display string with the existing coloring applied
|
// from the display string with the existing coloring applied
|
||||||
fmt.Fprint(v, " "+branch.DisplayString[4:])
|
fmt.Fprint(v, " "+branch.DisplayString[4:])
|
||||||
colorLog(color.FgCyan, time.Now().Sub(StartTime))
|
colorLog(color.FgCyan, time.Now().Sub(startTime))
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user