Skip to content

Commit df7d5f4

Browse files
committed
🔊 Add logger to mcp
issue #64
1 parent 367140e commit df7d5f4

File tree

51 files changed

+727
-49
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+727
-49
lines changed

cmd/caption/delete.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package caption
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/caption"
811
"github.com/mark3labs/mcp-go/mcp"
912
"github.com/spf13/cobra"
10-
"io"
1113
)
1214

1315
const (
@@ -76,11 +78,22 @@ func deleteHandler(
7678
onBehalfOf, _ = args["onBehalfOf"].(string)
7779
onBehalfOfContentOwner, _ = args["onBehalfOfContentOwner"].(string)
7880

81+
slog.InfoContext(ctx, "caption delete started")
82+
7983
var writer bytes.Buffer
8084
err := del(&writer)
8185
if err != nil {
86+
slog.ErrorContext(
87+
ctx, "caption delete failed",
88+
"error", err,
89+
"args", args,
90+
)
8291
return mcp.NewToolResultError(err.Error()), err
8392
}
93+
slog.InfoContext(
94+
ctx, "caption delete completed successfully",
95+
"resultSize", writer.Len(),
96+
)
8497
return mcp.NewToolResultText(writer.String()), nil
8598
}
8699

cmd/caption/download.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package caption
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/caption"
811
"github.com/mark3labs/mcp-go/mcp"
912
"github.com/spf13/cobra"
10-
"io"
1113
)
1214

1315
const (
@@ -97,11 +99,22 @@ func downloadHandler(
9799
onBehalfOf, _ = args["onBehalfOf"].(string)
98100
onBehalfOfContentOwner, _ = args["onBehalfOfContentOwner"].(string)
99101

102+
slog.InfoContext(ctx, "caption download started")
103+
100104
var writer bytes.Buffer
101105
err := download(&writer)
102106
if err != nil {
107+
slog.ErrorContext(
108+
ctx, "caption download failed",
109+
"error", err,
110+
"args", args,
111+
)
103112
return mcp.NewToolResultError(err.Error()), err
104113
}
114+
slog.InfoContext(
115+
ctx, "caption download completed successfully",
116+
"resultSize", writer.Len(),
117+
)
105118
return mcp.NewToolResultText(writer.String()), nil
106119
}
107120

cmd/caption/insert.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package caption
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/caption"
811
"github.com/eat-pray-ai/yutu/pkg/utils"
912
"github.com/mark3labs/mcp-go/mcp"
1013
"github.com/spf13/cobra"
11-
"io"
1214
)
1315

1416
const (
@@ -158,11 +160,22 @@ func insertHandler(
158160
output, _ = args["output"].(string)
159161
jpath, _ = args["jsonpath"].(string)
160162

163+
slog.InfoContext(ctx, "caption insert started")
164+
161165
var writer bytes.Buffer
162166
err := insert(&writer)
163167
if err != nil {
168+
slog.ErrorContext(
169+
ctx, "caption insert failed",
170+
"error", err,
171+
"args", args,
172+
)
164173
return mcp.NewToolResultError(err.Error()), err
165174
}
175+
slog.InfoContext(
176+
ctx, "caption insert completed successfully",
177+
"resultSize", writer.Len(),
178+
)
166179
return mcp.NewToolResultText(writer.String()), nil
167180
}
168181

cmd/caption/list.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package caption
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/caption"
811
"github.com/mark3labs/mcp-go/mcp"
912
"github.com/spf13/cobra"
10-
"io"
1113
)
1214

1315
const (
@@ -105,11 +107,22 @@ func listHandler(
105107
output, _ = args["output"].(string)
106108
jpath, _ = args["jsonpath"].(string)
107109

110+
slog.InfoContext(ctx, "caption list started")
111+
108112
var writer bytes.Buffer
109113
err := list(&writer)
110114
if err != nil {
115+
slog.ErrorContext(
116+
ctx, "caption list failed",
117+
"error", err,
118+
"args", args,
119+
)
111120
return mcp.NewToolResultError(err.Error()), err
112121
}
122+
slog.InfoContext(
123+
ctx, "caption list completed successfully",
124+
"resultSize", writer.Len(),
125+
)
113126
return mcp.NewToolResultText(writer.String()), nil
114127
}
115128

cmd/caption/update.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package caption
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/caption"
811
"github.com/eat-pray-ai/yutu/pkg/utils"
912
"github.com/mark3labs/mcp-go/mcp"
1013
"github.com/spf13/cobra"
11-
"io"
1214
)
1315

1416
const (
@@ -156,11 +158,22 @@ func updateHandler(
156158
output, _ = args["output"].(string)
157159
jpath, _ = args["jsonpath"].(string)
158160

161+
slog.InfoContext(ctx, "caption update started")
162+
159163
var writer bytes.Buffer
160164
err := update(&writer)
161165
if err != nil {
166+
slog.ErrorContext(
167+
ctx, "caption update failed",
168+
"error", err,
169+
"args", args,
170+
)
162171
return mcp.NewToolResultError(err.Error()), err
163172
}
173+
slog.InfoContext(
174+
ctx, "caption update completed successfully",
175+
"resultSize", writer.Len(),
176+
)
164177
return mcp.NewToolResultText(writer.String()), nil
165178
}
166179

cmd/channel/list.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package channel
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/channel"
811
"github.com/eat-pray-ai/yutu/pkg/utils"
912
"github.com/mark3labs/mcp-go/mcp"
1013
"github.com/spf13/cobra"
11-
"io"
1214
)
1315

