Skip to content

Commit 97cbdd7

Browse files
committed
feat: update logs to support format logs and struct logs
1 parent 21437ab commit 97cbdd7

File tree

50 files changed

+407
-495
lines changed

Some content is hidden

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

50 files changed

+407
-495
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@ model:
3737
3838
Enjoy a minimal agent from VeADK:
3939
40-
```golang
40+
```go
4141
package main
4242

4343
import (
4444
"context"
4545
"fmt"
46-
"log"
4746
"os"
48-
47+
4948
_ "github.com/volcengine/veadk-go/agent"
5049
veagent "github.com/volcengine/veadk-go/agent/llmagent"
50+
"github.com/volcengine/veadk-go/log"
5151
"google.golang.org/adk/agent"
5252
"google.golang.org/adk/cmd/launcher"
5353
"google.golang.org/adk/cmd/launcher/full"
@@ -66,7 +66,7 @@ func main() {
6666
},
6767
})
6868
if err != nil {
69-
fmt.Printf("NewVeAgent failed: %v", err)
69+
log.Errorf("NewVeAgent failed: %v", err)
7070
return
7171
}
7272

agent/init.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@
1515
package agents
1616

1717
import (
18-
"log"
18+
"github.com/volcengine/veadk-go/log"
1919

2020
"github.com/volcengine/veadk-go/configs"
2121
)
2222

2323
func init() {
2424
err := configs.SetupVeADKConfig()
2525
if err != nil {
26-
log.Printf("veadk.SetupVeADKConfig: %v", err)
26+
log.Errorf("veadk.SetupVeADKConfig: %v", err)
2727
}
2828
}

agent/remoteagent/a2a_agent.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"context"
1919
"errors"
2020
"fmt"
21-
"log"
2221

