grokkit/internal/git/git.go
Greg Gauthier 8b6449c947 feat(logging): implement structured logging with slog
- Refactor logger package to use Go's slog for JSON-structured logs
- Add configurable log levels (debug, info, warn, error) via config and flags
- Integrate logging across commands, git operations, and API client with metrics like timing and sizes
- Update README with logging documentation and usage examples
- Add global --debug and --verbose flags
- Enhance tests for logger initialization, levels, and structured output
2026-03-01 12:35:21 +00:00

38 lines
865 B
Go

package git
import (
"fmt"
"os/exec"
"strings"
"gmgauthier.com/grokkit/internal/logger"
)
func Run(args []string) (string, error) {
cmdStr := "git " + strings.Join(args, " ")
logger.Debug("executing git command", "command", cmdStr, "args", args)
out, err := exec.Command("git", args...).Output()
if err != nil {
logger.Error("git command failed",
"command", cmdStr,
"error", err)
return "", fmt.Errorf("git command failed: %w", err)
}
outputLen := len(out)
logger.Debug("git command completed",
"command", cmdStr,
"output_length", outputLen)
return string(out), nil
}
func IsRepo() bool {
logger.Debug("checking if directory is a git repository")
_, err := exec.Command("git", "rev-parse", "--is-inside-work-tree").Output()
isRepo := err == nil
logger.Debug("git repository check completed", "is_repo", isRepo)
return isRepo
}