From 1f6ce1ca5f7e70c8ec1cdf4d88fec32f62000446 Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Fri, 19 Dec 2025 23:01:19 +0100 Subject: [PATCH] chore: move logging to its own package so can be shared across repos Signed-off-by: Ettore Di Giacinto --- core/action/custom.go | 2 +- core/agent/actions.go | 2 +- core/agent/agent.go | 2 +- core/agent/agent_test.go | 2 +- core/agent/knowledgebase.go | 2 +- core/agent/mcp.go | 2 +- core/agent/observer.go | 2 +- core/conversations/conversationstracker.go | 2 +- core/state/pool.go | 2 +- core/types/observable.go | 4 +- go.mod | 1 + go.sum | 2 + pkg/llm/json.go | 2 +- pkg/localrag/client.go | 2 +- pkg/xlog/xlog.go | 71 ------------------- services/actions.go | 2 +- services/actions/githubissuelabeler.go | 2 +- services/actions/githubissuesearch.go | 2 +- services/actions/githubprreviewer.go | 2 +- .../actions/githubrepositorygetallcontent.go | 2 +- services/common.go | 2 +- services/connectors.go | 2 +- services/connectors/discord.go | 2 +- services/connectors/email.go | 2 +- services/connectors/githubissue.go | 2 +- services/connectors/githubpr.go | 2 +- services/connectors/irc.go | 2 +- services/connectors/matrix.go | 2 +- services/connectors/slack.go | 2 +- services/connectors/telegram.go | 2 +- services/connectors/twitter.go | 2 +- services/filters.go | 2 +- services/prompts.go | 2 +- services/prompts/custom.go | 2 +- tests/e2e/e2e_test.go | 2 +- webui/app.go | 2 +- webui/routes.go | 2 +- webui/types/openai.go | 2 +- 38 files changed, 39 insertions(+), 107 deletions(-) delete mode 100644 pkg/xlog/xlog.go diff --git a/core/action/custom.go b/core/action/custom.go index 03b6ade4..62ac82b8 100644 --- a/core/action/custom.go +++ b/core/action/custom.go @@ -9,7 +9,7 @@ import ( "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai/jsonschema" "github.com/traefik/yaegi/interp" "github.com/traefik/yaegi/stdlib" diff --git a/core/agent/actions.go b/core/agent/actions.go index 5982460c..096293b1 100644 --- a/core/agent/actions.go +++ b/core/agent/actions.go @@ -8,7 +8,7 @@ import ( "github.com/mudler/LocalAGI/core/types" "golang.org/x/exp/slices" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/core/agent/agent.go b/core/agent/agent.go index 879c8164..640cb184 100644 --- a/core/agent/agent.go +++ b/core/agent/agent.go @@ -14,8 +14,8 @@ import ( "time" "github.com/modelcontextprotocol/go-sdk/mcp" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/cogito" + "github.com/mudler/xlog" "github.com/mudler/LocalAGI/core/action" "github.com/mudler/LocalAGI/core/types" diff --git a/core/agent/agent_test.go b/core/agent/agent_test.go index c32d5e7b..c4e49f2f 100644 --- a/core/agent/agent_test.go +++ b/core/agent/agent_test.go @@ -7,8 +7,8 @@ import ( "strings" "sync" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/services/actions" + "github.com/mudler/xlog" . "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" diff --git a/core/agent/knowledgebase.go b/core/agent/knowledgebase.go index 774a9c00..4084c37c 100644 --- a/core/agent/knowledgebase.go +++ b/core/agent/knowledgebase.go @@ -7,8 +7,8 @@ import ( "time" "github.com/mudler/LocalAGI/core/types" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/cogito" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/core/agent/mcp.go b/core/agent/mcp.go index 7d4176d0..0b25b394 100644 --- a/core/agent/mcp.go +++ b/core/agent/mcp.go @@ -12,7 +12,7 @@ import ( "github.com/modelcontextprotocol/go-sdk/mcp" "github.com/mudler/LocalAGI/core/types" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai/jsonschema" ) diff --git a/core/agent/observer.go b/core/agent/observer.go index 920db036..300c95b2 100644 --- a/core/agent/observer.go +++ b/core/agent/observer.go @@ -7,7 +7,7 @@ import ( "github.com/mudler/LocalAGI/core/sse" "github.com/mudler/LocalAGI/core/types" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" ) type Observer interface { diff --git a/core/conversations/conversationstracker.go b/core/conversations/conversationstracker.go index c431e880..4d730638 100644 --- a/core/conversations/conversationstracker.go +++ b/core/conversations/conversationstracker.go @@ -5,7 +5,7 @@ import ( "sync" "time" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/core/state/pool.go b/core/state/pool.go index a0f56133..5df09b8f 100644 --- a/core/state/pool.go +++ b/core/state/pool.go @@ -21,7 +21,7 @@ import ( "github.com/sashabaranov/go-openai" "github.com/sashabaranov/go-openai/jsonschema" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" ) type AgentPool struct { diff --git a/core/types/observable.go b/core/types/observable.go index 3991476a..80b47e78 100644 --- a/core/types/observable.go +++ b/core/types/observable.go @@ -1,7 +1,7 @@ package types import ( - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) @@ -25,7 +25,7 @@ type Completion struct { Conversation []openai.ChatCompletionMessage `json:"conversation,omitempty"` ActionResult string `json:"action_result,omitempty"` AgentState *AgentInternalState `json:"agent_state,omitempty"` - FilterResult *FilterResult `json:"filter_result,omitempty"` + FilterResult *FilterResult `json:"filter_result,omitempty"` } type Observable struct { diff --git a/go.mod b/go.mod index 02ccd84d..c67849ca 100644 --- a/go.mod +++ b/go.mod @@ -40,6 +40,7 @@ require ( github.com/huandu/xstrings v1.5.0 // indirect github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/mudler/xlog v0.0.1 // indirect github.com/shopspring/decimal v1.4.0 // indirect github.com/spf13/cast v1.7.0 // indirect github.com/yosida95/uritemplate/v3 v3.0.2 // indirect diff --git a/go.sum b/go.sum index df18f382..b7108324 100644 --- a/go.sum +++ b/go.sum @@ -172,6 +172,8 @@ github.com/morikuni/aec v1.0.0 h1:nP9CBfwrvYnBRgY6qfDQkygYDmYwOilePFkwzv4dU8A= github.com/morikuni/aec v1.0.0/go.mod h1:BbKIizmSmc5MMPqRYbxO4ZU0S0+P200+tUnFx7PXmsc= github.com/mudler/cogito v0.4.2 h1:1PypFvUq3A+iBxMCR0v+sGXlhOsRnvyFZhEE93tsuDU= github.com/mudler/cogito v0.4.2/go.mod h1:2uhEElCTq8eXSsqJ1JF01oA5h9niXSELVKqCF1PqjEw= +github.com/mudler/xlog v0.0.1 h1:yR3/wszd3ZM6u1n96YITJZ4yUcDgqHSwvQmzUJa+8vg= +github.com/mudler/xlog v0.0.1/go.mod h1:39f5vcd05Qd6GWKM8IjyHNQ7AmOx3ZM0YfhfIGhC18U= github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec= github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/onsi/ginkgo/v2 v2.25.3 h1:Ty8+Yi/ayDAGtk4XxmmfUy4GabvM+MegeB4cDLRi6nw= diff --git a/pkg/llm/json.go b/pkg/llm/json.go index c4f48d1f..7316b61d 100644 --- a/pkg/llm/json.go +++ b/pkg/llm/json.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" "github.com/sashabaranov/go-openai/jsonschema" ) diff --git a/pkg/localrag/client.go b/pkg/localrag/client.go index e34c7ff7..0e76974a 100644 --- a/pkg/localrag/client.go +++ b/pkg/localrag/client.go @@ -16,7 +16,7 @@ import ( "time" "github.com/mudler/LocalAGI/core/agent" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" ) var _ agent.RAGDB = &WrappedClient{} diff --git a/pkg/xlog/xlog.go b/pkg/xlog/xlog.go deleted file mode 100644 index 8a61f528..00000000 --- a/pkg/xlog/xlog.go +++ /dev/null @@ -1,71 +0,0 @@ -package xlog - -import ( - "context" - "log/slog" - "os" - "runtime" -) - -var logger *slog.Logger - -func init() { - var level = slog.LevelDebug - - switch os.Getenv("LOG_LEVEL") { - case "info": - level = slog.LevelInfo - case "warn": - level = slog.LevelWarn - case "error": - level = slog.LevelError - case "debug": - level = slog.LevelDebug - } - - var opts = &slog.HandlerOptions{ - Level: level, - } - - var handler slog.Handler - - if os.Getenv("LOG_FORMAT") == "json" { - handler = slog.NewJSONHandler(os.Stdout, opts) - } else { - handler = slog.NewTextHandler(os.Stdout, opts) - } - logger = slog.New(handler) -} - -func _log(level slog.Level, msg string, args ...any) { - _, f, l, _ := runtime.Caller(2) - group := slog.Group( - "source", - slog.Attr{ - Key: "file", - Value: slog.AnyValue(f), - }, - slog.Attr{ - Key: "L", - Value: slog.AnyValue(l), - }, - ) - args = append(args, group) - logger.Log(context.Background(), level, msg, args...) -} - -func Info(msg string, args ...any) { - _log(slog.LevelInfo, msg, args...) -} - -func Debug(msg string, args ...any) { - _log(slog.LevelDebug, msg, args...) -} - -func Error(msg string, args ...any) { - _log(slog.LevelError, msg, args...) -} - -func Warn(msg string, args ...any) { - _log(slog.LevelWarn, msg, args...) -} diff --git a/services/actions.go b/services/actions.go index dcdbff01..5854ca40 100644 --- a/services/actions.go +++ b/services/actions.go @@ -13,7 +13,7 @@ import ( "github.com/mudler/LocalAGI/core/state" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/mudler/LocalAGI/services/actions" ) diff --git a/services/actions/githubissuelabeler.go b/services/actions/githubissuelabeler.go index 78bd8037..751bddff 100644 --- a/services/actions/githubissuelabeler.go +++ b/services/actions/githubissuelabeler.go @@ -8,7 +8,7 @@ import ( "github.com/google/go-github/v69/github" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai/jsonschema" ) diff --git a/services/actions/githubissuesearch.go b/services/actions/githubissuesearch.go index d6b518a9..386bb621 100644 --- a/services/actions/githubissuesearch.go +++ b/services/actions/githubissuesearch.go @@ -7,7 +7,7 @@ import ( "github.com/google/go-github/v69/github" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai/jsonschema" ) diff --git a/services/actions/githubprreviewer.go b/services/actions/githubprreviewer.go index 74ec5de5..dd158ab9 100644 --- a/services/actions/githubprreviewer.go +++ b/services/actions/githubprreviewer.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-github/v69/github" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai/jsonschema" ) diff --git a/services/actions/githubrepositorygetallcontent.go b/services/actions/githubrepositorygetallcontent.go index 91eab18b..2566661b 100644 --- a/services/actions/githubrepositorygetallcontent.go +++ b/services/actions/githubrepositorygetallcontent.go @@ -9,7 +9,7 @@ import ( "github.com/google/go-github/v69/github" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai/jsonschema" ) diff --git a/services/common.go b/services/common.go index e88fc752..f17080f9 100644 --- a/services/common.go +++ b/services/common.go @@ -4,7 +4,7 @@ import ( "fmt" "os" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" ) func memoryPath(agentName string, actionsConfigs map[string]string) string { diff --git a/services/connectors.go b/services/connectors.go index 1a5ddd8d..2a7f34a1 100644 --- a/services/connectors.go +++ b/services/connectors.go @@ -4,8 +4,8 @@ import ( "encoding/json" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/services/connectors" + "github.com/mudler/xlog" "github.com/mudler/LocalAGI/core/state" ) diff --git a/services/connectors/discord.go b/services/connectors/discord.go index 0589f991..49ceb6f9 100644 --- a/services/connectors/discord.go +++ b/services/connectors/discord.go @@ -9,7 +9,7 @@ import ( "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/services/connectors/email.go b/services/connectors/email.go index 89126b0e..b23e96a8 100644 --- a/services/connectors/email.go +++ b/services/connectors/email.go @@ -22,7 +22,7 @@ import ( "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/services/connectors/githubissue.go b/services/connectors/githubissue.go index ac673e8e..fc423f53 100644 --- a/services/connectors/githubissue.go +++ b/services/connectors/githubissue.go @@ -9,7 +9,7 @@ import ( "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/services/connectors/githubpr.go b/services/connectors/githubpr.go index 7b419815..9619e67b 100644 --- a/services/connectors/githubpr.go +++ b/services/connectors/githubpr.go @@ -9,7 +9,7 @@ import ( "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/services/connectors/irc.go b/services/connectors/irc.go index 1d31fd2e..144e2153 100644 --- a/services/connectors/irc.go +++ b/services/connectors/irc.go @@ -8,8 +8,8 @@ import ( "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/services/actions" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" irc "github.com/thoj/go-ircevent" ) diff --git a/services/connectors/matrix.go b/services/connectors/matrix.go index 8fadfec1..cd376cfe 100644 --- a/services/connectors/matrix.go +++ b/services/connectors/matrix.go @@ -10,7 +10,7 @@ import ( "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" "maunium.net/go/mautrix" "maunium.net/go/mautrix/event" diff --git a/services/connectors/slack.go b/services/connectors/slack.go index 9682c215..77e3083c 100644 --- a/services/connectors/slack.go +++ b/services/connectors/slack.go @@ -11,9 +11,9 @@ import ( "github.com/mudler/LocalAGI/pkg/config" "github.com/mudler/LocalAGI/pkg/localoperator" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/pkg/xstrings" "github.com/mudler/LocalAGI/services/actions" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" "github.com/mudler/LocalAGI/core/agent" diff --git a/services/connectors/telegram.go b/services/connectors/telegram.go index 1eae519e..7e78ad79 100644 --- a/services/connectors/telegram.go +++ b/services/connectors/telegram.go @@ -21,9 +21,9 @@ import ( "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" "github.com/mudler/LocalAGI/pkg/localoperator" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/pkg/xstrings" "github.com/mudler/LocalAGI/services/actions" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/services/connectors/twitter.go b/services/connectors/twitter.go index 884830ae..5d2c0515 100644 --- a/services/connectors/twitter.go +++ b/services/connectors/twitter.go @@ -9,8 +9,8 @@ import ( "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/services/connectors/twitter" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" ) diff --git a/services/filters.go b/services/filters.go index a1d0c3a5..afa96970 100644 --- a/services/filters.go +++ b/services/filters.go @@ -4,8 +4,8 @@ import ( "github.com/mudler/LocalAGI/core/state" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/services/filters" + "github.com/mudler/xlog" ) func Filters(a *state.AgentConfig) types.JobFilters { diff --git a/services/prompts.go b/services/prompts.go index ecb06475..7e7f7088 100644 --- a/services/prompts.go +++ b/services/prompts.go @@ -8,9 +8,9 @@ import ( "strings" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/services/actions" "github.com/mudler/LocalAGI/services/prompts" + "github.com/mudler/xlog" "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/state" diff --git a/services/prompts/custom.go b/services/prompts/custom.go index 8318a212..46a00c18 100644 --- a/services/prompts/custom.go +++ b/services/prompts/custom.go @@ -9,7 +9,7 @@ import ( "github.com/mudler/LocalAGI/core/agent" "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/config" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/traefik/yaegi/interp" "github.com/traefik/yaegi/stdlib" ) diff --git a/tests/e2e/e2e_test.go b/tests/e2e/e2e_test.go index e252cf40..ab96884f 100644 --- a/tests/e2e/e2e_test.go +++ b/tests/e2e/e2e_test.go @@ -8,7 +8,7 @@ import ( localagi "github.com/mudler/LocalAGI/pkg/client" "github.com/mudler/LocalAGI/pkg/utils/ptr" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai/jsonschema" . "github.com/onsi/ginkgo/v2" diff --git a/webui/app.go b/webui/app.go index a060f15e..9c8e3b7c 100644 --- a/webui/app.go +++ b/webui/app.go @@ -15,9 +15,9 @@ import ( coreTypes "github.com/mudler/LocalAGI/core/types" internalTypes "github.com/mudler/LocalAGI/core/types" "github.com/mudler/LocalAGI/pkg/llm" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/services" "github.com/mudler/LocalAGI/webui/types" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" "github.com/sashabaranov/go-openai/jsonschema" diff --git a/webui/routes.go b/webui/routes.go index 7f44e763..434b745b 100644 --- a/webui/routes.go +++ b/webui/routes.go @@ -18,8 +18,8 @@ import ( "github.com/mudler/LocalAGI/core/state" "github.com/mudler/LocalAGI/core/types" - "github.com/mudler/LocalAGI/pkg/xlog" "github.com/mudler/LocalAGI/services" + "github.com/mudler/xlog" ) //go:embed react-ui/dist/* diff --git a/webui/types/openai.go b/webui/types/openai.go index 02457a57..c4e35972 100644 --- a/webui/types/openai.go +++ b/webui/types/openai.go @@ -6,7 +6,7 @@ import ( "strings" coreTypes "github.com/mudler/LocalAGI/core/types" - "github.com/mudler/LocalAGI/pkg/xlog" + "github.com/mudler/xlog" "github.com/sashabaranov/go-openai" "github.com/sashabaranov/go-openai/jsonschema" )