2322
"github.com/a2aproject/a2a-go/a2a"
2423
"github.com/a2aproject/a2a-go/a2aclient"
@@ -144,7 +143,7 @@ func NewVeRemoteAgent(config *Config) (agent.Agent, error) {
144143
// Resolve an AgentCard
145144
card, err := agentcard.DefaultResolver.Resolve(ctx, config.BaseUrl, resolveOptions)
146145
if err != nil {
147-
log.Fatalf("Failed to resolve an AgentCard: %v", err)
146+
return nil, fmt.Errorf("veadk: failed to resolve veadk card: %w", err)
148147
}
149148

150149
card.URL = config.BaseUrl

apps/a2a_app/app.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ package a2a_app
1717
import (
1818
"context"
1919
"fmt"
20-
"log"
20+
21+
"github.com/volcengine/veadk-go/log"
22+
2123
"net/http"
2224
"net/url"
2325

@@ -46,7 +48,7 @@ func (a *agentkitA2AServerApp) Run(ctx context.Context, config *apps.RunConfig)
4648
config.SessionService = session.InMemoryService()
4749
}
4850

49-
log.Printf("Web servers starts on %s", a.GetWebUrl())
51+
log.Infof("Web servers starts on %s", a.GetWebUrl())
5052
err := a.SetupRouters(router, config)
5153
if err != nil {
5254
return fmt.Errorf("setup a2a routers failed: %w", err)

apps/agentkit_server_app/app.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ package agentkit_server_app
1717
import (
1818
"context"
1919
"fmt"
20-
"log"
2120
"net/http"
2221

2322
"github.com/gorilla/mux"
2423
"github.com/volcengine/veadk-go/apps"
2524
"github.com/volcengine/veadk-go/apps/a2a_app"
2625
"github.com/volcengine/veadk-go/apps/simple_app"
26+
"github.com/volcengine/veadk-go/log"
2727
"google.golang.org/adk/cmd/launcher"
2828
"google.golang.org/adk/cmd/launcher/web"
2929
"google.golang.org/adk/cmd/launcher/web/webui"
@@ -48,7 +48,7 @@ func (a *agentkitServerApp) Run(ctx context.Context, config *apps.RunConfig) err
4848
config.SessionService = session.InMemoryService()
4949
}
5050

51-
log.Printf("Web servers starts on %s", a.GetWebUrl())
51+
log.Infof("Web servers starts on %s", a.GetWebUrl())
5252
err := a.SetupRouters(router, config)
5353
if err != nil {
5454
return fmt.Errorf("setup agentkit server routers failed: %w", err)
@@ -125,8 +125,8 @@ func (a *agentkitServerApp) SetupRouters(router *mux.Router, config *apps.RunCon
125125
http.StripPrefix(a.ApiPathPrefix, corsHandler),
126126
)
127127

128-
log.Printf(" api: you can access API using %s", a.GetAPIPath())
129-
log.Printf(" api: for instance: %s/list-apps", a.GetAPIPath())
128+
log.Infof(" api: you can access API using %s", a.GetAPIPath())
129+
log.Infof(" api: for instance: %s/list-apps", a.GetAPIPath())
130130

131131
return nil
132132
}

apps/basic_app.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ type BasicApp interface {
5454
func DefaultApiConfig() *ApiConfig {
5555
return &ApiConfig{
5656
Port: 8000,
57-
WriteTimeout: time.Second * 15,
58-
ReadTimeout: time.Second * 15,
59-
IdleTimeout: time.Second * 60,
57+
WriteTimeout: time.Second * 60,
58+
ReadTimeout: time.Second * 60,
59+
IdleTimeout: time.Second * 120,
6060
SEEWriteTimeout: time.Second * 300,
6161
ApiPathPrefix: "", // set /api same as ADK-Go
6262
}

apps/simple_app/app.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ import (
1919
"encoding/json"
2020
"fmt"
2121
"io"
22-
"log"
22+
23+
"github.com/volcengine/veadk-go/log"
24+
2325
"net/http"
2426
"strings"
2527

@@ -88,16 +90,16 @@ func (app *agentkitSimpleApp) SetupRouters(router *mux.Router, config *apps.RunC
8890
router.NewRoute().Path("/invoke").Methods(http.MethodPost).HandlerFunc(app.newInvokeHandler())
8991
router.NewRoute().Path("/health").Methods(http.MethodGet).HandlerFunc(app.newHealthHandler())
9092

91-
log.Printf(" invoke: you can invoke agent using %s/invoke", app.GetWebUrl())
92-
log.Printf(" health: you can get health status using: %s/health", app.GetWebUrl())
93+
log.Infof(" invoke: you can invoke agent using %s/invoke", app.GetWebUrl())
94+
log.Infof(" health: you can get health status using: %s/health", app.GetWebUrl())
9395

9496
return nil
9597
}
9698

9799
func (app *agentkitSimpleApp) Run(ctx context.Context, config *apps.RunConfig) error {
98100
router := web.BuildBaseRouter()
99101

100-
log.Printf("Web servers starts on %s", app.GetWebUrl())
102+
log.Infof("Web servers starts on %s", app.GetWebUrl())
101103
err := app.SetupRouters(router, config)
102104
if err != nil {
103105
return fmt.Errorf("setup simple app router error: %w", err)
@@ -157,7 +159,7 @@ func (app *agentkitSimpleApp) newInvokeHandler() func(w http.ResponseWriter, r *
157159
var finalResponseText []string
158160
for event, err := range app.runner.Run(ctx, app.userID, app.session.ID(), userInput, agent.RunConfig{StreamingMode: agent.StreamingModeNone}) {
159161
if err != nil {
160-
log.Printf("Agent Run Error: %v", err)
162+
log.Errorf("Agent Run Error: %v", err)
161163
continue
162164
}
163165
if event.Content != nil && !event.Partial {

auth/veauth/apmplus_veauth.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ package veauth
1717
import (
1818
"encoding/json"
1919
"fmt"
20-
"log"
20+
"github.com/volcengine/veadk-go/log"
21+
2122
"strings"
2223

2324
"github.com/volcengine/veadk-go/common"
@@ -33,7 +34,7 @@ type getAppKeyResponse struct {
3334
}
3435

3536
func GetApmPlusToken(region string) (string, error) {
36-
log.Println("Fetching APMPlus token...")
37+
log.Info("Fetching APMPlus token...")
3738
if region == "" {
3839
region = common.DEFAULT_REGION
3940
}
@@ -89,6 +90,6 @@ func GetApmPlusToken(region string) (string, error) {
8990
return "", fmt.Errorf("failed to get APMPlus token: app_key not found in response")
9091
}
9192

92-
log.Println("Successfully fetching APMPlus API Key.")
93+
log.Info("Successfully fetching APMPlus API Key.")
9394
return resp.Data.AppKey, nil
9495
}

auth/veauth/ark_veauth.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ package veauth
1717
import (
1818
"encoding/json"
1919
"fmt"
20-
"log"
20+
"github.com/volcengine/veadk-go/log"
21+
2122
"net/http"
2223

2324
"github.com/volcengine/veadk-go/common"
@@ -45,7 +46,7 @@ func GetArkToken(region string) (string, error) {
4546
if region == "" {
4647
region = common.DEFAULT_MODEL_REGION
4748
}
48-
log.Println("Fetching ARK token...")
49+
log.Info("Fetching ARK token...")
4950

5051
accessKey := utils.GetEnvWithDefault(common.VOLCENGINE_ACCESS_KEY, configs.GetGlobalConfig().Volcengine.AK)
5152
secretKey := utils.GetEnvWithDefault(common.VOLCENGINE_SECRET_KEY, configs.GetGlobalConfig().Volcengine.SK)
@@ -102,7 +103,7 @@ func GetArkToken(region string) (string, error) {
102103
}
103104

104105
firstApiKeyId := listResp.Result.Items[0].ID
105-
log.Println("By default, VeADK fetches the first API Key in the list.")
106+
log.Info("By default, VeADK fetches the first API Key in the list.")
106107

107108
// GetRawApiKey
108109
req2 := ve_sign.VeRequest{
@@ -137,7 +138,7 @@ func GetArkToken(region string) (string, error) {
137138
return "", fmt.Errorf("failed to get ARK api key: key not found in response")
138139
}
139140

140-
log.Println("Successfully fetched ARK API Key.")
141+
log.Info("Successfully fetched ARK API Key.")
141142

142143
return apiKey, nil
143144
}

auth/veauth/mem0_veauth.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ package veauth
1717
import (
1818
"encoding/json"
1919
"fmt"
20-
"log"
2120

2221
"github.com/volcengine/veadk-go/common"
2322
"github.com/volcengine/veadk-go/configs"
2423
"github.com/volcengine/veadk-go/integrations/ve_sign"
24+
"github.com/volcengine/veadk-go/log"
2525
"github.com/volcengine/veadk-go/utils"
2626
)
2727

@@ -67,7 +67,6 @@ func getAPIKeyIDByProjectID(projectID, accessKey, secretKey, sessionToken, regio
6767
return "", fmt.Errorf("failed to describe memory project detail: %w", err)
6868
}
6969

70-
fmt.Println(string(respBody))
7170
var res describeMemoryProjectDetailResult
7271
if err := json.Unmarshal(respBody, &res); err != nil {
7372
return "", fmt.Errorf("failed to unmarshal response: %w", err)
@@ -109,8 +108,6 @@ func getAPIKeyByAPIKeyID(projectID, apiKeyID, accessKey, secretKey, sessionToken
109108
return "", fmt.Errorf("failed to describe api key detail: %w", err)
110109
}
111110

112-
fmt.Println(string(respBody))
113-
114111
var res describeAPIKeyDetailResult
115112
if err := json.Unmarshal(respBody, &res); err != nil {
116113
return "", fmt.Errorf("failed to unmarshal response: %w", err)
@@ -127,7 +124,7 @@ func GetVikingMem0Token(memoryProjectID string, region string) (string, error) {
127124
if region == "" {
128125
region = common.DEFAULT_REGION
129126
}
130-
log.Printf("Fetching Viking mem0 token...")
127+
log.Infof("Fetching Viking mem0 token...")
131128

132129
accessKey := utils.GetEnvWithDefault(common.VOLCENGINE_ACCESS_KEY, configs.GetGlobalConfig().Volcengine.AK)
133130
secretKey := utils.GetEnvWithDefault(common.VOLCENGINE_SECRET_KEY, configs.GetGlobalConfig().Volcengine.SK)

0 commit comments

Comments
 (0)