grokkit/internal/logger/logger.go
Greg Gauthier e355142c05 feat: add CI/CD workflows, persistent chat, shell completions, and testing
- Add Gitea CI workflow for testing, linting, and building
- Add release workflow for multi-platform builds and GitHub releases
- Implement persistent chat history with JSON storage
- Add shell completion generation for bash, zsh, fish, powershell
- Introduce custom error types and logging system
- Add interfaces for git and AI client for better testability
- Enhance config with temperature and timeout settings
- Add comprehensive unit tests for config, errors, git, grok, and logger
- Update README with installation, features, and development instructions
- Make model flag persistent across commands
- Add context timeouts to API requests
2026-03-01 12:17:22 +00:00

57 lines
1.2 KiB
Go

package logger
import (
"fmt"
"log"
"os"
"path/filepath"
)
var (
infoLog *log.Logger
errorLog *log.Logger
debugLog *log.Logger
)
func Init() error {
home, err := os.UserHomeDir()
if err != nil {
home = "."
}
logDir := filepath.Join(home, ".config", "grokkit")
if err := os.MkdirAll(logDir, 0755); err != nil {
return fmt.Errorf("failed to create log directory: %w", err)
}
logFile := filepath.Join(logDir, "grokkit.log")
file, err := os.OpenFile(logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0644)
if err != nil {
return fmt.Errorf("failed to open log file: %w", err)
}
infoLog = log.New(file, "INFO: ", log.Ldate|log.Ltime|log.Lshortfile)
errorLog = log.New(file, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
debugLog = log.New(file, "DEBUG: ", log.Ldate|log.Ltime|log.Lshortfile)
return nil
}
func Info(format string, v ...interface{}) {
if infoLog != nil {
infoLog.Output(2, fmt.Sprintf(format, v...))
}
}
func Error(format string, v ...interface{}) {
if errorLog != nil {
errorLog.Output(2, fmt.Sprintf(format, v...))
}
}
func Debug(format string, v ...interface{}) {
if debugLog != nil {
debugLog.Output(2, fmt.Sprintf(format, v...))
}
}