1416
const (
@@ -161,11 +163,22 @@ func listHandler(
161163
output, _ = args["output"].(string)
162164
jpath, _ = args["jsonpath"].(string)
163165

166+
slog.InfoContext(ctx, "channel list started")
167+
164168
var writer bytes.Buffer
165169
err := list(&writer)
166170
if err != nil {
171+
slog.ErrorContext(
172+
ctx, "channel list failed",
173+
"error", err,
174+
"args", args,
175+
)
167176
return mcp.NewToolResultError(err.Error()), err
168177
}
178+
slog.InfoContext(
179+
ctx, "channel list completed successfully",
180+
"resultSize", writer.Len(),
181+
)
169182
return mcp.NewToolResultText(writer.String()), nil
170183
}
171184

cmd/channel/update.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package channel
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/channel"
811
"github.com/mark3labs/mcp-go/mcp"
912
"github.com/spf13/cobra"
10-
"io"
1113
)
1214

1315
const (
@@ -113,11 +115,22 @@ func updateHandler(
113115
output, _ = args["output"].(string)
114116
jpath, _ = args["jsonpath"].(string)
115117

118+
slog.InfoContext(ctx, "channel update started")
119+
116120
var writer bytes.Buffer
117121
err := update(&writer)
118122
if err != nil {
123+
slog.ErrorContext(
124+
ctx, "channel update failed",
125+
"error", err,
126+
"args", args,
127+
)
119128
return mcp.NewToolResultError(err.Error()), err
120129
}
130+
slog.InfoContext(
131+
ctx, "channel update completed successfully",
132+
"resultSize", writer.Len(),
133+
)
121134
return mcp.NewToolResultText(writer.String()), nil
122135
}
123136

cmd/channelBanner/insert.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package channelBanner
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/channelBanner"
811
"github.com/mark3labs/mcp-go/mcp"
912
"github.com/spf13/cobra"
10-
"io"
1113
)
1214

1315
func init() {
@@ -86,11 +88,22 @@ func insertHandler(
8688
output, _ = args["output"].(string)
8789
jpath, _ = args["jsonpath"].(string)
8890

91+
slog.InfoContext(ctx, "channelBanner insert started")
92+
8993
var writer bytes.Buffer
9094
err := insert(&writer)
9195
if err != nil {
96+
slog.ErrorContext(
97+
ctx, "channelBanner insert failed",
98+
"error", err,
99+
"args", args,
100+
)
92101
return mcp.NewToolResultError(err.Error()), err
93102
}
103+
slog.InfoContext(
104+
ctx, "channelBanner insert completed successfully",
105+
"resultSize", writer.Len(),
106+
)
94107
return mcp.NewToolResultText(writer.String()), nil
95108
}
96109

cmd/channelSection/delete.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@ package channelSection
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/channelSection"
811
"github.com/mark3labs/mcp-go/mcp"
912
"github.com/spf13/cobra"
10-
"io"
1113
)
1214

1315
const (
@@ -70,11 +72,22 @@ func deleteHandler(
7072
}
7173
onBehalfOfContentOwner, _ = args["onBehalfOfContentOwner"].(string)
7274

75+
slog.InfoContext(ctx, "channelSection delete started")
76+
7377
var writer bytes.Buffer
7478
err := del(&writer)
7579
if err != nil {
80+
slog.ErrorContext(
81+
ctx, "channelSection delete failed",
82+
"error", err,
83+
"args", args,
84+
)
7685
return mcp.NewToolResultError(err.Error()), err
7786
}
87+
slog.InfoContext(
88+
ctx, "channelSection delete completed successfully",
89+
"resultSize", writer.Len(),
90+
)
7891
return mcp.NewToolResultText(writer.String()), nil
7992
}
8093

cmd/channelSection/list.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ package channelSection
33
import (
44
"bytes"
55
"context"
6+
"io"
7+
"log/slog"
8+
69
"github.com/eat-pray-ai/yutu/cmd"
710
"github.com/eat-pray-ai/yutu/pkg/channelSection"
811
"github.com/eat-pray-ai/yutu/pkg/utils"
912
"github.com/mark3labs/mcp-go/mcp"
1013
"github.com/spf13/cobra"
11-
"io"
1214
)
1315

1416
const (
@@ -113,11 +115,22 @@ func listHandler(
113115
output, _ = args["output"].(string)
114116
jpath, _ = args["jsonpath"].(string)
115117

118+
slog.InfoContext(ctx, "channelSection list started")
119+
116120
var writer bytes.Buffer
117121
err := list(&writer)
118122
if err != nil {
123+
slog.ErrorContext(
124+
ctx, "channelSection list failed",
125+
"error", err,
126+
"args", args,
127+
)
119128
return mcp.NewToolResultError(err.Error()), err
120129
}
130+
slog.InfoContext(
131+
ctx, "channelSection list completed successfully",
132+
"resultSize", writer.Len(),
133+
)
121134
return mcp.NewToolResultText(writer.String()), nil
122135
}
123136

0 commit comments

Comments
 (0)