Skip to content

Commit

Permalink
[FAB-8656] Initial logging modules
Browse files Browse the repository at this point in the history
This change introduces seperation between SDK modules for logging.

Change-Id: Ia87c00ca01594b180ed35c899bda3f72b75e2777
Signed-off-by: Troy Ronda <[email protected]>
  • Loading branch information
troyronda committed Mar 5, 2018
1 parent 4b576fd commit 3c009b4
Show file tree
Hide file tree
Showing 44 changed files with 55 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var logger *logging.Logger
var cfLogBridge *cLogger

func init() {
logger = logging.NewLogger("fabric_sdk_go")
logger = logging.NewLogger("fabsdk/fab")
cfLogBridge = &cLogger{}
clog.SetLogger(cfLogBridge)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ type Logger struct {

// MustGetLogger bridges calls the Go SDK NewLogger
func MustGetLogger(module string) *Logger {
fabModule := "fabric_sdk_go"
fabModule := "fabsdk/fab"
logger := logging.NewLogger(fabModule)
return &Logger{
Logger: logger,
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/channel/chclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

const (
defaultHandlerTimeout = time.Second * 10
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/channel/invoke/txnhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/client")

//EndorsementHandler for handling endorse transactions
type EndorsementHandler struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/common/discovery/greylist/greylist.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/client")

// Filter is a discovery filter that greylists certain peers that are
// known to be down for the configured amount of time
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/common"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/client")

const (
ccDataProviderSCC = "lscc"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/client")

type peerGroupResolver struct {
mspGroups []Group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/client")

// SelectionProvider implements selection provider
type SelectionProvider struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/ledger/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/client")

const (
defaultHandlerTimeout = time.Second * 10
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/resmgmt/resmgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ type SaveChannelRequest struct {
//RequestOption func for each Opts argument
type RequestOption func(opts *Opts) error

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/client")

// Client enables managing resources in Fabric network.
type Client struct {
Expand Down
16 changes: 12 additions & 4 deletions pkg/core/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ import (
cs "github.com/hyperledger/fabric-sdk-go/pkg/core/cryptosuite"
)

var logger = logging.NewLogger(logModule)
var logger = logging.NewLogger("fabsdk/core")

const (
cmdRoot = "FABRIC_SDK"
logModule = "fabric_sdk_go"
defaultTimeout = time.Second * 5
defaultConnIdleTimeout = time.Second * 30
defaultCacheSweepInterval = time.Second * 15
)

var logModules = [...]string{"fabsdk/client", "fabsdk/core", "fabsdk/fab"}

// Config represents the configuration for the client
type Config struct {
tlsCertPool *x509.CertPool
Expand Down Expand Up @@ -211,7 +212,9 @@ func initConfig(c *Config) (*Config, error) {
return nil, errors.WithMessage(err, "network configuration load failed")
}

logger.Infof("config %s logging level is set to: %s", logModule, loglevel.ParseString(logging.GetLevel(logModule)))
for _, logModule := range logModules {
logger.Infof("config %s logging level is set to: %s", logModule, loglevel.ParseString(logging.GetLevel(logModule)))
}
return c, nil
}

Expand All @@ -232,14 +235,19 @@ func setLogLevel(myViper *viper.Viper) {
loggingLevelString := myViper.GetString("client.logging.level")
logLevel := loglevel.INFO
if loggingLevelString != "" {
const logModule = "fabsdk" // TODO: allow more flexability in setting levels for different modules
logger.Debugf("%s logging level from the config: %v", logModule, loggingLevelString)
var err error
logLevel, err = logging.LogLevel(loggingLevelString)
if err != nil {
panic(err)
}
}
logging.SetLevel(logModule, logLevel)

// TODO: allow seperate settings for each
for _, logModule := range logModules {
logging.SetLevel(logModule, logLevel)
}
}

// load Default config
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func TestInitConfigWithCmdRoot(t *testing.T) {
TestInitConfigSuccess(t)
fileLoc := configTestFilePath
cmdRoot := "fabric_sdk"
var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")
logger.Infof("fileLoc is %s", fileLoc)

logger.Infof("fileLoc right before calling InitConfigWithCmdRoot is %s", fileLoc)
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/config/cryptoutil/cryptoutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
factory "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/sdkpatch/cryptosuitebridge"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")

// GetPrivateKeyFromCert will return private key represented by SKI in cert's public key
func GetPrivateKeyFromCert(cert []byte, cs core.CryptoSuite) (core.Key, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/config/urlutil/urlutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")

// IsTLSEnabled is a generic function that expects a URL and verifies if it has
// a prefix HTTPS or GRPCS to return true for TLS Enabled URLs or false otherwise
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/cryptosuite/bccsp/pkcs11/cryptosuiteimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")

//GetSuiteByConfig returns cryptosuite adaptor for bccsp loaded according to given config
func GetSuiteByConfig(config core.Config) (core.CryptoSuite, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/cryptosuite/bccsp/sw/cryptosuiteimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")

//GetSuiteByConfig returns cryptosuite adaptor for bccsp loaded according to given config
func GetSuiteByConfig(config core.Config) (core.CryptoSuite, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/cryptosuite/bccsp/wrapper/cryptosuiteimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")

//NewCryptoSuite returns cryptosuite adaptor for given bccsp.BCCSP implementation
func NewCryptoSuite(bccsp bccsp.BCCSP) core.CryptoSuite {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/cryptosuite/cryptosuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")

var initOnce sync.Once
var defaultCryptoSuite core.CryptoSuite
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/identitymgr/identitymgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/context/api/core"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")

// IdentityManager implements fab/IdentityManager
type IdentityManager struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/identitymgr/mocks/mockfabriccaserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/core")

// Matching key-cert pair. On enroll, the key will be
// imported into the key store, and the cert will be
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/ccpackager/gopackager/packager.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Descriptor struct {
// of the install payload.
var keep = []string{".go", ".c", ".h"}

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// NewCCPackage creates new go lang chaincode package
func NewCCPackage(chaincodePath string, goPath string) (*api.CCPackage, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/channel/ledger.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
pb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

const (
lscc = "lscc"
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/channel/membership/membership.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

type identityImpl struct {
mspManager msp.MSPManager
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/chconfig/chconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/context"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

const (
defaultMinResponses = 1
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/comm/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"google.golang.org/grpc/credentials"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// StreamProvider creates a GRPC stream
type StreamProvider func(conn *grpc.ClientConn) (grpc.ClientStream, error)
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// ConnectionState is the state of the client connection
type ConnectionState int32
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/client/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// Dispatcher is responsible for handling all events, including connection and registration events originating from the client,
// and events originating from the event server. All events are processed in a single Go routine
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/client/lbp/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// Random implements a random load-balance policy
type Random struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
ehpb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

const defaultTimeout = time.Second * 3

Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/deliverclient/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"google.golang.org/grpc"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

type deliverStream interface {
grpc.ClientStream
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/deliverclient/deliverclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// deliverProvider is the connection provider used for connecting to the Deliver service
var deliverProvider = func(channelID string, context fabcontext.Client, peer fab.Peer) (api.Connection, error) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/deliverclient/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

type dsConnection interface {
api.Connection
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/eventhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// EventHub allows a client to listen to event at a peer.
type EventHub struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/eventhubclient/connection/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// EventHubConnection manages the connection and client stream
// to the event hub server
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/eventhubclient/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

type ehConnection interface {
api.Connection
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/eventhubclient/eventhubclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

var ehConnProvider = func(channelID string, context context.Client, peer fab.Peer) (api.Connection, error) {
eventEndpoint, ok := peer.(api.EventEndpoint)
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/service/dispatcher/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/pkg/errors"
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

const (
dispatcherStateInitial = iota
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/events/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
stopTimeout = 5 * time.Second
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// EventProducer produces events which are dispatched to clients
type EventProducer interface {
Expand Down
2 changes: 1 addition & 1 deletion pkg/fab/keyvaluestore/filekeyvaluestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
newFileMode = 0600
)

var logger = logging.NewLogger("fabric_sdk_go")
var logger = logging.NewLogger("fabsdk/fab")

// KeySerializer converts a key to a unique fila path
type KeySerializer func(key interface{}) (string, error)
Expand Down
Loading

0 comments on commit 3c009b4

Please sign in to comment.