Skip to content

Commit 0ea65fd

Browse files
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 #897 patch set from #2300 address review comment rebased Change-Id: I1124bf8f771dbf4d34cc836437caa1d5526f4f43 Signed-off-by: Christopher Ferris <[email protected]>
1 parent dc6e24a commit 0ea65fd

22 files changed

+242
-255
lines changed

core/chaincode/exectransaction_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ package chaincode
1818

1919
import (
2020
"fmt"
21-
"io/ioutil"
2221
"net"
2322
"os"
2423
"strconv"
@@ -56,7 +55,6 @@ func initMemSrvc() (net.Listener, error) {
5655
//start clean
5756
finitMemSrvc(nil)
5857

59-
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
6058
ca.CacheConfiguration() // Cache configuration
6159

6260
aca := ca.NewACA()

core/crypto/crypto_test.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222

2323
"bytes"
2424
"fmt"
25-
"io/ioutil"
2625
"net"
2726
"os"
2827
"path/filepath"
@@ -436,7 +435,7 @@ func TestClientGetNextTCerts(t *testing.T) {
436435
var nCerts int = 1
437436
for i := 1; i < 3; i++ {
438437
nCerts *= 10
439-
fmt.Println(fmt.Sprintf("Calling GetNextTCerts(%d)", nCerts))
438+
t.Logf("Calling GetNextTCerts(%d)", nCerts)
440439
rvCerts, err := deployer.GetNextTCerts(nCerts)
441440
if err != nil {
442441
t.Fatalf("Could not receive %d TCerts", nCerts)
@@ -1524,7 +1523,6 @@ func setup() {
15241523
}
15251524

15261525
func initPKI() {
1527-
ca.LogInit(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr, os.Stdout)
15281526
ca.CacheConfiguration() // Need cache the configuration first
15291527
aca = ca.NewACA()
15301528
eca = ca.NewECA()
@@ -1567,21 +1565,18 @@ func initNodes() {
15671565
// Init clients
15681566
err := initClients()
15691567
if err != nil {
1570-
fmt.Printf("Failed initializing clients [%s]\n", err)
15711568
panic(fmt.Errorf("Failed initializing clients [%s].", err))
15721569
}
15731570

15741571
// Init peer
15751572
err = initPeers()
15761573
if err != nil {
1577-
fmt.Printf("Failed initializing peers [%s]\n", err)
15781574
panic(fmt.Errorf("Failed initializing peers [%s].", err))
15791575
}
15801576

15811577
// Init validators
15821578
err = initValidators()
15831579
if err != nil {
1584-
fmt.Printf("Failed initializing validators [%s]\n", err)
15851580
panic(fmt.Errorf("Failed initializing validators [%s].", err))
15861581
}
15871582

core/logging.go flogging/logging.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package core
17+
package flogging
1818

1919
import (
2020
"os"

core/logging_test.go flogging/logging_test.go

+21-20
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,29 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package core
17+
package flogging_test
1818

1919
import (
2020
"testing"
2121

22+
"github.com/hyperledger/fabric/flogging"
2223
"github.com/op/go-logging"
2324
"github.com/spf13/viper"
2425
)
2526

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

29-
LoggingInit("")
30+
flogging.LoggingInit("")
3031

31-
assertDefaultLoggingLevel(t, DefaultLoggingLevel())
32+
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
3233
}
3334

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

38-
LoggingInit("")
39+
flogging.LoggingInit("")
3940

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

47-
LoggingInit("")
48+
flogging.LoggingInit("")
4849

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

56-
LoggingInit("")
57+
flogging.LoggingInit("")
5758

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

66-
LoggingInit("")
67+
flogging.LoggingInit("")
6768

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

76-
LoggingInit("")
77+
flogging.LoggingInit("")
7778

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

86-
LoggingInit("")
87+
flogging.LoggingInit("")
8788

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

96-
LoggingInit("node")
97+
flogging.LoggingInit("node")
9798

9899
assertDefaultLoggingLevel(t, logging.ERROR)
99100
}
100101

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

104-
LoggingInit("unknown command")
105+
flogging.LoggingInit("unknown command")
105106

106-
assertDefaultLoggingLevel(t, DefaultLoggingLevel())
107+
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
107108
}
108109

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

113-
LoggingInit("")
114+
flogging.LoggingInit("")
114115

115-
assertDefaultLoggingLevel(t, DefaultLoggingLevel())
116+
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
116117
}
117118

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

122-
LoggingInit("")
123+
flogging.LoggingInit("")
123124

124-
assertDefaultLoggingLevel(t, DefaultLoggingLevel())
125+
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
125126
}
126127

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

131-
LoggingInit("")
132+
flogging.LoggingInit("")
132133

133-
assertDefaultLoggingLevel(t, DefaultLoggingLevel())
134+
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
134135
}
135136

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

140-
LoggingInit("")
141+
flogging.LoggingInit("")
141142

142-
assertDefaultLoggingLevel(t, DefaultLoggingLevel())
143+
assertDefaultLoggingLevel(t, flogging.DefaultLoggingLevel())
143144
}
144145

145146
func assertDefaultLoggingLevel(t *testing.T, expectedLevel logging.Level) {

membersrvc/ca/aca.go

+13-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package ca
1919
import (
2020
"encoding/asn1"
2121
"errors"
22-
"fmt"
2322
"google/protobuf"
2423
"strings"
2524
"time"
@@ -28,12 +27,16 @@ import (
2827

2928
"database/sql"
3029

30+
"github.com/hyperledger/fabric/flogging"
31+
"github.com/op/go-logging"
3132
"github.com/spf13/viper"
3233
"google.golang.org/grpc"
3334

3435
pb "github.com/hyperledger/fabric/membersrvc/protos"
3536
)
3637

38+
var acaLogger = logging.MustGetLogger("aca")
39+
3740
var (
3841
//ACAAttribute is the base OID to the attributes extensions.
3942
ACAAttribute = asn1.ObjectIdentifier{1, 2, 3, 4, 5, 6, 10}
@@ -220,7 +223,7 @@ func (attrPair *AttributePair) ToACAAttribute() *pb.ACAAttribute {
220223
// NewACA sets up a new ACA.
221224
func NewACA() *ACA {
222225
aca := &ACA{CA: NewCA("aca", initializeACATables)}
223-
226+
flogging.LoggingInit("aca")
224227
return aca
225228
}
226229

@@ -263,12 +266,12 @@ func (aca *ACA) fetchAttributes(id, affiliation string) ([]*AttributePair, error
263266
}
264267
attributes = append(attributes, attrPair)
265268
} else {
266-
Error.Printf("Invalid attribute entry '%v'", vals[0])
269+
acaLogger.Errorf("Invalid attribute entry '%v'", vals[0])
267270
}
268271
}
269272
}
270273

271-
fmt.Printf("%v %v", id, attributes)
274+
acaLogger.Debugf("%v %v", id, attributes)
272275

273276
return attributes, nil
274277
}
@@ -365,28 +368,28 @@ func (aca *ACA) findAttribute(owner *AttributeOwner, attributeName string) (*Att
365368

366369
func (aca *ACA) startACAP(srv *grpc.Server) {
367370
pb.RegisterACAPServer(srv, &ACAP{aca})
368-
Info.Println("ACA PUBLIC gRPC API server started")
371+
acaLogger.Info("ACA PUBLIC gRPC API server started")
369372
}
370373

371374
// Start starts the ACA.
372375
func (aca *ACA) Start(srv *grpc.Server) {
373-
Info.Println("Staring ACA services...")
376+
acaLogger.Info("Staring ACA services...")
374377
aca.startACAP(srv)
375378
aca.gRPCServer = srv
376-
Info.Println("ACA services started")
379+
acaLogger.Info("ACA services started")
377380
}
378381

379382
// Stop stops the ACA
380383
func (aca *ACA) Stop() error {
381-
Info.Println("Stopping the ACA services...")
384+
acaLogger.Info("Stopping the ACA services...")
382385
if aca.gRPCServer != nil {
383386
aca.gRPCServer.Stop()
384387
}
385388
err := aca.CA.Stop()
386389
if err != nil {
387-
Error.Println("Error stopping the ACA services ", err)
390+
acaLogger.Errorf("Error stopping the ACA services: %s ", err)
388391
} else {
389-
Info.Println("ACA services stopped")
392+
acaLogger.Info("ACA services stopped")
390393
}
391394
return err
392395
}

membersrvc/ca/acap.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,15 @@ import (
2626
"crypto/x509/pkix"
2727

2828
"github.com/golang/protobuf/proto"
29+
"github.com/op/go-logging"
2930
"golang.org/x/net/context"
3031

3132
"github.com/hyperledger/fabric/core/crypto/primitives"
3233
pb "github.com/hyperledger/fabric/membersrvc/protos"
3334
)
3435

36+
var acapLogger = logging.MustGetLogger("acap")
37+
3538
// ACAP serves the public GRPC interface of the ACA.
3639
//
3740
type ACAP struct {
@@ -40,7 +43,7 @@ type ACAP struct {
4043

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

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

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

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

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

0 commit comments

Comments
 (0)