Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replaced with dapr-kit logger #491

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions actor/manager/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ package manager

import (
"context"
"log"
"reflect"

"github.com/dapr/go-sdk/actor"
"github.com/dapr/go-sdk/actor/codec"
actorErr "github.com/dapr/go-sdk/actor/error"
"github.com/dapr/go-sdk/actor/state"
dapr "github.com/dapr/go-sdk/client"
"github.com/dapr/kit/logger"
)

var log = logger.NewLogger("dapr.actor.manager")

// Deprecated: use ActorContainerContext instead.
type ActorContainer interface {
Invoke(methodName string, param []byte) ([]reflect.Value, actorErr.ActorErr)
Expand Down Expand Up @@ -87,7 +89,7 @@ func NewDefaultActorContainerContext(ctx context.Context, actorID string, impl a
}
methodType, err := getAbsctractMethodMap(impl)
if err != nil {
log.Printf("failed to get absctract method map from registered provider, err = %s", err)
log.Infof("failed to get absctract method map from registered provider, err = %s", err)
return nil, actorErr.ErrActorServerInvalid
}
return &DefaultActorContainerContext{
Expand Down
7 changes: 3 additions & 4 deletions actor/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"context"
"errors"
"fmt"
"log"
"reflect"
"sync"
"unicode"
Expand Down Expand Up @@ -181,7 +180,7 @@ func (m *DefaultActorManagerContext) InvokeReminder(ctx context.Context, actorID
}
reminderParams := &api.ActorReminderParams{}
if err := m.serializer.Unmarshal(params, reminderParams); err != nil {
log.Printf("failed to unmarshal reminder param, err: %v ", err)
log.Infof("failed to unmarshal reminder param, err: %v ", err)
return actorErr.ErrRemindersParamsInvalid
}
actorContainer, aerr := m.getAndCreateActorContainerIfNotExist(ctx, actorID)
Expand All @@ -204,7 +203,7 @@ func (m *DefaultActorManagerContext) InvokeTimer(ctx context.Context, actorID, t
}
timerParams := &api.ActorTimerParam{}
if err := m.serializer.Unmarshal(params, timerParams); err != nil {
log.Printf("failed to unmarshal reminder param, err: %v ", err)
log.Infof("failed to unmarshal reminder param, err: %v ", err)
return actorErr.ErrTimerParamsInvalid
}
actorContainer, aerr := m.getAndCreateActorContainerIfNotExist(ctx, actorID)
Expand Down Expand Up @@ -251,7 +250,7 @@ func suitableMethods(typ reflect.Type) map[string]*MethodType {
for m := 0; m < typ.NumMethod(); m++ {
method := typ.Method(m)
if mt, err := suiteMethod(method); err != nil {
log.Printf("method %s is illegal, err = %s, just skip it", method.Name, err)
log.Infof("method %s is illegal, err = %v, just skip it", method.Name, err)
} else {
methods[method.Name] = mt
}
Expand Down
14 changes: 7 additions & 7 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"errors"
"fmt"
"io"
"log"
"net"
"os"
"strconv"
Expand All @@ -41,6 +40,7 @@ import (

// used to import codec implements.
_ "github.com/dapr/go-sdk/actor/codec/impl"
"github.com/dapr/kit/logger"
)

const (
Expand All @@ -55,7 +55,7 @@ const (
)

var (
logger = log.New(os.Stdout, "", 0)
log = logger.NewLogger("dapr.client")
lock = &sync.Mutex{}
_ Client = (*GRPCClient)(nil)
defaultClient Client
Expand Down Expand Up @@ -274,7 +274,7 @@ func NewClientWithAddressContext(ctx context.Context, address string) (client Cl
if address == "" {
return nil, errors.New("empty address")
}
logger.Printf("dapr client initializing for: %s", address)
log.Infof("dapr client initializing for: %s", address)

timeoutSeconds, err := getClientTimeoutSeconds()
if err != nil {
Expand Down Expand Up @@ -308,7 +308,7 @@ func NewClientWithAddressContext(ctx context.Context, address string) (client Cl
return nil, fmt.Errorf("error creating connection to '%s': %w", address, err)
}
if hasToken := os.Getenv(apiTokenEnvVarName); hasToken != "" {
logger.Println("client uses API token")
log.Info("client uses API token")
}

return NewClientWithConnection(conn), nil
Expand All @@ -334,7 +334,7 @@ func NewClientWithSocket(socket string) (client Client, err error) {
if socket == "" {
return nil, errors.New("nil socket")
}
logger.Printf("dapr client initializing for: %s", socket)
log.Infof("dapr client initializing for: %s", socket)
addr := "unix://" + socket
conn, err := grpc.Dial(
addr,
Expand All @@ -345,7 +345,7 @@ func NewClientWithSocket(socket string) (client Client, err error) {
return nil, fmt.Errorf("error creating connection to '%s': %w", addr, err)
}
if hasToken := os.Getenv(apiTokenEnvVarName); hasToken != "" {
logger.Println("client uses API token")
log.Info("client uses API token")
}
return NewClientWithConnection(conn), nil
}
Expand Down Expand Up @@ -385,7 +385,7 @@ func (c *GRPCClient) WithTraceID(ctx context.Context, id string) context.Context
if id == "" {
return ctx
}
logger.Printf("using trace parent ID: %s", id)
log.Infof("using trace parent ID: %s", id)
md := metadata.Pairs(traceparentKey, id)
return metadata.NewOutgoingContext(ctx, md)
}
Expand Down
10 changes: 5 additions & 5 deletions client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func getTestClient(ctx context.Context) (client Client, closer func()) {
l := bufconn.Listen(testBufSize)
go func() {
if err := s.Serve(l); err != nil && err.Error() != "closed" {
logger.Fatalf("test server exited with error: %v", err)
log.Fatalf("test server exited with error: %v", err)
}
}()

Expand All @@ -153,7 +153,7 @@ func getTestClient(ctx context.Context) (client Client, closer func()) {

c, err := grpc.DialContext(ctx, "", d, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
logger.Fatalf("failed to dial test context: %v", err)
log.Fatalf("failed to dial test context: %v", err)
}

closer = func() {
Expand All @@ -175,12 +175,12 @@ func getTestClientWithSocket(ctx context.Context) (client Client, closer func())
var lc net.ListenConfig
l, err := lc.Listen(ctx, "unix", testSocket)
if err != nil {
logger.Fatalf("socket test server created with error: %v", err)
log.Fatalf("socket test server created with error: %v", err)
}

go func() {
if err = s.Serve(l); err != nil && err.Error() != "accept unix /tmp/dapr.socket: use of closed network connection" {
logger.Fatalf("socket test server exited with error: %v", err)
log.Fatalf("socket test server exited with error: %v", err)
}
}()

Expand All @@ -191,7 +191,7 @@ func getTestClientWithSocket(ctx context.Context) (client Client, closer func())
}

if client, err = NewClientWithSocket(testSocket); err != nil {
logger.Fatalf("socket test client created with error: %v", err)
log.Fatalf("socket test client created with error: %v", err)
}

return
Expand Down
3 changes: 1 addition & 2 deletions client/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"errors"
"fmt"
"log"

"github.com/google/uuid"

Expand Down Expand Up @@ -102,7 +101,7 @@ func PublishEventWithRawPayload() PublishEventOption {
// PublishEventfromCustomContent serializes an struct and publishes its contents as data (JSON) onto topic in specific pubsub component.
// Deprecated: This method is deprecated and will be removed in a future version of the SDK. Please use `PublishEvent` instead.
func (c *GRPCClient) PublishEventfromCustomContent(ctx context.Context, pubsubName, topicName string, data interface{}) error {
log.Println("DEPRECATED: client.PublishEventfromCustomContent is deprecated and will be removed in a future version of the SDK. Please use `PublishEvent` instead.")
log.Info("DEPRECATED: client.PublishEventfromCustomContent is deprecated and will be removed in a future version of the SDK. Please use `PublishEvent` instead.")

// Perform the JSON marshaling here just in case someone passed a []byte or string as data
enc, err := json.Marshal(data)
Expand Down
8 changes: 4 additions & 4 deletions client/wait_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ type Server struct {
func (s *Server) Close() {
close(s.done)
if err := s.listener.Close(); err != nil {
logger.Fatal(err)
log.Fatal(err)
}
os.Remove(unresponsiveUnixSocketFilePath)
}
Expand All @@ -61,7 +61,7 @@ func (s *Server) listenButKeepSilent() {
case <-s.done:
return
default:
logger.Fatal(err)
log.Fatal(err)
break
}
} else {
Expand All @@ -85,7 +85,7 @@ func createUnresponsiveUnixServer() (*Server, error) {
func createUnresponsiveServer(network string, unresponsiveServerAddress string) (*Server, error) {
serverListener, err := net.Listen(network, unresponsiveServerAddress)
if err != nil {
logger.Fatalf("Creation of test server on network %s and address %s failed with error: %v",
log.Fatalf("Creation of test server on network %s and address %s failed with error: %v",
network, unresponsiveServerAddress, err)
return nil, err
}
Expand All @@ -109,7 +109,7 @@ func createNonBlockingClient(ctx context.Context, serverAddr string) (client Cli
grpc.WithTransportCredentials(insecure.NewCredentials()),
)
if err != nil {
logger.Fatal(err)
log.Fatal(err)
return nil, err
}
return NewClientWithConnection(conn), nil
Expand Down
1 change: 0 additions & 1 deletion examples/actor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ dapr stop --app-id actor-serving
## Result
- client side
```
== APP == dapr client initializing for: 127.0.0.1:55776
== APP == get user result = &{abc 123}
== APP == get invoke result = laurence
== APP == get post result = laurence
Expand Down
6 changes: 5 additions & 1 deletion examples/actor/serving/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ package main
import (
"context"
"fmt"
"log"
"net/http"

"github.com/dapr/go-sdk/actor"
dapr "github.com/dapr/go-sdk/client"
"github.com/dapr/go-sdk/examples/actor/api"

daprd "github.com/dapr/go-sdk/service/http"
"github.com/dapr/kit/logger"
)

var (
log = logger.NewLogger("dapr.examples.actor")
)

func testActorFactory() actor.ServerContext {
Expand Down
7 changes: 5 additions & 2 deletions examples/grpc-service/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ package main

import (
"context"
"log"
"time"

"google.golang.org/grpc"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
"google.golang.org/grpc/metadata"

"github.com/dapr/kit/logger"
)

var log = logger.NewLogger("dapr.examples.grpc-client")

const (
address = "localhost:50007"
)
Expand All @@ -32,5 +35,5 @@ func main() {
log.Fatalf("could not greet: %v", err)
}

log.Printf("Greeting: %s", r.GetMessage())
log.Infof("Greeting: %s", r.GetMessage())
}
6 changes: 4 additions & 2 deletions examples/grpc-service/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@ package main

import (
"context"
"log"
"net"

daprd "github.com/dapr/go-sdk/service/grpc"
"google.golang.org/grpc"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
"github.com/dapr/kit/logger"
)

var log = logger.NewLogger("dapr.examples.grpc-server")

const (
port = ":50051"
)
Expand All @@ -21,7 +23,7 @@ type server struct {

// SayHello implements helloworld.GreeterServer
func (s *server) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
log.Printf("Received: %v", in.GetName())
log.Infof("Received: %v", in.GetName())
return &pb.HelloReply{Message: "Hello " + in.GetName()}, nil
}

Expand Down
2 changes: 0 additions & 2 deletions examples/hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ name: Run and send order
background: true
sleep: 5
expected_stdout_lines:
- '== APP == dapr client initializing for: 127.0.0.1:3500'
- '== APP == Sending order ID 20'
- '== APP == Successfully persisted state'
-->
Expand All @@ -99,7 +98,6 @@ name: Run and get order
background: true
sleep: 5
expected_stdout_lines:
- '== APP == dapr client initializing for: 127.0.0.1:3500'
- '== APP == Getting order'
- '== APP == Order ID 20'
-->
Expand Down
8 changes: 5 additions & 3 deletions examples/pubsub/sub/sub.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ package main

import (
"context"
"log"
"net/http"

"github.com/dapr/go-sdk/service/common"
daprd "github.com/dapr/go-sdk/service/http"
"github.com/dapr/kit/logger"
)

var log = logger.NewLogger("dapr.examples.pubsub.sub")

// Subscription to tell the dapr what topic to subscribe.
// - PubsubName: is the name of the component configured in the metadata of pubsub.yaml.
// - Topic: is the name of the topic to subscribe.
Expand Down Expand Up @@ -60,11 +62,11 @@ func main() {
}

func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
log.Printf("event - PubsubName: %s, Topic: %s, ID: %s, Data: %s", e.PubsubName, e.Topic, e.ID, e.Data)
log.Infof("event - PubsubName: %s, Topic: %s, ID: %s, Data: %s", e.PubsubName, e.Topic, e.ID, e.Data)
return false, nil
}

func importantEventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
log.Printf("important event - PubsubName: %s, Topic: %s, ID: %s, Data: %s", e.PubsubName, e.Topic, e.ID, e.Data)
log.Infof("important event - PubsubName: %s, Topic: %s, ID: %s, Data: %s", e.PubsubName, e.Topic, e.ID, e.Data)
return false, nil
}
10 changes: 6 additions & 4 deletions examples/service/serving/grpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package main
import (
"context"
"errors"
"log"

"github.com/dapr/go-sdk/service/common"
daprd "github.com/dapr/go-sdk/service/grpc"
"github.com/dapr/kit/logger"
)

var log = logger.NewLogger("dapr.examples.service.grpc")

func main() {
// create a Dapr service server
s, err := daprd.NewService(":50001")
Expand Down Expand Up @@ -55,7 +57,7 @@ func main() {
}

func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
log.Printf("event - PubsubName:%s, Topic:%s, ID:%s, Data: %s", e.PubsubName, e.Topic, e.ID, e.Data)
log.Infof("event - PubsubName:%s, Topic:%s, ID:%s, Data: %s", e.PubsubName, e.Topic, e.ID, e.Data)
return false, nil
}

Expand All @@ -64,7 +66,7 @@ func echoHandler(ctx context.Context, in *common.InvocationEvent) (out *common.C
err = errors.New("nil invocation parameter")
return
}
log.Printf(
log.Infof(
"echo - ContentType:%s, Verb:%s, QueryString:%s, %s",
in.ContentType, in.Verb, in.QueryString, in.Data,
)
Expand All @@ -77,6 +79,6 @@ func echoHandler(ctx context.Context, in *common.InvocationEvent) (out *common.C
}

func runHandler(ctx context.Context, in *common.BindingEvent) (out []byte, err error) {
log.Printf("binding - Data:%s, Meta:%v", in.Data, in.Metadata)
log.Infof("binding - Data:%s, Meta:%v", in.Data, in.Metadata)
return nil, nil
}
Loading
Loading