- 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
58 lines
1.1 KiB
Go
58 lines
1.1 KiB
Go
package config
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
func Load() {
|
|
home, err := os.UserHomeDir()
|
|
if err != nil {
|
|
// Fall back to current directory if home not found
|
|
home = "."
|
|
}
|
|
configPath := filepath.Join(home, ".config", "grokkit")
|
|
|
|
viper.SetConfigName("config")
|
|
viper.SetConfigType("toml")
|
|
viper.AddConfigPath(configPath)
|
|
viper.AddConfigPath(".")
|
|
viper.AutomaticEnv()
|
|
|
|
viper.SetDefault("default_model", "grok-4")
|
|
viper.SetDefault("temperature", 0.7)
|
|
viper.SetDefault("log_level", "info")
|
|
viper.SetDefault("timeout", 60)
|
|
|
|
// Config file is optional, so we ignore read errors
|
|
_ = viper.ReadInConfig()
|
|
}
|
|
|
|
func GetModel(flagModel string) string {
|
|
if flagModel != "" {
|
|
if alias := viper.GetString("aliases." + flagModel); alias != "" {
|
|
return alias
|
|
}
|
|
return flagModel
|
|
}
|
|
return viper.GetString("default_model")
|
|
}
|
|
|
|
func GetTemperature() float64 {
|
|
return viper.GetFloat64("temperature")
|
|
}
|
|
|
|
func GetTimeout() int {
|
|
timeout := viper.GetInt("timeout")
|
|
if timeout <= 0 {
|
|
return 60 // Default 60 seconds
|
|
}
|
|
return timeout
|
|
}
|
|
|
|
func GetLogLevel() string {
|
|
return viper.GetString("log_level")
|
|
}
|