-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Made rpcutil.LogCall to log RPC call on the server side. * Improved appserver.RPCGateway logging #195 * Changed appcommon.Key to use UUID.
- Loading branch information
志宇
committed
Mar 5, 2020
1 parent
8e03b43
commit 4dff2e3
Showing
10 changed files
with
103 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package appcommon | ||
|
||
import "github.com/SkycoinProject/dmsg/cipher" | ||
import ( | ||
"github.com/google/uuid" | ||
) | ||
|
||
// Key is an app key to authenticate within the | ||
// app server. | ||
type Key string | ||
|
||
// GenerateAppKey generates new app key. | ||
func GenerateAppKey() Key { | ||
raw, _ := cipher.GenerateKeyPair() | ||
return Key(raw.Hex()) | ||
return Key(uuid.New().String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package rpcutil | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// LogCall is used to log an RPC call from the rpc.Server | ||
func LogCall(log logrus.FieldLogger, method string, in interface{}) func(out interface{}, err *error) { | ||
|
||
// Just in case log is not set. | ||
// However, this is dangerous as it may result in a race condition. | ||
if log == nil { | ||
log = logrus.New() | ||
} | ||
|
||
start := time.Now() | ||
log = log. | ||
WithField("_method", method). | ||
WithField("_received", start.Format(time.Kitchen)) | ||
if in != nil { | ||
log = log.WithField("input", in) | ||
} | ||
|
||
return func(out interface{}, err *error) { | ||
log := log.WithField("_period", time.Since(start).String()) | ||
if out != nil { | ||
log = log.WithField("output", out) | ||
} | ||
if err != nil && *err != nil { | ||
log = log.WithError(*err) | ||
} | ||
log.Info("Request processed.") | ||
} | ||
} |
Oops, something went wrong.