Skip to content

Commit

Permalink
Aligned logging in membersrvc with that in peer.
Browse files Browse the repository at this point in the history
Moved logging modules from core to its own package so it could be shared, renamed flogging.
Fixes #897 #897
patch set from #2300
address review comment
rebased

Change-Id: I1124bf8f771dbf4d34cc836437caa1d5526f4f43
Signed-off-by: Christopher Ferris <chrisfer@us.ibm.com>
  • Loading branch information
christo4ferris committed Jul 31, 2016
1 parent dc6e24a commit 0ea65fd
Show file tree
Hide file tree
Showing 22 changed files with 242 additions and 255 deletions.
2 changes: 0 additions & 2 deletions core/chaincode/exectransaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package chaincode

import (
"fmt"
"io/ioutil"
"net"
"os"
"strconv"
Expand Down Expand Up @@ -56,7 +55,6 @@ func initMemSrvc() (net.Listener, error) {
//start clean
finitMemSrvc(nil)

ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
ca.CacheConfiguration() // Cache configuration

aca := ca.NewACA()
Expand Down
7 changes: 1 addition & 6 deletions core/crypto/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (

"bytes"
"fmt"
"io/ioutil"
"net"
"os"
"path/filepath"
Expand Down Expand Up @@ -436,7 +435,7 @@ func TestClientGetNextTCerts(t *testing.T) {
var nCerts int = 1
for i := 1; i < 3; i++ {
nCerts *= 10
fmt.Println(fmt.Sprintf("Calling GetNextTCerts(%d)", nCerts))
t.Logf("Calling GetNextTCerts(%d)", nCerts)
rvCerts, err := deployer.GetNextTCerts(nCerts)
if err != nil {
t.Fatalf("Could not receive %d TCerts", nCerts)
Expand Down Expand Up @@ -1524,7 +1523,6 @@ func setup() {
}

func initPKI() {
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
ca.CacheConfiguration() // Need cache the configuration first
aca = ca.NewACA()
eca = ca.NewECA()
Expand Down Expand Up @@ -1567,21 +1565,18 @@ func initNodes() {
// Init clients
err := initClients()
if err != nil {
fmt.Printf("Failed initializing clients [%s]\n", err)
panic(fmt.Errorf("Failed initializing clients [%s].", err))
}

// Init peer
err = initPeers()
if err != nil {
fmt.Printf("Failed initializing peers [%s]\n", err)
panic(fmt.Errorf("Failed initializing peers [%s].", err))
}

// Init validators
err = initValidators()
if err != nil {
fmt.Printf("Failed initializing validators [%s]\n", err)
panic(fmt.Errorf("Failed initializing validators [%s].", err))
}

Expand Down
2 changes: 1 addition & 1 deletion core/logging.go → flogging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package core
package flogging

import (
"os"
Expand Down
41 changes: 21 additions & 20 deletions core/logging_test.go → flogging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,29 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package core
package flogging_test

import (
"testing"

"github.com/hyperledger/fabric/flogging"
"github.com/op/go-logging"
"github.com/spf13/viper"
)

func TestLoggingLevelDefault(t *testing.T) {
viper.Reset()

LoggingInit("")
flogging.LoggingInit("")

assertDefaultLoggingLevel(t, DefaultLoggingLevel())
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
}

func TestLoggingLevelOtherThanDefault(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "warning")

LoggingInit("")
flogging.LoggingInit("")

assertDefaultLoggingLevel(t, logging.WARNING)
}
Expand All @@ -44,7 +45,7 @@ func TestLoggingLevelForSpecificModule(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "core=info")

LoggingInit("")
flogging.LoggingInit("")

assertModuleLoggingLevel(t, "core", logging.INFO)
}
Expand All @@ -53,7 +54,7 @@ func TestLoggingLeveltForMultipleModules(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "core=warning:test=debug")

LoggingInit("")
flogging.LoggingInit("")

assertModuleLoggingLevel(t, "core", logging.WARNING)
assertModuleLoggingLevel(t, "test", logging.DEBUG)
Expand All @@ -63,7 +64,7 @@ func TestLoggingLevelForMultipleModulesAtSameLevel(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "core,test=warning")

LoggingInit("")
flogging.LoggingInit("")

assertModuleLoggingLevel(t, "core", logging.WARNING)
assertModuleLoggingLevel(t, "test", logging.WARNING)
Expand All @@ -73,7 +74,7 @@ func TestLoggingLevelForModuleWithDefault(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "info:test=warning")

LoggingInit("")
flogging.LoggingInit("")

assertDefaultLoggingLevel(t, logging.INFO)
assertModuleLoggingLevel(t, "test", logging.WARNING)
Expand All @@ -83,7 +84,7 @@ func TestLoggingLevelForModuleWithDefaultAtEnd(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "test=warning:info")

LoggingInit("")
flogging.LoggingInit("")

assertDefaultLoggingLevel(t, logging.INFO)
assertModuleLoggingLevel(t, "test", logging.WARNING)
Expand All @@ -93,53 +94,53 @@ func TestLoggingLevelForSpecificCommand(t *testing.T) {
viper.Reset()
viper.Set("logging.node", "error")

LoggingInit("node")
flogging.LoggingInit("node")

assertDefaultLoggingLevel(t, logging.ERROR)
}

func TestLoggingLevelForUnknownCommandGoesToDefault(t *testing.T) {
viper.Reset()

LoggingInit("unknown command")
flogging.LoggingInit("unknown command")

assertDefaultLoggingLevel(t, DefaultLoggingLevel())
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
}

func TestLoggingLevelInvalid(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "invalidlevel")

LoggingInit("")
flogging.LoggingInit("")

assertDefaultLoggingLevel(t, DefaultLoggingLevel())
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
}

func TestLoggingLevelInvalidModules(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "core=invalid")

LoggingInit("")
flogging.LoggingInit("")

assertDefaultLoggingLevel(t, DefaultLoggingLevel())
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
}

func TestLoggingLevelInvalidEmptyModule(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "=warning")

LoggingInit("")
flogging.LoggingInit("")

assertDefaultLoggingLevel(t, DefaultLoggingLevel())
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
}

func TestLoggingLevelInvalidModuleSyntax(t *testing.T) {
viper.Reset()
viper.Set("logging_level", "type=warn=again")

LoggingInit("")
flogging.LoggingInit("")

assertDefaultLoggingLevel(t, DefaultLoggingLevel())
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
}

func assertDefaultLoggingLevel(t *testing.T, expectedLevel logging.Level) {
Expand Down
23 changes: 13 additions & 10 deletions membersrvc/ca/aca.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package ca
import (
"encoding/asn1"
"errors"
"fmt"
"google/protobuf"
"strings"
"time"
Expand All @@ -28,12 +27,16 @@ import (

"database/sql"

"github.com/hyperledger/fabric/flogging"
"github.com/op/go-logging"
"github.com/spf13/viper"
"google.golang.org/grpc"

pb "github.com/hyperledger/fabric/membersrvc/protos"
)

var acaLogger = logging.MustGetLogger("aca")

var (
//ACAAttribute is the base OID to the attributes extensions.
ACAAttribute = asn1.ObjectIdentifier{1, 2, 3, 4, 5, 6, 10}
Expand Down Expand Up @@ -220,7 +223,7 @@ func (attrPair *AttributePair) ToACAAttribute() *pb.ACAAttribute {
// NewACA sets up a new ACA.
func NewACA() *ACA {
aca := &ACA{CA: NewCA("aca", initializeACATables)}

flogging.LoggingInit("aca")
return aca
}

Expand Down Expand Up @@ -263,12 +266,12 @@ func (aca *ACA) fetchAttributes(id, affiliation string) ([]*AttributePair, error
}
attributes = append(attributes, attrPair)
} else {
Error.Printf("Invalid attribute entry '%v'", vals[0])
acaLogger.Errorf("Invalid attribute entry '%v'", vals[0])
}
}
}

fmt.Printf("%v %v", id, attributes)
acaLogger.Debugf("%v %v", id, attributes)

return attributes, nil
}
Expand Down Expand Up @@ -365,28 +368,28 @@ func (aca *ACA) findAttribute(owner *AttributeOwner, attributeName string) (*Att

func (aca *ACA) startACAP(srv *grpc.Server) {
pb.RegisterACAPServer(srv, &ACAP{aca})
Info.Println("ACA PUBLIC gRPC API server started")
acaLogger.Info("ACA PUBLIC gRPC API server started")
}

// Start starts the ACA.
func (aca *ACA) Start(srv *grpc.Server) {
Info.Println("Staring ACA services...")
acaLogger.Info("Staring ACA services...")
aca.startACAP(srv)
aca.gRPCServer = srv
Info.Println("ACA services started")
acaLogger.Info("ACA services started")
}

// Stop stops the ACA
func (aca *ACA) Stop() error {
Info.Println("Stopping the ACA services...")
acaLogger.Info("Stopping the ACA services...")
if aca.gRPCServer != nil {
aca.gRPCServer.Stop()
}
err := aca.CA.Stop()
if err != nil {
Error.Println("Error stopping the ACA services ", err)
acaLogger.Errorf("Error stopping the ACA services: %s ", err)
} else {
Info.Println("ACA services stopped")
acaLogger.Info("ACA services stopped")
}
return err
}
9 changes: 6 additions & 3 deletions membersrvc/ca/acap.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ import (
"crypto/x509/pkix"

"github.com/golang/protobuf/proto"
"github.com/op/go-logging"
"golang.org/x/net/context"

"github.com/hyperledger/fabric/core/crypto/primitives"
pb "github.com/hyperledger/fabric/membersrvc/protos"
)

var acapLogger = logging.MustGetLogger("acap")

// ACAP serves the public GRPC interface of the ACA.
//
type ACAP struct {
Expand All @@ -40,7 +43,7 @@ type ACAP struct {

// FetchAttributes fetchs the attributes from the outside world and populate them into the database.
func (acap *ACAP) FetchAttributes(ctx context.Context, in *pb.ACAFetchAttrReq) (*pb.ACAFetchAttrResp, error) {
Trace.Println("grpc ACAP:FetchAttributes")
acapLogger.Debug("grpc ACAP:FetchAttributes")

if in.Ts == nil || in.ECert == nil || in.Signature == nil {
return &pb.ACAFetchAttrResp{Status: pb.ACAFetchAttrResp_FAILURE, Msg: "Bad request"}, nil
Expand Down Expand Up @@ -107,7 +110,7 @@ func (acap *ACAP) createRequestAttributeResponse(status pb.ACAAttrResp_StatusCod

// RequestAttributes lookups the atributes in the database and return a certificate with attributes included in the request and found in the database.
func (acap *ACAP) RequestAttributes(ctx context.Context, in *pb.ACAAttrReq) (*pb.ACAAttrResp, error) {
Trace.Println("grpc ACAP:RequestAttributes")
acapLogger.Debug("grpc ACAP:RequestAttributes")

fail := pb.ACAAttrResp_FULL_SUCCESSFUL // else explicit which-param-failed error
if nil == in.Ts {
Expand Down Expand Up @@ -225,7 +228,7 @@ func (acap *ACAP) addAttributesToExtensions(attributes *[]AttributePair, extensi
// ReadCACertificate reads the certificate of the ACA.
//
func (acap *ACAP) ReadCACertificate(ctx context.Context, in *pb.Empty) (*pb.Cert, error) {
Trace.Println("grpc ACAP:ReadCACertificate")
acapLogger.Debug("grpc ACAP:ReadCACertificate")

return &pb.Cert{Cert: acap.aca.raw}, nil
}
Loading

0 comments on commit 0ea65fd

Please sign in to comment.