From 0ea65fd1ddbcffb83eef851cd63e25fdd2574855 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Wed, 27 Jul 2016 06:06:13 -0700 Subject: [PATCH] Aligned logging in membersrvc with that in peer. Moved logging modules from core to its own package so it could be shared, renamed flogging. Fixes #897 https://github.com/hyperledger/fabric/issues/897 patch set from https://github.com/hyperledger/fabric/pull/2300 address review comment rebased Change-Id: I1124bf8f771dbf4d34cc836437caa1d5526f4f43 Signed-off-by: Christopher Ferris --- core/chaincode/exectransaction_test.go | 2 - core/crypto/crypto_test.go | 7 +- {core => flogging}/logging.go | 2 +- {core => flogging}/logging_test.go | 41 ++++---- membersrvc/ca/aca.go | 23 +++-- membersrvc/ca/acap.go | 9 +- membersrvc/ca/ca.go | 129 +++++++++++++------------ membersrvc/ca/ca_test.go | 2 +- membersrvc/ca/eca.go | 32 +++--- membersrvc/ca/ecaa.go | 21 ++-- membersrvc/ca/ecap.go | 25 ++--- membersrvc/ca/membersrvc_test.go | 2 - membersrvc/ca/tca.go | 35 ++++--- membersrvc/ca/tca_test.go | 9 +- membersrvc/ca/tcaa.go | 9 +- membersrvc/ca/tcap.go | 19 ++-- membersrvc/ca/tlsca.go | 25 +++-- membersrvc/ca/tlsca_test.go | 2 - membersrvc/ca/util.go | 25 ----- membersrvc/membersrvc.yaml | 19 +++- membersrvc/server.go | 46 +++------ peer/main.go | 13 +-- 22 files changed, 242 insertions(+), 255 deletions(-) rename {core => flogging}/logging.go (99%) rename {core => flogging}/logging_test.go (79%) diff --git a/core/chaincode/exectransaction_test.go b/core/chaincode/exectransaction_test.go index 43a33b0a4da..23e4715a941 100644 --- a/core/chaincode/exectransaction_test.go +++ b/core/chaincode/exectransaction_test.go @@ -18,7 +18,6 @@ package chaincode import ( "fmt" - "io/ioutil" "net" "os" "strconv" @@ -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() diff --git a/core/crypto/crypto_test.go b/core/crypto/crypto_test.go index ea3853a7ca4..6a038c36ec8 100644 --- a/core/crypto/crypto_test.go +++ b/core/crypto/crypto_test.go @@ -22,7 +22,6 @@ import ( "bytes" "fmt" - "io/ioutil" "net" "os" "path/filepath" @@ -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) @@ -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() @@ -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)) } diff --git a/core/logging.go b/flogging/logging.go similarity index 99% rename from core/logging.go rename to flogging/logging.go index e3116300d84..f2e93a615ce 100644 --- a/core/logging.go +++ b/flogging/logging.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package core +package flogging import ( "os" diff --git a/core/logging_test.go b/flogging/logging_test.go similarity index 79% rename from core/logging_test.go rename to flogging/logging_test.go index 716caa161e6..000320b534f 100644 --- a/core/logging_test.go +++ b/flogging/logging_test.go @@ -14,11 +14,12 @@ 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" ) @@ -26,16 +27,16 @@ import ( 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) } @@ -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) } @@ -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) @@ -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) @@ -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) @@ -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) @@ -93,7 +94,7 @@ func TestLoggingLevelForSpecificCommand(t *testing.T) { viper.Reset() viper.Set("logging.node", "error") - LoggingInit("node") + flogging.LoggingInit("node") assertDefaultLoggingLevel(t, logging.ERROR) } @@ -101,45 +102,45 @@ func TestLoggingLevelForSpecificCommand(t *testing.T) { 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) { diff --git a/membersrvc/ca/aca.go b/membersrvc/ca/aca.go index ce76a4f4985..c0d83e814fe 100644 --- a/membersrvc/ca/aca.go +++ b/membersrvc/ca/aca.go @@ -19,7 +19,6 @@ package ca import ( "encoding/asn1" "errors" - "fmt" "google/protobuf" "strings" "time" @@ -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} @@ -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 } @@ -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 } @@ -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 } diff --git a/membersrvc/ca/acap.go b/membersrvc/ca/acap.go index 722fc03e497..4ab6114c763 100644 --- a/membersrvc/ca/acap.go +++ b/membersrvc/ca/acap.go @@ -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 { @@ -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 @@ -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 { @@ -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 } diff --git a/membersrvc/ca/ca.go b/membersrvc/ca/ca.go index e77e6615b46..05789be7dbb 100644 --- a/membersrvc/ca/ca.go +++ b/membersrvc/ca/ca.go @@ -36,12 +36,15 @@ import ( "time" "github.com/hyperledger/fabric/core/crypto/primitives" + "github.com/hyperledger/fabric/flogging" pb "github.com/hyperledger/fabric/membersrvc/protos" - _ "github.com/mattn/go-sqlite3" // This blank import is required to load sqlite3 driver + "github.com/op/go-logging" "github.com/spf13/viper" ) +var caLogger = logging.MustGetLogger("ca") + // CA is the base certificate authority. type CA struct { db *sql.DB @@ -123,6 +126,7 @@ func NewDefaultCertificateSpecWithCommonName(id string, commonName string, pub i return NewDefaultPeriodCertificateSpecWithCommonName(id, commonName, serialNumber, pub, usage, opt...) } +// CacheConfiguration caches the viper configuration func CacheConfiguration() { caOrganization = viper.GetString("pki.ca.subject.organization") caCountry = viper.GetString("pki.ca.subject.country") @@ -221,28 +225,29 @@ func initializeCommonTables(db *sql.DB) error { // NewCA sets up a new CA. func NewCA(name string, initTables TableInitializer) *CA { ca := new(CA) + flogging.LoggingInit("ca") ca.path = filepath.Join(rootPath, caDir) if _, err := os.Stat(ca.path); err != nil { - Info.Println("Fresh start; creating databases, key pairs, and certificates.") + caLogger.Info("Fresh start; creating databases, key pairs, and certificates.") if err := os.MkdirAll(ca.path, 0755); err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } } // open or create certificate database db, err := sql.Open("sqlite3", ca.path+"/"+name+".db") if err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } if err = db.Ping(); err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } if err = initTables(db); err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } ca.db = db @@ -260,7 +265,7 @@ func NewCA(name string, initTables TableInitializer) *CA { } cert, err := x509.ParseCertificate(raw) if err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } ca.raw = raw @@ -269,19 +274,19 @@ func NewCA(name string, initTables TableInitializer) *CA { return ca } -// Close closes down the CA. +// Stop Close closes down the CA. func (ca *CA) Stop() error { err := ca.db.Close() if err == nil { - Trace.Println("Shutting down CA - Successfully") + caLogger.Debug("Shutting down CA - Successfully") } else { - Trace.Println(fmt.Sprintf("Shutting down CA - Error closing DB [%s]", err)) + caLogger.Debug(fmt.Sprintf("Shutting down CA - Error closing DB [%s]", err)) } return err } func (ca *CA) createCAKeyPair(name string) *ecdsa.PrivateKey { - Trace.Println("Creating CA key pair.") + caLogger.Debug("Creating CA key pair.") curve := primitives.GetDefaultCurve() @@ -295,7 +300,7 @@ func (ca *CA) createCAKeyPair(name string) *ecdsa.PrivateKey { }) err = ioutil.WriteFile(ca.path+"/"+name+".priv", cooked, 0644) if err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } raw, _ = x509.MarshalPKIXPublicKey(&priv.PublicKey) @@ -306,18 +311,18 @@ func (ca *CA) createCAKeyPair(name string) *ecdsa.PrivateKey { }) err = ioutil.WriteFile(ca.path+"/"+name+".pub", cooked, 0644) if err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } } if err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } return priv } func (ca *CA) readCAPrivateKey(name string) (*ecdsa.PrivateKey, error) { - Trace.Println("Reading CA private key.") + caLogger.Debug("Reading CA private key.") cooked, err := ioutil.ReadFile(ca.path + "/" + name + ".priv") if err != nil { @@ -329,11 +334,11 @@ func (ca *CA) readCAPrivateKey(name string) (*ecdsa.PrivateKey, error) { } func (ca *CA) createCACertificate(name string, pub *ecdsa.PublicKey) []byte { - Trace.Println("Creating CA certificate.") + caLogger.Debug("Creating CA certificate.") raw, err := ca.newCertificate(name, pub, x509.KeyUsageDigitalSignature|x509.KeyUsageCertSign, nil) if err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } cooked := pem.EncodeToMemory( @@ -343,14 +348,14 @@ func (ca *CA) createCACertificate(name string, pub *ecdsa.PublicKey) []byte { }) err = ioutil.WriteFile(ca.path+"/"+name+".cert", cooked, 0644) if err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } return raw } func (ca *CA) readCACertificate(name string) ([]byte, error) { - Trace.Println("Reading CA certificate.") + caLogger.Debug("Reading CA certificate.") cooked, err := ioutil.ReadFile(ca.path + "/" + name + ".cert") if err != nil { @@ -367,11 +372,11 @@ func (ca *CA) createCertificate(id string, pub interface{}, usage x509.KeyUsage, } func (ca *CA) createCertificateFromSpec(spec *CertificateSpec, timestamp int64, kdfKey []byte, persist bool) ([]byte, error) { - Trace.Println("Creating certificate for " + spec.GetID() + ".") + caLogger.Debug("Creating certificate for " + spec.GetID() + ".") raw, err := ca.newCertificateFromSpec(spec) if err != nil { - Error.Println(err) + caLogger.Error(err) return nil, err } @@ -391,7 +396,7 @@ func (ca *CA) persistCertificate(id string, timestamp int64, usage x509.KeyUsage var err error if _, err = ca.db.Exec("INSERT INTO Certificates (id, timestamp, usage, cert, hash, kdfkey) VALUES (?, ?, ?, ?, ?, ?)", id, timestamp, usage, certRaw, hash.Sum(nil), kdfKey); err != nil { - Error.Println(err) + caLogger.Error(err) } return err } @@ -442,14 +447,14 @@ func (ca *CA) newCertificateFromSpec(spec *CertificateSpec) ([]byte, error) { ca.priv, ) if isCA && err != nil { - Panic.Panicln(err) + caLogger.Panic(err) } return raw, err } func (ca *CA) readCertificateByKeyUsage(id string, usage x509.KeyUsage) ([]byte, error) { - Trace.Printf("Reading certificate for %s and usage %v", id, usage) + caLogger.Debugf("Reading certificate for %s and usage %v", id, usage) mutex.RLock() defer mutex.RUnlock() @@ -458,14 +463,14 @@ func (ca *CA) readCertificateByKeyUsage(id string, usage x509.KeyUsage) ([]byte, err := ca.db.QueryRow("SELECT cert FROM Certificates WHERE id=? AND usage=?", id, usage).Scan(&raw) if err != nil { - Trace.Printf("readCertificateByKeyUsage() Error: %v", err) + caLogger.Debugf("readCertificateByKeyUsage() Error: %v", err) } return raw, err } func (ca *CA) readCertificateByTimestamp(id string, ts int64) ([]byte, error) { - Trace.Println("Reading certificate for " + id + ".") + caLogger.Debug("Reading certificate for " + id + ".") mutex.RLock() defer mutex.RUnlock() @@ -477,7 +482,7 @@ func (ca *CA) readCertificateByTimestamp(id string, ts int64) ([]byte, error) { } func (ca *CA) readCertificates(id string, opt ...int64) (*sql.Rows, error) { - Trace.Println("Reading certificatess for " + id + ".") + caLogger.Debug("Reading certificatess for " + id + ".") mutex.RLock() defer mutex.RUnlock() @@ -490,7 +495,7 @@ func (ca *CA) readCertificates(id string, opt ...int64) (*sql.Rows, error) { } func (ca *CA) readCertificateSets(id string, start, end int64) (*sql.Rows, error) { - Trace.Println("Reading certificate sets for " + id + ".") + caLogger.Debug("Reading certificate sets for " + id + ".") mutex.RLock() defer mutex.RUnlock() @@ -499,7 +504,7 @@ func (ca *CA) readCertificateSets(id string, start, end int64) (*sql.Rows, error } func (ca *CA) readCertificateByHash(hash []byte) ([]byte, error) { - Trace.Println("Reading certificate for hash " + string(hash) + ".") + caLogger.Debug("Reading certificate for hash " + string(hash) + ".") mutex.RLock() defer mutex.RUnlock() @@ -512,7 +517,7 @@ func (ca *CA) readCertificateByHash(hash []byte) ([]byte, error) { } func (ca *CA) isValidAffiliation(affiliation string) (bool, error) { - Trace.Println("Validating affiliation: " + affiliation) + caLogger.Debug("Validating affiliation: " + affiliation) mutex.RLock() defer mutex.RUnlock() @@ -521,11 +526,11 @@ func (ca *CA) isValidAffiliation(affiliation string) (bool, error) { var err error err = ca.db.QueryRow("SELECT count(row) FROM AffiliationGroups WHERE name=?", affiliation).Scan(&count) if err != nil { - Trace.Println("Affiliation <" + affiliation + "> is INVALID.") + caLogger.Debug("Affiliation <" + affiliation + "> is INVALID.") return false, err } - Trace.Println("Affiliation <" + affiliation + "> is VALID.") + caLogger.Debug("Affiliation <" + affiliation + "> is VALID.") return count == 1, nil } @@ -540,7 +545,7 @@ func (ca *CA) isValidAffiliation(affiliation string) (bool, error) { func (ca *CA) requireAffiliation(role pb.Role) bool { roleStr, _ := MemberRoleToString(role) - Trace.Println("Assigned role is: " + roleStr + ".") + caLogger.Debug("Assigned role is: " + roleStr + ".") return role != pb.Role_VALIDATOR && role != pb.Role_AUDITOR } @@ -548,7 +553,7 @@ func (ca *CA) requireAffiliation(role pb.Role) bool { // validateAndGenerateEnrollID validates the affiliation subject func (ca *CA) validateAndGenerateEnrollID(id, affiliation string, role pb.Role) (string, error) { roleStr, _ := MemberRoleToString(role) - Trace.Println("Validating and generating enrollID for user id: " + id + ", affiliation: " + affiliation + ", role: " + roleStr + ".") + caLogger.Debug("Validating and generating enrollID for user id: " + id + ", affiliation: " + affiliation + ", role: " + roleStr + ".") // Check whether the affiliation is required for the current user. // @@ -561,7 +566,7 @@ func (ca *CA) validateAndGenerateEnrollID(id, affiliation string, role pb.Role) } if !valid { - Trace.Println("Invalid affiliation group: ") + caLogger.Debug("Invalid affiliation group: ") return "", errors.New("Invalid affiliation group " + affiliation) } @@ -576,7 +581,7 @@ func (ca *CA) validateAndGenerateEnrollID(id, affiliation string, role pb.Role) func (ca *CA) registerUser(id, affiliation string, role pb.Role, registrar, memberMetadata string, opt ...string) (string, error) { memberMetadata = removeQuotes(memberMetadata) roleStr, _ := MemberRoleToString(role) - Trace.Printf("Received request to register user with id: %s, affiliation: %s, role: %s, registrar: %s, memberMetadata: %s\n", + caLogger.Debugf("Received request to register user with id: %s, affiliation: %s, role: %s, registrar: %s, memberMetadata: %s\n", id, affiliation, roleStr, registrar, memberMetadata) var enrollID, tok string @@ -615,7 +620,7 @@ func (ca *CA) registerUserWithEnrollID(id string, enrollID string, role pb.Role, defer mutex.Unlock() roleStr, _ := MemberRoleToString(role) - Trace.Printf("Registering user %s as %s with memberMetadata %s\n", id, roleStr, memberMetadata) + caLogger.Debugf("Registering user %s as %s with memberMetadata %s\n", id, roleStr, memberMetadata) var tok string if len(opt) > 0 && len(opt[0]) > 0 { @@ -633,7 +638,7 @@ func (ca *CA) registerUserWithEnrollID(id string, enrollID string, role pb.Role, _, err = ca.db.Exec("INSERT INTO Users (id, enrollmentId, token, role, metadata, state) VALUES (?, ?, ?, ?, ?, ?)", id, enrollID, tok, role, memberMetadata, 0) if err != nil { - Error.Println(err) + caLogger.Error(err) } return tok, err @@ -645,7 +650,7 @@ func (ca *CA) registerAffiliationGroup(name string, parentName string) error { mutex.Lock() defer mutex.Unlock() - Trace.Println("Registering affiliation group " + name + " parent " + parentName + ".") + caLogger.Debug("Registering affiliation group " + name + " parent " + parentName + ".") var parentID int var err error @@ -668,7 +673,7 @@ func (ca *CA) registerAffiliationGroup(name string, parentName string) error { _, err = ca.db.Exec("INSERT INTO AffiliationGroups (name, parent) VALUES (?, ?)", name, parentID) if err != nil { - Error.Println(err) + caLogger.Error(err) } return err @@ -678,7 +683,7 @@ func (ca *CA) registerAffiliationGroup(name string, parentName string) error { // deleteUser deletes a user given a name // func (ca *CA) deleteUser(id string) error { - Trace.Println("Deleting user " + id + ".") + caLogger.Debug("Deleting user " + id + ".") mutex.Lock() defer mutex.Unlock() @@ -688,12 +693,12 @@ func (ca *CA) deleteUser(id string) error { if err == nil { _, err = ca.db.Exec("DELETE FROM Certificates Where id=?", id) if err != nil { - Error.Println(err) + caLogger.Error(err) } _, err = ca.db.Exec("DELETE FROM Users WHERE row=?", row) if err != nil { - Error.Println(err) + caLogger.Error(err) } } @@ -703,7 +708,7 @@ func (ca *CA) deleteUser(id string) error { // readUser reads a token given an id // func (ca *CA) readUser(id string) *sql.Row { - Trace.Println("Reading token for " + id + ".") + caLogger.Debug("Reading token for " + id + ".") mutex.RLock() defer mutex.RUnlock() @@ -714,7 +719,7 @@ func (ca *CA) readUser(id string) *sql.Row { // readUsers reads users of a given Role // func (ca *CA) readUsers(role int) (*sql.Rows, error) { - Trace.Println("Reading users matching role " + strconv.FormatInt(int64(role), 2) + ".") + caLogger.Debug("Reading users matching role " + strconv.FormatInt(int64(role), 2) + ".") return ca.db.Query("SELECT id, role FROM Users WHERE role&?!=0", role) } @@ -722,7 +727,7 @@ func (ca *CA) readUsers(role int) (*sql.Rows, error) { // readRole returns the user Role given a user id // func (ca *CA) readRole(id string) int { - Trace.Println("Reading role for " + id + ".") + caLogger.Debug("Reading role for " + id + ".") mutex.RLock() defer mutex.RUnlock() @@ -734,7 +739,7 @@ func (ca *CA) readRole(id string) int { } func (ca *CA) readAffiliationGroups() ([]*AffiliationGroup, error) { - Trace.Println("Reading affilition groups.") + caLogger.Debug("Reading affilition groups.") rows, err := ca.db.Query("SELECT row, name, parent FROM AffiliationGroups") if err != nil { @@ -804,24 +809,24 @@ func (ca *CA) canRegister(registrar string, newMemberRole string, newMemberMetad var registrarMetadataStr string err := ca.db.QueryRow("SELECT metadata FROM Users WHERE id=?", registrar).Scan(®istrarMetadataStr) if err != nil { - Trace.Printf("CA.canRegister: db error: %s\n", err.Error()) + caLogger.Debugf("CA.canRegister: db error: %s\n", err.Error()) return err } - Trace.Printf("CA.canRegister: registrar=%s, registrarMD=%s, newMemberRole=%s, newMemberMD=%s", + caLogger.Debugf("CA.canRegister: registrar=%s, registrarMD=%s, newMemberRole=%s, newMemberMD=%s", registrar, registrarMetadataStr, newMemberRole, newMemberMetadataStr) // If isn't a registrar at all, then error if registrarMetadataStr == "" { - Trace.Println("canRegister: member " + registrar + " is not a registrar") + caLogger.Debug("canRegister: member " + registrar + " is not a registrar") return errors.New("member " + registrar + " is not a registrar") } // Get the registrar's metadata - Trace.Println("CA.canRegister: parsing registrar's metadata") + caLogger.Debug("CA.canRegister: parsing registrar's metadata") registrarMetadata, err := newMemberMetadata(registrarMetadataStr) if err != nil { return err } // Convert the user's meta to an object - Trace.Println("CA.canRegister: parsing new member's metadata") + caLogger.Debug("CA.canRegister: parsing new member's metadata") newMemberMetadata, err := newMemberMetadata(newMemberMetadataStr) if err != nil { return err @@ -833,15 +838,15 @@ func (ca *CA) canRegister(registrar string, newMemberRole string, newMemberMetad // Convert a string to a MemberMetadata func newMemberMetadata(metadata string) (*MemberMetadata, error) { if metadata == "" { - Trace.Println("newMemberMetadata: nil") + caLogger.Debug("newMemberMetadata: nil") return nil, nil } var mm MemberMetadata err := json.Unmarshal([]byte(metadata), &mm) if err != nil { - Trace.Printf("newMemberMetadata: error: %s, metadata: %s\n", err.Error(), metadata) + caLogger.Debugf("newMemberMetadata: error: %s, metadata: %s\n", err.Error(), metadata) } - Trace.Printf("newMemberMetadata: metadata=%s, object=%+v\n", metadata, mm) + caLogger.Debugf("newMemberMetadata: metadata=%s, object=%+v\n", metadata, mm) return &mm, err } @@ -860,15 +865,15 @@ type Registrar struct { // with MemberMetadata of 'newMemberMetadata' func (mm *MemberMetadata) canRegister(registrar string, newRole string, newMemberMetadata *MemberMetadata) error { // Can register a member of this type? - Trace.Printf("MM.canRegister registrar=%s, newRole=%s\n", registrar, newRole) + caLogger.Debugf("MM.canRegister registrar=%s, newRole=%s\n", registrar, newRole) if !strContained(newRole, mm.Registrar.Roles) { - Trace.Printf("MM.canRegister: role %s can't be registered by %s\n", newRole, registrar) + caLogger.Debugf("MM.canRegister: role %s can't be registered by %s\n", newRole, registrar) return errors.New("member " + registrar + " may not register member of type " + newRole) } // The registrar privileges that are being registered must not be larger than the registrar's if newMemberMetadata == nil { // Not requesting registrar privileges for this member, so we are OK - Trace.Println("MM.canRegister: not requesting registrar privileges") + caLogger.Debug("MM.canRegister: not requesting registrar privileges") return nil } return strsContained(newMemberMetadata.Registrar.Roles, mm.Registrar.DelegateRoles, registrar, "delegateRoles") @@ -876,14 +881,14 @@ func (mm *MemberMetadata) canRegister(registrar string, newRole string, newMembe // Return an error if all strings in 'strs1' are not contained in 'strs2' func strsContained(strs1 []string, strs2 []string, registrar string, field string) error { - Trace.Printf("CA.strsContained: registrar=%s, field=%s, strs1=%+v, strs2=%+v\n", registrar, field, strs1, strs2) + caLogger.Debugf("CA.strsContained: registrar=%s, field=%s, strs1=%+v, strs2=%+v\n", registrar, field, strs1, strs2) for _, s := range strs1 { if !strContained(s, strs2) { - Trace.Printf("CA.strsContained: no: %s not in %+v\n", s, strs2) + caLogger.Debugf("CA.strsContained: no: %s not in %+v\n", s, strs2) return errors.New("user " + registrar + " may not register " + field + " " + s) } } - Trace.Println("CA.strsContained: ok") + caLogger.Debug("CA.strsContained: ok") return nil } @@ -920,6 +925,6 @@ func removeQuotes(str string) string { (strings.HasPrefix(str, "\"") && strings.HasSuffix(str, "\"")) { str = str[1 : len(str)-1] } - Trace.Printf("removeQuotes: %s\n", str) + caLogger.Debugf("removeQuotes: %s\n", str) return str } diff --git a/membersrvc/ca/ca_test.go b/membersrvc/ca/ca_test.go index 685859f699e..9bcc114b387 100644 --- a/membersrvc/ca/ca_test.go +++ b/membersrvc/ca/ca_test.go @@ -45,8 +45,8 @@ func TestNewCA(t *testing.T) { } //initialize logging to avoid panics in the current code - LogInit(os.Stdout, os.Stdout, os.Stdout, os.Stderr, os.Stdout) CacheConfiguration() // Cache configuration + //Create new CA ca := NewCA(name, initializeTables) if ca == nil { diff --git a/membersrvc/ca/eca.go b/membersrvc/ca/eca.go index e465a42b8a3..9fcb5e129ec 100644 --- a/membersrvc/ca/eca.go +++ b/membersrvc/ca/eca.go @@ -29,11 +29,15 @@ import ( "strings" "github.com/hyperledger/fabric/core/crypto/primitives" + "github.com/hyperledger/fabric/flogging" pb "github.com/hyperledger/fabric/membersrvc/protos" + "github.com/op/go-logging" "github.com/spf13/viper" "google.golang.org/grpc" ) +var ecaLogger = logging.MustGetLogger("eca") + var ( // ECertSubjectRole is the ASN1 object identifier of the subject's role. // @@ -57,10 +61,12 @@ func initializeECATables(db *sql.DB) error { // func NewECA() *ECA { eca := &ECA{CA: NewCA("eca", initializeECATables)} + flogging.LoggingInit("eca") { // read or create global symmetric encryption key var cooked string + var l = logging.MustGetLogger("ECA") raw, err := ioutil.ReadFile(eca.path + "/obc.aes") if err != nil { @@ -71,7 +77,7 @@ func NewECA() *ECA { err = ioutil.WriteFile(eca.path+"/obc.aes", []byte(cooked), 0644) if err != nil { - Panic.Panicln(err) + l.Panic(err) } } else { cooked = string(raw) @@ -79,7 +85,7 @@ func NewECA() *ECA { eca.obcKey, err = base64.StdEncoding.DecodeString(cooked) if err != nil { - Panic.Panicln(err) + l.Panic(err) } } @@ -91,12 +97,12 @@ func NewECA() *ECA { block, _ := pem.Decode(cooked) priv, err = x509.ParseECPrivateKey(block.Bytes) if err != nil { - Panic.Panicln(err) + ecaLogger.Panic(err) } } else { priv, err = ecdsa.GenerateKey(primitives.GetDefaultCurve(), rand.Reader) if err != nil { - Panic.Panicln(err) + ecaLogger.Panic(err) } raw, _ := x509.MarshalECPrivateKey(priv) @@ -107,7 +113,7 @@ func NewECA() *ECA { }) err := ioutil.WriteFile(eca.path+"/obc.ecies", cooked, 0644) if err != nil { - Panic.Panicln(err) + ecaLogger.Panic(err) } } @@ -134,7 +140,7 @@ func (eca *ECA) populateUsersTable() { vals := strings.Fields(flds) role, err := strconv.Atoi(vals[0]) if err != nil { - Panic.Panicln(err) + ecaLogger.Panic(err) } var affiliation, memberMetadata, registrar string if len(vals) >= 3 { @@ -182,35 +188,35 @@ func (eca *ECA) populateAffiliationGroupsTable() { // Start starts the ECA. // func (eca *ECA) Start(srv *grpc.Server) { - Info.Println("Starting ECA...") + ecaLogger.Info("Starting ECA...") eca.startECAP(srv) eca.startECAA(srv) eca.gRPCServer = srv - Info.Println("ECA started.") + ecaLogger.Info("ECA started.") } // Stop stops the ECA services. func (eca *ECA) Stop() { - Info.Println("Stopping ECA services...") + ecaLogger.Info("Stopping ECA services...") if eca.gRPCServer != nil { eca.gRPCServer.Stop() } err := eca.CA.Stop() if err != nil { - Error.Println("ECA Error stopping services ", err) + ecaLogger.Errorf("ECA Error stopping services: %s", err) } else { - Info.Println("ECA stopped") + ecaLogger.Info("ECA stopped") } } func (eca *ECA) startECAP(srv *grpc.Server) { pb.RegisterECAPServer(srv, &ECAP{eca}) - Info.Println("ECA PUBLIC gRPC API server started") + ecaLogger.Info("ECA PUBLIC gRPC API server started") } func (eca *ECA) startECAA(srv *grpc.Server) { pb.RegisterECAAServer(srv, &ECAA{eca}) - Info.Println("ECA ADMIN gRPC API server started") + ecaLogger.Info("ECA ADMIN gRPC API server started") } diff --git a/membersrvc/ca/ecaa.go b/membersrvc/ca/ecaa.go index 21e303a30b6..40af1c1fe06 100644 --- a/membersrvc/ca/ecaa.go +++ b/membersrvc/ca/ecaa.go @@ -26,9 +26,12 @@ import ( "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric/core/crypto/primitives" pb "github.com/hyperledger/fabric/membersrvc/protos" + "github.com/op/go-logging" "golang.org/x/net/context" ) +var ecaaLogger = logging.MustGetLogger("ecaa") + // ECAA serves the administrator GRPC interface of the ECA. // type ECAA struct { @@ -39,7 +42,7 @@ type ECAA struct { // an error is returned. // func (ecaa *ECAA) RegisterUser(ctx context.Context, in *pb.RegisterUserReq) (*pb.Token, error) { - Trace.Println("gRPC ECAA:RegisterUser") + ecaaLogger.Debug("gRPC ECAA:RegisterUser") // Check the signature err := ecaa.checkRegistrarSignature(in) @@ -56,7 +59,7 @@ func (ecaa *ECAA) RegisterUser(ctx context.Context, in *pb.RegisterUserReq) (*pb return nil, err } jsonStr := string(json) - Trace.Println("gRPC ECAA:RegisterUser: json=" + jsonStr) + ecaaLogger.Debugf("gRPC ECAA:RegisterUser: json=%s", jsonStr) tok, err := ecaa.eca.registerUser(in.Id.Id, in.Affiliation, in.Role, registrarID, jsonStr) // Return the one-time password @@ -65,11 +68,11 @@ func (ecaa *ECAA) RegisterUser(ctx context.Context, in *pb.RegisterUserReq) (*pb } func (ecaa *ECAA) checkRegistrarSignature(in *pb.RegisterUserReq) error { - Trace.Println("ECAA.checkRegistrarSignature") + ecaaLogger.Debug("ECAA.checkRegistrarSignature") // If no registrar was specified if in.Registrar == nil || in.Registrar.Id == nil || in.Registrar.Id.Id == "" { - Trace.Println("gRPC ECAA:checkRegistrarSignature: no registrar was specified") + ecaaLogger.Debug("gRPC ECAA:checkRegistrarSignature: no registrar was specified") return errors.New("no registrar was specified") } @@ -102,19 +105,19 @@ func (ecaa *ECAA) checkRegistrarSignature(in *pb.RegisterUserReq) error { // Check the signature if ecdsa.Verify(cert.PublicKey.(*ecdsa.PublicKey), hash.Sum(nil), r, s) == false { // Signature verification failure - Trace.Printf("ECAA.checkRegistrarSignature: failure for %s\n", registrar) + ecaaLogger.Debugf("ECAA.checkRegistrarSignature: failure for %s", registrar) return errors.New("Signature verification failed.") } // Signature verification was successful - Trace.Printf("ECAA.checkRegistrarSignature: success for %s\n", registrar) + ecaaLogger.Debugf("ECAA.checkRegistrarSignature: success for %s", registrar) return nil } // ReadUserSet returns a list of users matching the parameters set in the read request. // func (ecaa *ECAA) ReadUserSet(ctx context.Context, in *pb.ReadUserSetReq) (*pb.UserSet, error) { - Trace.Println("gRPC ECAA:ReadUserSet") + ecaaLogger.Debug("gRPC ECAA:ReadUserSet") req := in.Req.Id if ecaa.eca.readRole(req)&int(pb.Role_AUDITOR) == 0 { @@ -168,7 +171,7 @@ func (ecaa *ECAA) ReadUserSet(ctx context.Context, in *pb.ReadUserSetReq) (*pb.U // RevokeCertificate revokes a certificate from the ECA. Not yet implemented. // func (ecaa *ECAA) RevokeCertificate(context.Context, *pb.ECertRevokeReq) (*pb.CAStatus, error) { - Trace.Println("gRPC ECAA:RevokeCertificate") + ecaaLogger.Debug("gRPC ECAA:RevokeCertificate") return nil, errors.New("ECAA:RevokeCertificate method not (yet) implemented") } @@ -176,7 +179,7 @@ func (ecaa *ECAA) RevokeCertificate(context.Context, *pb.ECertRevokeReq) (*pb.CA // PublishCRL requests the creation of a certificate revocation list from the ECA. Not yet implemented. // func (ecaa *ECAA) PublishCRL(context.Context, *pb.ECertCRLReq) (*pb.CAStatus, error) { - Trace.Println("gRPC ECAA:CreateCRL") + ecaaLogger.Debug("gRPC ECAA:CreateCRL") return nil, errors.New("ECAA:PublishCRL method not (yet) implemented") } diff --git a/membersrvc/ca/ecap.go b/membersrvc/ca/ecap.go index 3d2ddfb231b..988bf0ad41b 100644 --- a/membersrvc/ca/ecap.go +++ b/membersrvc/ca/ecap.go @@ -34,10 +34,13 @@ import ( "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric/core/crypto/primitives" pb "github.com/hyperledger/fabric/membersrvc/protos" + "github.com/op/go-logging" "github.com/spf13/viper" "golang.org/x/net/context" ) +var ecapLogger = logging.MustGetLogger("ecap") + // ECAP serves the public GRPC interface of the ECA. // type ECAP struct { @@ -47,7 +50,7 @@ type ECAP struct { // ReadCACertificate reads the certificate of the ECA. // func (ecap *ECAP) ReadCACertificate(ctx context.Context, in *pb.Empty) (*pb.Cert, error) { - Trace.Println("gRPC ECAP:ReadCACertificate") + ecapLogger.Debug("gRPC ECAP:ReadCACertificate") return &pb.Cert{Cert: ecap.eca.raw}, nil } @@ -98,7 +101,7 @@ func (ecap *ECAP) fetchAttributes(cert *pb.Cert) error { // CreateCertificatePair requests the creation of a new enrollment certificate pair by the ECA. // func (ecap *ECAP) CreateCertificatePair(ctx context.Context, in *pb.ECertCreateReq) (*pb.ECertCreateResp, error) { - Trace.Println("gRPC ECAP:CreateCertificate") + ecapLogger.Debug("gRPC ECAP:CreateCertificate") // validate token var tok, prev []byte @@ -110,11 +113,11 @@ func (ecap *ECAP) CreateCertificatePair(ctx context.Context, in *pb.ECertCreateR if err != nil { errMsg := "Identity lookup error: " + err.Error() - Trace.Println(errMsg) + ecapLogger.Debug(errMsg) return nil, errors.New(errMsg) } if !bytes.Equal(tok, in.Tok.Tok) { - Trace.Printf("id or token mismatch: id=%s\n", id) + ecapLogger.Debugf("id or token mismatch: id=%s", id) return nil, errors.New("Identity or token does not match.") } @@ -134,7 +137,7 @@ func (ecap *ECAP) CreateCertificatePair(ctx context.Context, in *pb.ECertCreateR mutex.Unlock() if err != nil { - Error.Println(err) + ecapLogger.Error(err) return nil, err } @@ -188,7 +191,7 @@ func (ecap *ECAP) CreateCertificatePair(ctx context.Context, in *pb.ECertCreateR spec := NewDefaultCertificateSpecWithCommonName(id, enrollID, skey.(*ecdsa.PublicKey), x509.KeyUsageDigitalSignature, pkix.Extension{Id: ECertSubjectRole, Critical: true, Value: []byte(strconv.Itoa(ecap.eca.readRole(id)))}) sraw, err := ecap.eca.createCertificateFromSpec(spec, ts, nil, true) if err != nil { - Error.Println(err) + ecapLogger.Error(err) return nil, err } @@ -200,7 +203,7 @@ func (ecap *ECAP) CreateCertificatePair(ctx context.Context, in *pb.ECertCreateR mutex.Lock() ecap.eca.db.Exec("DELETE FROM Certificates Where id=?", id) mutex.Unlock() - Error.Println(err) + ecapLogger.Error(err) return nil, err } @@ -211,7 +214,7 @@ func (ecap *ECAP) CreateCertificatePair(ctx context.Context, in *pb.ECertCreateR mutex.Lock() ecap.eca.db.Exec("DELETE FROM Certificates Where id=?", id) mutex.Unlock() - Error.Println(err) + ecapLogger.Error(err) return nil, err } @@ -241,7 +244,7 @@ func (ecap *ECAP) CreateCertificatePair(ctx context.Context, in *pb.ECertCreateR // ReadCertificatePair reads an enrollment certificate pair from the ECA. // func (ecap *ECAP) ReadCertificatePair(ctx context.Context, in *pb.ECertReadReq) (*pb.CertPair, error) { - Trace.Println("gRPC ECAP:ReadCertificate") + ecapLogger.Debug("gRPC ECAP:ReadCertificate") rows, err := ecap.eca.readCertificates(in.Id.Id) defer rows.Close() @@ -267,7 +270,7 @@ func (ecap *ECAP) ReadCertificatePair(ctx context.Context, in *pb.ECertReadReq) // ReadCertificateByHash reads a single enrollment certificate by hash from the ECA. // func (ecap *ECAP) ReadCertificateByHash(ctx context.Context, hash *pb.Hash) (*pb.Cert, error) { - Trace.Println("gRPC ECAP:ReadCertificateByHash") + ecapLogger.Debug("gRPC ECAP:ReadCertificateByHash") raw, err := ecap.eca.readCertificateByHash(hash.Hash) return &pb.Cert{Cert: raw}, err @@ -276,7 +279,7 @@ func (ecap *ECAP) ReadCertificateByHash(ctx context.Context, hash *pb.Hash) (*pb // RevokeCertificatePair revokes a certificate pair from the ECA. Not yet implemented. // func (ecap *ECAP) RevokeCertificatePair(context.Context, *pb.ECertRevokeReq) (*pb.CAStatus, error) { - Trace.Println("gRPC ECAP:RevokeCertificate") + ecapLogger.Debug("gRPC ECAP:RevokeCertificate") return nil, errors.New("ECAP:RevokeCertificate method not (yet) implemented") } diff --git a/membersrvc/ca/membersrvc_test.go b/membersrvc/ca/membersrvc_test.go index d9906247fd4..6a0ec0a756f 100644 --- a/membersrvc/ca/membersrvc_test.go +++ b/membersrvc/ca/membersrvc_test.go @@ -17,7 +17,6 @@ limitations under the License. package ca import ( - "io/ioutil" "net" "os" "testing" @@ -69,7 +68,6 @@ func setupTestConfig() { } func initPKI() { - LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout) CacheConfiguration() // Cache configuration aca = NewACA() eca = NewECA() diff --git a/membersrvc/ca/tca.go b/membersrvc/ca/tca.go index 9eeb823124b..4c375e2da11 100644 --- a/membersrvc/ca/tca.go +++ b/membersrvc/ca/tca.go @@ -27,10 +27,14 @@ import ( "io/ioutil" "github.com/hyperledger/fabric/core/crypto/primitives" + "github.com/hyperledger/fabric/flogging" pb "github.com/hyperledger/fabric/membersrvc/protos" + "github.com/op/go-logging" "google.golang.org/grpc" ) +var tcaLogger = logging.MustGetLogger("tca") + var ( // TCertEncTCertIndex is the ASN1 object identifier of the TCert index. TCertEncTCertIndex = asn1.ObjectIdentifier{1, 2, 3, 4, 5, 6, 7} @@ -84,20 +88,21 @@ func initializeTCATables(db *sql.DB) error { // NewTCA sets up a new TCA. func NewTCA(eca *ECA) *TCA { tca := &TCA{NewCA("tca", initializeTCATables), eca, nil, nil, nil, nil} + flogging.LoggingInit("tca") err := tca.readHmacKey() if err != nil { - Panic.Panicln(err) + tcaLogger.Panic(err) } err = tca.readRootPreKey() if err != nil { - Panic.Panicln(err) + tcaLogger.Panic(err) } err = tca.initializePreKeyTree() if err != nil { - Panic.Panicln(err) + tcaLogger.Panic(err) } return tca } @@ -113,7 +118,7 @@ func (tca *TCA) readHmacKey() error { err = ioutil.WriteFile(tca.path+"/tca.hmac", []byte(cooked), 0644) if err != nil { - Panic.Panicln(err) + tcaLogger.Panic(err) } } else { cooked = string(raw) @@ -134,7 +139,7 @@ func (tca *TCA) readRootPreKey() error { err = ioutil.WriteFile(tca.path+"/root_pk.hmac", []byte(cooked), 0644) if err != nil { - Panic.Panicln(err) + tcaLogger.Panic(err) } } else { cooked = string(raw) @@ -173,7 +178,7 @@ func (tca *TCA) initializePreKeyGroup(group *AffiliationGroup) error { } func (tca *TCA) initializePreKeyTree() error { - Trace.Println("Initializing PreKeys.") + tcaLogger.Debug("Initializing PreKeys.") groups, err := tca.eca.readAffiliationGroups() if err != nil { return err @@ -186,7 +191,7 @@ func (tca *TCA) initializePreKeyTree() error { return err } } - Trace.Println("Initializing PK group ", group.name) + tcaLogger.Debug("Initializing PK group ", group.name) tca.preKeys[group.name] = group.preKey } @@ -207,36 +212,36 @@ func (tca *TCA) getPreKFrom(enrollmentCertificate *x509.Certificate) ([]byte, er // Start starts the TCA. func (tca *TCA) Start(srv *grpc.Server) { - Info.Println("Staring TCA services...") + tcaLogger.Info("Staring TCA services...") tca.startTCAP(srv) tca.startTCAA(srv) tca.gRPCServer = srv - Info.Println("TCA started.") + tcaLogger.Info("TCA started.") } // Stop stops the TCA services. func (tca *TCA) Stop() error { - Info.Println("Stopping the TCA services...") + tcaLogger.Info("Stopping the TCA services...") if tca.gRPCServer != nil { tca.gRPCServer.Stop() } err := tca.CA.Stop() if err != nil { - Error.Println("Error stopping TCA services", err) + tcaLogger.Errorf("Error stopping TCA services: %s", err) } else { - Info.Println("TCA services stopped") + tcaLogger.Info("TCA services stopped") } return err } func (tca *TCA) startTCAP(srv *grpc.Server) { pb.RegisterTCAPServer(srv, &TCAP{tca}) - Info.Println("TCA PUBLIC gRPC API server started") + tcaLogger.Info("TCA PUBLIC gRPC API server started") } func (tca *TCA) startTCAA(srv *grpc.Server) { pb.RegisterTCAAServer(srv, &TCAA{tca}) - Info.Println("TCA ADMIN gRPC API server started") + tcaLogger.Info("TCA ADMIN gRPC API server started") } func (tca *TCA) getCertificateSets(enrollmentID string) ([]*TCertSet, error) { @@ -278,7 +283,7 @@ func (tca *TCA) persistCertificateSet(enrollmentID string, timestamp int64, nonc var err error if _, err = tca.db.Exec("INSERT INTO TCertificateSets (enrollmentID, timestamp, nonce, kdfkey) VALUES (?, ?, ?, ?)", enrollmentID, timestamp, nonce, kdfKey); err != nil { - Error.Println(err) + tcaLogger.Error(err) } return err } diff --git a/membersrvc/ca/tca_test.go b/membersrvc/ca/tca_test.go index bf07574a202..a0b38e1941d 100644 --- a/membersrvc/ca/tca_test.go +++ b/membersrvc/ca/tca_test.go @@ -23,7 +23,6 @@ import ( "fmt" "google/protobuf" "io/ioutil" - "os" "testing" "time" @@ -68,7 +67,7 @@ func TestCreateCertificateSet(t *testing.T) { t.Fatal(err) } - const EXPECTED_TCERT_SUBJECT_COMMON_NAME_VALUE string = "Transaction Certificate" + const expectedTcertSubjectCommonNameValue string = "Transaction Certificate" ncerts := 1 for nattributes := -1; nattributes < 1; nattributes++ { certificateSetRequest, err := buildCertificateSetRequest(enrollmentID, priv, ncerts, nattributes) @@ -112,8 +111,8 @@ func TestCreateCertificateSet(t *testing.T) { } t.Logf("Examining TCert[%d]'s Subject: %v", pos, tcert.Subject) - if tcert.Subject.CommonName != EXPECTED_TCERT_SUBJECT_COMMON_NAME_VALUE { - t.Fatalf("The TCert's Subject.CommonName is '%s' which is different than '%s'", tcert.Subject.CommonName, EXPECTED_TCERT_SUBJECT_COMMON_NAME_VALUE) + if tcert.Subject.CommonName != expectedTcertSubjectCommonNameValue { + t.Fatalf("The TCert's Subject.CommonName is '%s' which is different than '%s'", tcert.Subject.CommonName, expectedTcertSubjectCommonNameValue) } t.Logf("Successfully verified that TCert[%d].Subject.CommonName == '%s'", pos, tcert.Subject.CommonName) } @@ -155,8 +154,6 @@ func initTCA() (*TCA, error) { return nil, fmt.Errorf("Failed initializing the crypto layer [%v]", err) } - //initialize logging to avoid panics in the current code - LogInit(os.Stdout, os.Stdout, os.Stdout, os.Stderr, os.Stdout) CacheConfiguration() // Cache configuration eca := NewECA() if eca == nil { diff --git a/membersrvc/ca/tcaa.go b/membersrvc/ca/tcaa.go index 49b53e4744b..b1e80b12acf 100644 --- a/membersrvc/ca/tcaa.go +++ b/membersrvc/ca/tcaa.go @@ -20,9 +20,12 @@ import ( "errors" pb "github.com/hyperledger/fabric/membersrvc/protos" + "github.com/op/go-logging" "golang.org/x/net/context" ) +var tcaaLogger = logging.MustGetLogger("tcaa") + // TCAA serves the administrator GRPC interface of the TCA. type TCAA struct { tca *TCA @@ -30,21 +33,21 @@ type TCAA struct { // RevokeCertificate revokes a certificate from the TCA. Not yet implemented. func (tcaa *TCAA) RevokeCertificate(context.Context, *pb.TCertRevokeReq) (*pb.CAStatus, error) { - Trace.Println("grpc TCAA:RevokeCertificate") + tcaaLogger.Debug("grpc TCAA:RevokeCertificate") return nil, errors.New("not yet implemented") } // RevokeCertificateSet revokes a certificate set from the TCA. Not yet implemented. func (tcaa *TCAA) RevokeCertificateSet(context.Context, *pb.TCertRevokeSetReq) (*pb.CAStatus, error) { - Trace.Println("grpc TCAA:RevokeCertificateSet") + tcaaLogger.Debug("grpc TCAA:RevokeCertificateSet") return nil, errors.New("not yet implemented") } // PublishCRL requests the creation of a certificate revocation list from the TCA. Not yet implemented. func (tcaa *TCAA) PublishCRL(context.Context, *pb.TCertCRLReq) (*pb.CAStatus, error) { - Trace.Println("grpc TCAA:CreateCRL") + tcaaLogger.Debug("grpc TCAA:CreateCRL") return nil, errors.New("not yet implemented") } diff --git a/membersrvc/ca/tcap.go b/membersrvc/ca/tcap.go index c47045ce393..840d2b7cecb 100644 --- a/membersrvc/ca/tcap.go +++ b/membersrvc/ca/tcap.go @@ -35,12 +35,15 @@ import ( "github.com/hyperledger/fabric/core/crypto/primitives" "github.com/hyperledger/fabric/core/util" pb "github.com/hyperledger/fabric/membersrvc/protos" + "github.com/op/go-logging" "github.com/spf13/viper" "golang.org/x/net/context" "google/protobuf" ) +var tcapLogger = logging.MustGetLogger("tcap") + // TCAP serves the public GRPC interface of the TCA. type TCAP struct { tca *TCA @@ -48,7 +51,7 @@ type TCAP struct { // ReadCACertificate reads the certificate of the TCA. func (tcap *TCAP) ReadCACertificate(ctx context.Context, in *pb.Empty) (*pb.Cert, error) { - Trace.Println("grpc TCAP:ReadCACertificate") + tcapLogger.Debugf("grpc TCAP:ReadCACertificate") return &pb.Cert{Cert: tcap.tca.raw}, nil } @@ -139,7 +142,7 @@ func (tcap *TCAP) requestAttributes(id string, ecert []byte, attrs []*pb.TCertAt } if resp.Status >= pb.ACAAttrResp_FAILURE_MINVAL && resp.Status <= pb.ACAAttrResp_FAILURE_MAXVAL { - return nil, errors.New(fmt.Sprint("Error fetching attributes = ", resp.Status)) + return nil, fmt.Errorf("Error fetching attributes = %s", resp.Status) } return tcap.selectValidAttributes(resp.Cert.Cert) @@ -147,7 +150,7 @@ func (tcap *TCAP) requestAttributes(id string, ecert []byte, attrs []*pb.TCertAt // CreateCertificateSet requests the creation of a new transaction certificate set by the TCA. func (tcap *TCAP) CreateCertificateSet(ctx context.Context, in *pb.TCertCreateSetReq) (*pb.TCertCreateSetResp, error) { - Trace.Println("grpc TCAP:CreateCertificateSet") + tcapLogger.Debugf("grpc TCAP:CreateCertificateSet") id := in.Id.Id raw, err := tcap.tca.eca.readCertificateByKeyUsage(id, x509.KeyUsageDigitalSignature) @@ -163,7 +166,7 @@ func (tcap *TCAP) createCertificateSet(ctx context.Context, raw []byte, in *pb.T var err error var id = in.Id.Id var timestamp = in.Ts.Seconds - const TCERT_SUBJECT_COMMON_NAME_VALUE string = "Transaction Certificate" + const tcertSubjectCommonNameValue string = "Transaction Certificate" if in.Attributes != nil && viper.GetBool("aca.enabled") { attrs, err = tcap.requestAttributes(id, raw, in.Attributes) @@ -249,9 +252,9 @@ func (tcap *TCAP) createCertificateSet(ctx context.Context, raw []byte, in *pb.T return nil, err } - spec := NewDefaultPeriodCertificateSpecWithCommonName(id, TCERT_SUBJECT_COMMON_NAME_VALUE, tcertid, &txPub, x509.KeyUsageDigitalSignature, extensions...) + spec := NewDefaultPeriodCertificateSpecWithCommonName(id, tcertSubjectCommonNameValue, tcertid, &txPub, x509.KeyUsageDigitalSignature, extensions...) if raw, err = tcap.tca.createCertificateFromSpec(spec, timestamp, kdfKey, false); err != nil { - Error.Println(err) + tcapLogger.Error(err) return nil, err } @@ -343,14 +346,14 @@ func (tcap *TCAP) generateExtensions(tcertid *big.Int, tidx []byte, enrollmentCe // RevokeCertificate revokes a certificate from the TCA. Not yet implemented. func (tcap *TCAP) RevokeCertificate(context.Context, *pb.TCertRevokeReq) (*pb.CAStatus, error) { - Trace.Println("grpc TCAP:RevokeCertificate") + tcapLogger.Debugf("grpc TCAP:RevokeCertificate") return nil, errors.New("not yet implemented") } // RevokeCertificateSet revokes a certificate set from the TCA. Not yet implemented. func (tcap *TCAP) RevokeCertificateSet(context.Context, *pb.TCertRevokeSetReq) (*pb.CAStatus, error) { - Trace.Println("grpc TCAP:RevokeCertificateSet") + tcapLogger.Debugf("grpc TCAP:RevokeCertificateSet") return nil, errors.New("not yet implemented") } diff --git a/membersrvc/ca/tlsca.go b/membersrvc/ca/tlsca.go index dd545181861..9106d9ac1b5 100644 --- a/membersrvc/ca/tlsca.go +++ b/membersrvc/ca/tlsca.go @@ -25,11 +25,15 @@ import ( "github.com/golang/protobuf/proto" "github.com/hyperledger/fabric/core/crypto/primitives" + "github.com/hyperledger/fabric/flogging" pb "github.com/hyperledger/fabric/membersrvc/protos" + "github.com/op/go-logging" "golang.org/x/net/context" "google.golang.org/grpc" ) +var tlscaLogger = logging.MustGetLogger("tlsca") + // TLSCA is the tls certificate authority. // type TLSCA struct { @@ -58,6 +62,7 @@ func initializeTLSCATables(db *sql.DB) error { // func NewTLSCA(eca *ECA) *TLSCA { tlsca := &TLSCA{NewCA("tlsca", initializeTLSCATables), eca, nil} + flogging.LoggingInit("tlsca") return tlsca } @@ -68,7 +73,7 @@ func (tlsca *TLSCA) Start(srv *grpc.Server) { tlsca.startTLSCAP(srv) tlsca.startTLSCAA(srv) - Info.Println("TLSCA started.") + tlscaLogger.Info("TLSCA started.") } func (tlsca *TLSCA) startTLSCAP(srv *grpc.Server) { @@ -81,15 +86,15 @@ func (tlsca *TLSCA) startTLSCAA(srv *grpc.Server) { // Stop stops the TCA services. func (tlsca *TLSCA) Stop() error { - Info.Println("Stopping the TLSCA services...") + tlscaLogger.Info("Stopping the TLSCA services...") if tlsca.gRPCServer != nil { tlsca.gRPCServer.Stop() } err := tlsca.CA.Stop() if err != nil { - Error.Println("Error stopping the TLSCA services ", err) + tlscaLogger.Errorf("Error stopping the TLSCA services: %s", err) } else { - Info.Println("TLSCA services stopped") + tlscaLogger.Info("TLSCA services stopped") } return err } @@ -97,7 +102,7 @@ func (tlsca *TLSCA) Stop() error { // ReadCACertificate reads the certificate of the TLSCA. // func (tlscap *TLSCAP) ReadCACertificate(ctx context.Context, in *pb.Empty) (*pb.Cert, error) { - Trace.Println("grpc TLSCAP:ReadCACertificate") + tlscaLogger.Debug("grpc TLSCAP:ReadCACertificate") return &pb.Cert{Cert: tlscap.tlsca.raw}, nil } @@ -105,7 +110,7 @@ func (tlscap *TLSCAP) ReadCACertificate(ctx context.Context, in *pb.Empty) (*pb. // CreateCertificate requests the creation of a new enrollment certificate by the TLSCA. // func (tlscap *TLSCAP) CreateCertificate(ctx context.Context, in *pb.TLSCertCreateReq) (*pb.TLSCertCreateResp, error) { - Trace.Println("grpc TLSCAP:CreateCertificate") + tlscaLogger.Debug("grpc TLSCAP:CreateCertificate") id := in.Id.Id @@ -133,7 +138,7 @@ func (tlscap *TLSCAP) CreateCertificate(ctx context.Context, in *pb.TLSCertCreat } if raw, err = tlscap.tlsca.createCertificate(id, pub.(*ecdsa.PublicKey), x509.KeyUsageDigitalSignature, in.Ts.Seconds, nil); err != nil { - Error.Println(err) + tlscaLogger.Error(err) return nil, err } @@ -143,7 +148,7 @@ func (tlscap *TLSCAP) CreateCertificate(ctx context.Context, in *pb.TLSCertCreat // ReadCertificate reads an enrollment certificate from the TLSCA. // func (tlscap *TLSCAP) ReadCertificate(ctx context.Context, in *pb.TLSCertReadReq) (*pb.Cert, error) { - Trace.Println("grpc TLSCAP:ReadCertificate") + tlscaLogger.Debug("grpc TLSCAP:ReadCertificate") raw, err := tlscap.tlsca.readCertificateByKeyUsage(in.Id.Id, x509.KeyUsageKeyAgreement) if err != nil { @@ -156,7 +161,7 @@ func (tlscap *TLSCAP) ReadCertificate(ctx context.Context, in *pb.TLSCertReadReq // RevokeCertificate revokes a certificate from the TLSCA. Not yet implemented. // func (tlscap *TLSCAP) RevokeCertificate(context.Context, *pb.TLSCertRevokeReq) (*pb.CAStatus, error) { - Trace.Println("grpc TLSCAP:RevokeCertificate") + tlscaLogger.Debug("grpc TLSCAP:RevokeCertificate") return nil, errors.New("not yet implemented") } @@ -164,7 +169,7 @@ func (tlscap *TLSCAP) RevokeCertificate(context.Context, *pb.TLSCertRevokeReq) ( // RevokeCertificate revokes a certificate from the TLSCA. Not yet implemented. // func (tlscaa *TLSCAA) RevokeCertificate(context.Context, *pb.TLSCertRevokeReq) (*pb.CAStatus, error) { - Trace.Println("grpc TLSCAA:RevokeCertificate") + tlscaLogger.Debug("grpc TLSCAA:RevokeCertificate") return nil, errors.New("not yet implemented") } diff --git a/membersrvc/ca/tlsca_test.go b/membersrvc/ca/tlsca_test.go index 66757445f8f..de890a9b704 100644 --- a/membersrvc/ca/tlsca_test.go +++ b/membersrvc/ca/tlsca_test.go @@ -19,7 +19,6 @@ package ca import ( "io/ioutil" "net" - "os" "testing" "time" @@ -63,7 +62,6 @@ func TestTLS(t *testing.T) { } func startTLSCA(t *testing.T) { - LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout) CacheConfiguration() // Cache configuration ecaS = NewECA() tlscaS = NewTLSCA(ecaS) diff --git a/membersrvc/ca/util.go b/membersrvc/ca/util.go index 0ad429f5101..54c297132da 100644 --- a/membersrvc/ca/util.go +++ b/membersrvc/ca/util.go @@ -18,8 +18,6 @@ package ca import ( "errors" - "io" - "log" mrand "math/rand" "time" @@ -33,29 +31,6 @@ const ( letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits ) -var ( - // Trace is a trace logger. - Trace *log.Logger - // Info is an info logger. - Info *log.Logger - // Warning is a warning logger. - Warning *log.Logger - // Error is an error logger. - Error *log.Logger - // Panic is a panic logger. - Panic *log.Logger -) - -// LogInit initializes the various loggers. -// -func LogInit(trace, info, warning, error, panic io.Writer) { - Trace = log.New(trace, "TRACE: ", log.LstdFlags|log.Lshortfile) - Info = log.New(info, "INFO: ", log.LstdFlags) - Warning = log.New(warning, "WARNING: ", log.LstdFlags|log.Lshortfile) - Error = log.New(error, "ERROR: ", log.LstdFlags|log.Lshortfile) - Panic = log.New(panic, "PANIC: ", log.LstdFlags|log.Lshortfile) -} - var rnd = mrand.NewSource(time.Now().UnixNano()) func randomString(n int) string { diff --git a/membersrvc/membersrvc.yaml b/membersrvc/membersrvc.yaml index af770d772da..31456c1f34b 100644 --- a/membersrvc/membersrvc.yaml +++ b/membersrvc/membersrvc.yaml @@ -34,11 +34,20 @@ security: # Enabling/disabling different logging levels of the CA. # logging: - trace: 0 - info: 1 - warning: 1 - error: 1 - panic: 1 + +# Please see fabric/docs/Setup/logging-control.md for more +# options. + server: warning + ca: warning + eca: warning + ecap: warning + ecaa: warning + aca: warning + acap: warning + tca: warning + tcap: warning + tcaa: warning + tlsca: warning # Default users to be registered with the CA on first launch. The role is a binary OR # of the different roles a user can have: diff --git a/membersrvc/server.go b/membersrvc/server.go index e59511b2c69..f9169cccfe7 100644 --- a/membersrvc/server.go +++ b/membersrvc/server.go @@ -17,9 +17,6 @@ limitations under the License. package main import ( - "fmt" - "io" - "io/ioutil" "net" "os" "path/filepath" @@ -28,7 +25,9 @@ import ( "strings" "github.com/hyperledger/fabric/core/crypto" + "github.com/hyperledger/fabric/flogging" "github.com/hyperledger/fabric/membersrvc/ca" + "github.com/op/go-logging" "github.com/spf13/viper" "google.golang.org/grpc" "google.golang.org/grpc/credentials" @@ -36,7 +35,10 @@ import ( const envPrefix = "MEMBERSRVC_CA" +var logger = logging.MustGetLogger("server") + func main() { + viper.SetEnvPrefix(envPrefix) viper.AutomaticEnv() replacer := strings.NewReplacer(".", "_") @@ -52,46 +54,20 @@ func main() { } err := viper.ReadInConfig() if err != nil { - panic(fmt.Errorf("Fatal error when reading %s config file: %s\n", "membersrvc", err)) + logger.Panicf("Fatal error when reading %s config file: %s", "membersrvc", err) } - var iotrace, ioinfo, iowarning, ioerror, iopanic io.Writer - if viper.GetInt("logging.trace") == 1 { - iotrace = os.Stdout - } else { - iotrace = ioutil.Discard - } - if viper.GetInt("logging.info") == 1 { - ioinfo = os.Stdout - } else { - ioinfo = ioutil.Discard - } - if viper.GetInt("logging.warning") == 1 { - iowarning = os.Stdout - } else { - iowarning = ioutil.Discard - } - if viper.GetInt("logging.error") == 1 { - ioerror = os.Stderr - } else { - ioerror = ioutil.Discard - } - if viper.GetInt("logging.panic") == 1 { - iopanic = os.Stdout - } else { - iopanic = ioutil.Discard - } + flogging.LoggingInit("server") // Init the crypto layer if err := crypto.Init(); err != nil { - panic(fmt.Errorf("Failed initializing the crypto layer [%s]", err)) + logger.Panicf("Failed initializing the crypto layer [%s]", err) } - ca.LogInit(iotrace, ioinfo, iowarning, ioerror, iopanic) // cache configure ca.CacheConfiguration() - ca.Info.Println("CA Server (" + viper.GetString("server.version") + ")") + logger.Infof("CA Server (" + viper.GetString("server.version") + ")") aca := ca.NewACA() defer aca.Stop() @@ -111,7 +87,7 @@ func main() { if viper.GetString("server.tls.cert.file") != "" { creds, err := credentials.NewServerTLSFromFile(viper.GetString("server.tls.cert.file"), viper.GetString("server.tls.key.file")) if err != nil { - panic(err) + logger.Panic(err) } opts = []grpc.ServerOption{grpc.Creds(creds)} } @@ -123,7 +99,7 @@ func main() { tlsca.Start(srv) if sock, err := net.Listen("tcp", viper.GetString("server.port")); err != nil { - ca.Error.Println("Fail to start CA Server: ", err) + logger.Errorf("Fail to start CA Server: %s", err) os.Exit(1) } else { srv.Serve(sock) diff --git a/peer/main.go b/peer/main.go index 5adcb194933..ceec648ea11 100644 --- a/peer/main.go +++ b/peer/main.go @@ -57,6 +57,7 @@ import ( "github.com/hyperledger/fabric/core/rest" "github.com/hyperledger/fabric/core/system_chaincode" "github.com/hyperledger/fabric/events/producer" + "github.com/hyperledger/fabric/flogging" pb "github.com/hyperledger/fabric/protos" ) @@ -78,7 +79,7 @@ var mainCmd = &cobra.Command{ return core.CacheConfiguration() }, PreRun: func(cmd *cobra.Command, args []string) { - core.LoggingInit("peer") + flogging.LoggingInit("peer") }, Run: func(cmd *cobra.Command, args []string) { if versionFlag { @@ -97,7 +98,7 @@ var versionCmd = &cobra.Command{ Short: "Print fabric peer version.", Long: `Print current version of fabric peer server.`, PreRun: func(cmd *cobra.Command, args []string) { - core.LoggingInit("version") + flogging.LoggingInit("version") }, Run: func(cmd *cobra.Command, args []string) { showVersion() @@ -109,7 +110,7 @@ var nodeCmd = &cobra.Command{ Short: fmt.Sprintf("%s specific commands.", nodeFuncName), Long: fmt.Sprintf("%s specific commands.", nodeFuncName), PersistentPreRun: func(cmd *cobra.Command, args []string) { - core.LoggingInit(nodeFuncName) + flogging.LoggingInit(nodeFuncName) }, } @@ -149,7 +150,7 @@ var networkCmd = &cobra.Command{ Short: fmt.Sprintf("%s specific commands.", networkFuncName), Long: fmt.Sprintf("%s specific commands.", networkFuncName), PersistentPreRun: func(cmd *cobra.Command, args []string) { - core.LoggingInit(networkFuncName) + flogging.LoggingInit(networkFuncName) }, } @@ -167,7 +168,7 @@ var networkLoginCmd = &cobra.Command{ // Short: "Accesses VM specific functionality.", // Long: `Accesses VM specific functionality.`, // PersistentPreRun: func(cmd *cobra.Command, args []string) { -// core.LoggingInit("vm") +// flogging.LoggingInit("vm") // }, // } // @@ -217,7 +218,7 @@ var chaincodeCmd = &cobra.Command{ Short: fmt.Sprintf("%s specific commands.", chainFuncName), Long: fmt.Sprintf("%s specific commands.", chainFuncName), PersistentPreRun: func(cmd *cobra.Command, args []string) { - core.LoggingInit(chainFuncName) + flogging.LoggingInit(chainFuncName) }, }