@@ -30,6 +30,7 @@ import (
30
30
"github.com/golang/protobuf/proto"
31
31
"github.com/golang/protobuf/ptypes/timestamp"
32
32
"github.com/hyperledger/fabric/bccsp/factory"
33
+ "github.com/hyperledger/fabric/common/flogging"
33
34
"github.com/hyperledger/fabric/core/comm"
34
35
pb "github.com/hyperledger/fabric/protos/peer"
35
36
"github.com/hyperledger/fabric/protos/utils"
@@ -41,6 +42,7 @@ import (
41
42
42
43
// Logger for the shim package.
43
44
var chaincodeLogger = logging .MustGetLogger ("shim" )
45
+ var logOutput = os .Stderr
44
46
45
47
const (
46
48
minUnicodeRuneValue = 0 //U+0000
@@ -70,12 +72,7 @@ var peerAddress string
70
72
func Start (cc Chaincode ) error {
71
73
// If Start() is called, we assume this is a standalone chaincode and set
72
74
// up formatted logging.
73
- format := logging .MustStringFormatter ("%{time:15:04:05.000} [%{module}] %{level:.4s} : %{message}" )
74
- backend := logging .NewLogBackend (os .Stderr , "" , 0 )
75
- backendFormatter := logging .NewBackendFormatter (backend , format )
76
- logging .SetBackend (backendFormatter ).SetLevel (logging .Level (shimLoggingLevel ), "shim" )
77
-
78
- SetChaincodeLoggingLevel ()
75
+ SetupChaincodeLogging ()
79
76
80
77
err := factory .InitFactories (& factory .DefaultOpts )
81
78
if err != nil {
@@ -121,18 +118,23 @@ func IsEnabledForLogLevel(logLevel string) bool {
121
118
return chaincodeLogger .IsEnabledFor (lvl )
122
119
}
123
120
124
- // SetChaincodeLoggingLevel sets the chaincode logging level to the value
125
- // of CORE_LOGGING_CHAINCODE set from core.yaml by chaincode_support.go
126
- func SetChaincodeLoggingLevel () {
121
+ // SetupChaincodeLogging sets the chaincode logging format and the level
122
+ // to the values of CORE_CHAINCODE_LOGFORMAT and CORE_CHAINCODE_LOGLEVEL set
123
+ // from core.yaml by chaincode_support.go
124
+ func SetupChaincodeLogging () {
127
125
viper .SetEnvPrefix ("CORE" )
128
126
viper .AutomaticEnv ()
129
127
replacer := strings .NewReplacer ("." , "_" )
130
128
viper .SetEnvKeyReplacer (replacer )
131
129
132
- chaincodeLogLevelString := viper .GetString ("logging.chaincode" )
130
+ logFormat := viper .GetString ("chaincode.logFormat" )
131
+ flogging .SetLoggingFormat (logFormat , logOutput )
132
+
133
+ chaincodeLogLevelString := viper .GetString ("chaincode.logLevel" )
133
134
if chaincodeLogLevelString == "" {
134
135
shimLogLevelDefault := logging .Level (shimLoggingLevel )
135
136
chaincodeLogger .Infof ("Chaincode log level not provided; defaulting to: %s" , shimLogLevelDefault )
137
+ SetLoggingLevel (shimLoggingLevel )
136
138
} else {
137
139
chaincodeLogLevel , err := LogLevel (chaincodeLogLevelString )
138
140
if err == nil {
@@ -620,7 +622,7 @@ const (
620
622
LogCritical = LoggingLevel (logging .CRITICAL )
621
623
)
622
624
623
- var shimLoggingLevel = LogDebug // Necessary for correct initialization; See Start()
625
+ var shimLoggingLevel = LogInfo // Necessary for correct initialization; See Start()
624
626
625
627
// SetLoggingLevel allows a Go language chaincode to set the logging level of
626
628
// its shim.
0 commit comments