summaryrefslogtreecommitdiffhomepage
path: root/internal/logging
diff options
context:
space:
mode:
authoradamdottv <[email protected]>2025-05-08 12:03:59 -0500
committeradamdottv <[email protected]>2025-05-08 12:03:59 -0500
commitf41b7bbd0a0cc731fd7c471b7ee8b26f14a21755 (patch)
treebd34e77a07516735a220c210d4930fbe2132a63b /internal/logging
parente35ea2d448d1a3c9cf0a6fba1318e522fc61d1eb (diff)
downloadopencode-f41b7bbd0a0cc731fd7c471b7ee8b26f14a21755.tar.gz
opencode-f41b7bbd0a0cc731fd7c471b7ee8b26f14a21755.zip
chore: refactoring status updates
Diffstat (limited to 'internal/logging')
-rw-r--r--internal/logging/logger.go34
-rw-r--r--internal/logging/message.go12
-rw-r--r--internal/logging/writer.go23
3 files changed, 20 insertions, 49 deletions
diff --git a/internal/logging/logger.go b/internal/logging/logger.go
index 7ae2e7b87..31462a542 100644
--- a/internal/logging/logger.go
+++ b/internal/logging/logger.go
@@ -6,6 +6,8 @@ import (
"os"
"runtime/debug"
"time"
+
+ "github.com/opencode-ai/opencode/internal/status"
)
func Info(msg string, args ...any) {
@@ -24,33 +26,15 @@ func Error(msg string, args ...any) {
slog.Error(msg, args...)
}
-func InfoPersist(msg string, args ...any) {
- args = append(args, persistKeyArg, true)
- slog.Info(msg, args...)
-}
-
-func DebugPersist(msg string, args ...any) {
- args = append(args, persistKeyArg, true)
- slog.Debug(msg, args...)
-}
-
-func WarnPersist(msg string, args ...any) {
- args = append(args, persistKeyArg, true)
- slog.Warn(msg, args...)
-}
-
-func ErrorPersist(msg string, args ...any) {
- args = append(args, persistKeyArg, true)
- slog.Error(msg, args...)
-}
-
// RecoverPanic is a common function to handle panics gracefully.
// It logs the error, creates a panic log file with stack trace,
// and executes an optional cleanup function before returning.
func RecoverPanic(name string, cleanup func()) {
if r := recover(); r != nil {
// Log the panic
- ErrorPersist(fmt.Sprintf("Panic in %s: %v", name, r))
+ errorMsg := fmt.Sprintf("Panic in %s: %v", name, r)
+ Error(errorMsg)
+ status.Error(errorMsg)
// Create a timestamped panic log file
timestamp := time.Now().Format("20060102-150405")
@@ -58,7 +42,9 @@ func RecoverPanic(name string, cleanup func()) {
file, err := os.Create(filename)
if err != nil {
- ErrorPersist(fmt.Sprintf("Failed to create panic log: %v", err))
+ errMsg := fmt.Sprintf("Failed to create panic log: %v", err)
+ Error(errMsg)
+ status.Error(errMsg)
} else {
defer file.Close()
@@ -67,7 +53,9 @@ func RecoverPanic(name string, cleanup func()) {
fmt.Fprintf(file, "Time: %s\n\n", time.Now().Format(time.RFC3339))
fmt.Fprintf(file, "Stack Trace:\n%s\n", debug.Stack())
- InfoPersist(fmt.Sprintf("Panic details written to %s", filename))
+ infoMsg := fmt.Sprintf("Panic details written to %s", filename)
+ Info(infoMsg)
+ status.Info(infoMsg)
}
// Execute cleanup function if provided
diff --git a/internal/logging/message.go b/internal/logging/message.go
index 30ae8f379..b8a42d966 100644
--- a/internal/logging/message.go
+++ b/internal/logging/message.go
@@ -6,13 +6,11 @@ import (
// LogMessage is the event payload for a log message
type LogMessage struct {
- ID string
- Time time.Time
- Level string
- Persist bool // used when we want to show the mesage in the status bar
- PersistTime time.Duration // used when we want to show the mesage in the status bar
- Message string `json:"msg"`
- Attributes []Attr
+ ID string
+ Time time.Time
+ Level string
+ Message string `json:"msg"`
+ Attributes []Attr
}
type Attr struct {
diff --git a/internal/logging/writer.go b/internal/logging/writer.go
index 4cb89f24f..7191f7720 100644
--- a/internal/logging/writer.go
+++ b/internal/logging/writer.go
@@ -13,11 +13,6 @@ import (
)
const (
- persistKeyArg = "$_persist"
- PersistTimeArg = "$_persist_time"
-)
-
-const (
// Maximum number of log messages to keep in memory
maxLogMessages = 1000
)
@@ -76,20 +71,10 @@ func (w *writer) Write(p []byte) (int, error) {
case "msg":
msg.Message = string(d.Value())
default:
- if string(d.Key()) == persistKeyArg {
- msg.Persist = true
- } else if string(d.Key()) == PersistTimeArg {
- parsed, err := time.ParseDuration(string(d.Value()))
- if err != nil {
- continue
- }
- msg.PersistTime = parsed
- } else {
- msg.Attributes = append(msg.Attributes, Attr{
- Key: string(d.Key()),
- Value: string(d.Value()),
- })
- }
+ msg.Attributes = append(msg.Attributes, Attr{
+ Key: string(d.Key()),
+ Value: string(d.Value()),
+ })
}
}
defaultLogData.Add(msg)