12 "github.com/charmbracelet/crush/internal/event"
13 "gopkg.in/natefinch/lumberjack.v2"
18 initialized atomic.Bool
21func Setup(logFile string, debug bool) {
23 logRotator := &lumberjack.Logger{
25 MaxSize: 10, // Max size in MB
26 MaxBackups: 0, // Number of backups
28 Compress: false, // Enable compression
31 level := slog.LevelInfo
33 level = slog.LevelDebug
36 logger := slog.NewJSONHandler(logRotator, &slog.HandlerOptions{
41 slog.SetDefault(slog.New(logger))
42 initialized.Store(true)
46func Initialized() bool {
47 return initialized.Load()
50func RecoverPanic(name string, cleanup func()) {
51 if r := recover(); r != nil {
52 event.Error(r, "panic", true, "name", name)
54 // Create a timestamped panic log file
55 timestamp := time.Now().Format("20060102-150405")
56 filename := fmt.Sprintf("crush-panic-%s-%s.log", name, timestamp)
58 file, err := os.Create(filename)
62 // Write panic information and stack trace
63 fmt.Fprintf(file, "Panic in %s: %v\n\n", name, r)
64 fmt.Fprintf(file, "Time: %s\n\n", time.Now().Format(time.RFC3339))
65 fmt.Fprintf(file, "Stack Trace:\n%s\n", debug.Stack())
67 // Execute cleanup function if provided
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list