Skip to content

Commit

Permalink
[FAB-6272] Improve log vendoring
Browse files Browse the repository at this point in the history
This patch updates the pinning scripts to replace
Fabric, Fabric CA, & CFSSL logging mechanism with the SDK logger.
The SDK packages are also updated to use the SDK logger.

Change-Id: I16c8bd54b3d22caab526d07a3c27bd479b83226e
Signed-off-by: Troy Ronda <troy.ronda@securekey.com>
  • Loading branch information
troyronda committed Sep 29, 2017
1 parent a2f9ea8 commit b5ac164
Show file tree
Hide file tree
Showing 47 changed files with 431 additions and 337 deletions.
9 changes: 1 addition & 8 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@
# (https://github.com/golang/dep/blob/master/docs/FAQ.md#how-do-i-constrain-a-transitive-dependencys-version)

# Mainly downstreams that have a direct reference
[[override]]
name = "github.com/op/go-logging"
# TODO: source isn't picked up by parent projects - need better solution
source = "github.com/troyronda/go-logging" # TODO: Better home for this fork
branch = "datarace"
# note: go-logging is mainly a downstream package but is also in tests to ensure the fork is applied

[[override]]
name = "github.com/cloudflare/cfssl"
branch = "master"
Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric-ca/lib/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import (

cfsslapi "github.com/cloudflare/cfssl/api"
"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/log"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/tls"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric-ca/lib/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"fmt"
"net/http"

"github.com/cloudflare/cfssl/log"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package logbridge

import (
clog "github.com/cloudflare/cfssl/log"
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
)

var logger *logging.Logger
var cfLogBridge *cLogger

func init() {
logger = logging.NewLogger("fabric_sdk_go")
cfLogBridge = &cLogger{}
clog.SetLogger(cfLogBridge)
}

// Debug bridges calls to the Go SDK logger's Debug.
func Debug(args ...interface{}) {
logger.Debug(args...)
}

// Debugf bridges calls to the Go SDK logger's Debugf.
func Debugf(format string, args ...interface{}) {
logger.Debugf(format, args)
}

// Info bridges calls to the Go SDK logger's Info.
func Info(args ...interface{}) {
logger.Info(args...)
}

// Infof bridges calls to the Go SDK logger's Debugf.
func Infof(format string, args ...interface{}) {
logger.Infof(format, args...)
}

// Fatalf bridges calls to the Go SDK logger's Debugf.
func Fatalf(format string, args ...interface{}) {
logger.Fatalf(format, args...)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package logbridge

// cLogger implements CFSSL's SyslogWriter interface
type cLogger struct {
}

// Debug bridges calls to the Go SDK logger's Debug.
func (log *cLogger) Debug(s string) {
logger.Debug(s)
}

// Info bridges calls to the Go SDK logger's Info.
func (log *cLogger) Info(s string) {
logger.Info(s)
}

// Warning bridges calls to the Go SDK logger's Warn.
func (log *cLogger) Warning(s string) {
logger.Warn(s)
}

// Err bridges calls to the Go SDK logger's Error.
func (log *cLogger) Err(s string) {
logger.Error(s)
}

// Crit bridges calls to the Go SDK logger's Error.
func (log *cLogger) Crit(s string) {
logger.Error(s)
}

// Emerg bridges calls to the Go SDK logger's Error.
func (log *cLogger) Emerg(s string) {
logger.Error(s)
}
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric-ca/lib/signer.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ limitations under the License.
package lib

import (
"github.com/cloudflare/cfssl/log"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric-ca/lib/tls/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"io/ioutil"
"time"

"github.com/cloudflare/cfssl/log"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/factory"
Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric-ca/lib/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
"fmt"
"io/ioutil"

"github.com/cloudflare/cfssl/log"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/api"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/util"
"github.com/spf13/viper"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric-ca/util/csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ import (
"github.com/cloudflare/cfssl/config"
"github.com/cloudflare/cfssl/csr"
"github.com/cloudflare/cfssl/helpers"
"github.com/cloudflare/cfssl/log"
_ "github.com/cloudflare/cfssl/ocsp" // for ocspSignerFromConfig
"github.com/cloudflare/cfssl/signer"
"github.com/cloudflare/cfssl/signer/local"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/factory"
cspsigner "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/signer"
Expand Down
15 changes: 1 addition & 14 deletions internal/github.com/hyperledger/fabric-ca/util/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ import (
"strconv"
"strings"

"github.com/cloudflare/cfssl/log"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
"github.com/mitchellh/mapstructure"
"github.com/op/go-logging"
"github.com/spf13/cast"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down Expand Up @@ -138,18 +137,6 @@ func (fr *flagRegistrar) getTag(f *Field, tagName string) string {
return val
}

// CmdRunBegin is called at the beginning of each cobra run function
func CmdRunBegin() {
// If -d or --debug, set debug logging level
if viper.GetBool("debug") {
log.Level = log.LevelDebug

logging.SetLevel(logging.INFO, "bccsp")
logging.SetLevel(logging.INFO, "bccsp_p11")
logging.SetLevel(logging.INFO, "bccsp_sw")
}
}

// FlagString sets up a flag for a string, binding it to its name
func FlagString(flags *pflag.FlagSet, name, short string, def string, desc string) {
flags.StringP(name, short, def, desc)
Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric-ca/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import (
"strings"
"time"

"github.com/cloudflare/cfssl/log"
log "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric-ca/lib/logbridge"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
"github.com/spf13/viper"
"golang.org/x/crypto/ocsp"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package logbridge

import (
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
)

// Log levels (from fabric-sdk-go/pkg/logging/level.go).
const (
CRITICAL logging.Level = iota
ERROR
WARNING
INFO
DEBUG
)

// Logger bridges the SDK's logger struct
type Logger struct {
*logging.Logger
module string
}

// MustGetLogger bridges calls the Go SDK NewLogger
func MustGetLogger(module string) *Logger {
fabModule := "fabric_sdk_go"
logger := logging.NewLogger(fabModule)
return &Logger{
Logger: logger,
module: fabModule,
}
}

// Warningf bridges calls to the Go SDK logger's Warnf.
func (l *Logger) Warningf(format string, args ...interface{}) {
l.Warnf(format, args...)
}

// Warning bridges calls to the Go SDK logger's Warn.
func (l *Logger) Warning(format string, args ...interface{}) {
l.Warn(args...)
}

// IsEnabledFor bridges calls to the Go SDK logger's IsEnabledFor.
func (l *Logger) IsEnabledFor(level logging.Level) bool {
return logging.IsEnabledFor(level, l.module)
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (
"sync"
"time"

flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/config"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/flogging"
"github.com/spf13/viper"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import (
"golang.org/x/net/context"
"google.golang.org/grpc"

flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/comm"
mspmgmt "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp/mgmt"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/protos/utils"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/flogging"
ehpb "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/peer"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric/msp/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import (
"sync"

"github.com/golang/groupcache/lru"
flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/flogging"
pmsp "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
)

Expand Down
4 changes: 2 additions & 2 deletions internal/github.com/hyperledger/fabric/msp/identities.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import (
"time"

"github.com/golang/protobuf/proto"
flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/logbridge"
logging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/logbridge"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/flogging"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"
"github.com/op/go-logging"
)

var mspIdentityLogger = flogging.MustGetLogger("msp/identity")
Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric/msp/mgmt/mgmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (

"errors"

flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/logbridge"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/core/config"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp"
"github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/msp/cache"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/flogging"
)

// LoadLocalMsp loads the local MSP from the specified directory
Expand Down
2 changes: 1 addition & 1 deletion internal/github.com/hyperledger/fabric/msp/mspmgrimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ package msp
import (
"fmt"

"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/common/flogging"
flogging "github.com/hyperledger/fabric-sdk-go/internal/github.com/hyperledger/fabric/common/logbridge"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/protos/msp"

"github.com/golang/protobuf/proto"
Expand Down
7 changes: 2 additions & 5 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,14 @@ import (
"path/filepath"

"github.com/hyperledger/fabric-sdk-go/api/apiconfig"
"github.com/hyperledger/fabric-sdk-go/pkg/logging"
bccspFactory "github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/factory"
"github.com/hyperledger/fabric-sdk-go/third_party/github.com/hyperledger/fabric/bccsp/pkcs11"
"github.com/op/go-logging"
"github.com/spf13/viper"
)

var myViper = viper.New()
var logger = logging.MustGetLogger("fabric_sdk_go")
var format = logging.MustStringFormatter(
`%{color}%{time:15:04:05.000} [%{module}] %{level:.4s} : %{color:reset} %{message}`,
)
var logger = logging.NewLogger("fabric_sdk_go")

const (
cmdRoot = "fabric_sdk"
Expand Down
Loading

0 comments on commit b5ac164

Please sign in to comment.