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 7 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 @@

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 @@
}
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)

Check warning on line 92 in actor/manager/container.go

View check run for this annotation

Codecov / codecov/patch

actor/manager/container.go#L92

Added line #L92 was not covered by tests
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 = %s, just skip it", method.Name, err)
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
} 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 @@
"errors"
"fmt"
"io"
"log"
"net"
"os"
"strconv"
Expand All @@ -41,6 +40,7 @@

// 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 @@
)

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 @@
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 @@
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")

Check warning on line 311 in client/client.go

View check run for this annotation

Codecov / codecov/patch

client/client.go#L311

Added line #L311 was not covered by tests
}

return NewClientWithConnection(conn), nil
Expand All @@ -334,7 +334,7 @@
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 @@
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 @@
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.Infof("DEPRECATED: client.PublishEventfromCustomContent is deprecated and will be removed in a future version of the SDK. Please use `PublishEvent` instead.")
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved

// 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
4 changes: 2 additions & 2 deletions daprdocs/content/en/go-sdk-docs/go-client/_index.md
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ type MyActor struct {

// MyActorMethod is a method that can be invoked on MyActor.
func (a *MyActor) MyActorMethod(ctx context.Context, req *actors.Message) (string, error) {
log.Printf("Received message: %s", req.Data)
log.Infof("Received message: %s", req.Data)
return "Hello from MyActor!", nil
}

Expand Down Expand Up @@ -274,7 +274,7 @@ func main() {
log.Fatal("Error invoking actor method: ", err)
}

log.Printf("Response from actor: %s", resp.Data)
log.Infof("Response from actor: %s", resp.Data)

// Wait for a few seconds before terminating
time.Sleep(5 * time.Second)
Expand Down
6 changes: 3 additions & 3 deletions daprdocs/content/en/go-sdk-docs/go-service/grpc-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ The handler method itself can be any method with the expected signature:

```go
func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
log.Printf("event - PubsubName:%s, Topic:%s, ID:%s, Data: %v", e.PubsubName, e.Topic, e.ID, e.Data)
log.Infof("event - PubsubName:%s, Topic:%s, ID:%s, Data: %v", e.PubsubName, e.Topic, e.ID, e.Data)
// do something with the event
return true, nil
}
Expand Down Expand Up @@ -96,7 +96,7 @@ The handler method itself can be any method with the expected signature:

```go
func echoHandler(ctx context.Context, in *common.InvocationEvent) (out *common.Content, err error) {
log.Printf("echo - ContentType:%s, Verb:%s, QueryString:%s, %+v", in.ContentType, in.Verb, in.QueryString, string(in.Data))
log.Infof("echo - ContentType:%s, Verb:%s, QueryString:%s, %+v", in.ContentType, in.Verb, in.QueryString, string(in.Data))
// do something with the invocation here
out = &common.Content{
Data: in.Data,
Expand All @@ -120,7 +120,7 @@ The handler method itself can be any method with the expected signature:

```go
func runHandler(ctx context.Context, in *common.BindingEvent) (out []byte, err error) {
log.Printf("binding - Data:%v, Meta:%v", in.Data, in.Metadata)
log.Infof("binding - Data:%v, Meta:%v", in.Data, in.Metadata)
// do something with the invocation here
return nil, nil
}
Expand Down
6 changes: 3 additions & 3 deletions daprdocs/content/en/go-sdk-docs/go-service/http-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ The handler method itself can be any method with the expected signature:

```go
func eventHandler(ctx context.Context, e *common.TopicEvent) (retry bool, err error) {
log.Printf("event - PubsubName:%s, Topic:%s, ID:%s, Data: %v", e.PubsubName, e.Topic, e.ID, e.Data)
log.Infof("event - PubsubName:%s, Topic:%s, ID:%s, Data: %v", e.PubsubName, e.Topic, e.ID, e.Data)
// do something with the event
return true, nil
}
Expand Down Expand Up @@ -92,7 +92,7 @@ The handler method itself can be any method with the expected signature:

```go
func echoHandler(ctx context.Context, in *common.InvocationEvent) (out *common.Content, err error) {
log.Printf("echo - ContentType:%s, Verb:%s, QueryString:%s, %+v", in.ContentType, in.Verb, in.QueryString, string(in.Data))
log.Infof("echo - ContentType:%s, Verb:%s, QueryString:%s, %+v", in.ContentType, in.Verb, in.QueryString, string(in.Data))
// do something with the invocation here
out = &common.Content{
Data: in.Data,
Expand All @@ -115,7 +115,7 @@ The handler method itself can be any method with the expected signature:

```go
func runHandler(ctx context.Context, in *common.BindingEvent) (out []byte, err error) {
log.Printf("binding - Data:%v, Meta:%v", in.Data, in.Metadata)
log.Infof("binding - Data:%v, Meta:%v", in.Data, in.Metadata)
// do something with the invocation here
return nil, 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
sadath-12 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading
Loading