1313import java .io .File ;
1414import java .io .IOException ;
1515import java .io .InputStream ;
16- import java .io .PrintWriter ;
17- import java .io .StringWriter ;
1816import java .nio .file .Files ;
1917import java .nio .file .Paths ;
2018import java .security .Security ;
2119import java .util .Base64 ;
22- import java .util .Collections ;
23- import java .util .Date ;
24- import java .util .List ;
2520import java .util .Properties ;
26- import java .util .logging .Formatter ;
2721import java .util .logging .Level ;
28- import java .util .logging .LogManager ;
2922import java .util .logging .LogRecord ;
3023import java .util .logging .Logger ;
3124import java .util .logging .SimpleFormatter ;
3225
26+ import com .google .protobuf .InvalidProtocolBufferException ;
27+ import com .google .protobuf .util .JsonFormat ;
28+
3329import org .apache .commons .cli .CommandLine ;
3430import org .apache .commons .cli .DefaultParser ;
3531import org .apache .commons .cli .Options ;
4238import org .hyperledger .fabric .shim .impl .ChaincodeSupportClient ;
4339import org .hyperledger .fabric .shim .impl .InvocationTaskManager ;
4440
45- import com .google .protobuf .InvalidProtocolBufferException ;
46- import com .google .protobuf .util .JsonFormat ;
47-
4841import io .grpc .ManagedChannelBuilder ;
49- import io .grpc .netty .GrpcSslContexts ;
50- import io .grpc .netty .NegotiationType ;
51- import io .grpc .netty .NettyChannelBuilder ;
52- import io .netty .handler .ssl .SslContext ;
42+ import io .grpc .netty .shaded . io . grpc . netty . GrpcSslContexts ;
43+ import io .grpc .netty .shaded . io . grpc . netty . NegotiationType ;
44+ import io .grpc .netty .shaded . io . grpc . netty . NettyChannelBuilder ;
45+ import io .grpc . netty . shaded . io . netty .handler .ssl .SslContext ;
5346
5447public abstract class ChaincodeBase implements Chaincode {
5548
@@ -147,6 +140,7 @@ protected final void connectToPeer() throws IOException {
147140 }
148141
149142 protected final void initializeLogging () {
143+ // the VM wide formatting string.
150144 System .setProperty ("java.util.logging.SimpleFormatter.format" ,
151145 "%1$tH:%1$tM:%1$tS:%1$tL %4$-7.7s %2$-80.80s %5$s%6$s%n" );
152146 final Logger rootLogger = Logger .getLogger ("" );
@@ -157,53 +151,12 @@ protected final void initializeLogging() {
157151
158152 @ Override
159153 public synchronized String format (final LogRecord record ) {
160- return super .format (record ).replaceFirst (".*SEVERE\\ s*\\ S*\\ s*\\ S*" , "\u001B [1;31m$0\u001B [0m" )
161- .replaceFirst (".*WARNING\\ s*\\ S*\\ s*\\ S*" , "\u001B [1;33m$0\u001B [0m" )
162- .replaceFirst (".*CONFIG\\ s*\\ S*\\ s*\\ S*" , "\u001B [35m$0\u001B [0m" )
163- .replaceFirst (".*FINE\\ s*\\ S*\\ s*\\ S*" , "\u001B [36m$0\u001B [0m" )
164- .replaceFirst (".*FINER\\ s*\\ S*\\ s*\\ S*" , "\u001B [36m$0\u001B [0m" )
165- .replaceFirst (".*FINEST\\ s*\\ S*\\ s*\\ S*" , "\u001B [36m$0\u001B [0m" );
154+ return Thread .currentThread () + " " + super .format (record );
166155 }
167156
168157 });
169158 }
170159
171- final LogManager logManager = LogManager .getLogManager ();
172-
173- final Formatter f = new Formatter () {
174-
175- private final Date dat = new Date ();
176- private final String format = "%1$tH:%1$tM:%1$tS:%1$tL %4$-7.7s %2$-80.80s %5$s%6$s%n" ;
177-
178- @ Override
179- public String format (final LogRecord record ) {
180- dat .setTime (record .getMillis ());
181- String source ;
182- if (record .getSourceClassName () != null ) {
183- source = record .getSourceClassName ();
184- if (record .getSourceMethodName () != null ) {
185- source += " " + record .getSourceMethodName ();
186- }
187- } else {
188- source = record .getLoggerName ();
189- }
190- final String message = formatMessage (record );
191- String throwable = "" ;
192- if (record .getThrown () != null ) {
193- final StringWriter sw = new StringWriter ();
194- final PrintWriter pw = new PrintWriter (sw );
195- pw .println ();
196- record .getThrown ().printStackTrace (pw );
197- pw .close ();
198- throwable = sw .toString ();
199- }
200- return String .format (format , dat , source , record .getLoggerName (), record .getLevel (), message ,
201- throwable );
202-
203- }
204-
205- };
206-
207160 rootLogger .info ("Updated all handlers the format" );
208161 // set logging level of chaincode logger
209162 final Level chaincodeLogLevel = mapLevel (System .getenv (CORE_CHAINCODE_LOGGING_LEVEL ));
@@ -223,31 +176,26 @@ public String format(final LogRecord record) {
223176 Logger .getLogger (ChaincodeBase .class .getPackage ().getName ()).setLevel (shimLogLevel );
224177 Logger .getLogger (ContractRouter .class .getPackage ().getName ()).setLevel (chaincodeLogLevel );
225178
226- final List <?> loggers = Collections .list (LogManager .getLogManager ().getLoggerNames ());
227- loggers .forEach (x -> {
228- final Logger l = LogManager .getLogManager ().getLogger ((String ) x );
229- // err what is the code supposed to do?
230- });
231-
232179 }
233180
234181 private Level mapLevel (final String level ) {
235182
236183 if (level != null ) {
237184 switch (level .toUpperCase ().trim ()) {
238- case "CRITICAL" :
239- case "ERROR" :
240- return Level .SEVERE ;
241- case "WARNING" :
242- return Level .WARNING ;
243- case "INFO" :
244- return Level .INFO ;
245- case "NOTICE" :
246- return Level .CONFIG ;
247- case "DEBUG" :
248- return Level .FINEST ;
249- default :
250- break ;
185+ case "CRITICAL" :
186+ case "ERROR" :
187+ return Level .SEVERE ;
188+ case "WARNING" :
189+ case "WARN" :
190+ return Level .WARNING ;
191+ case "INFO" :
192+ return Level .INFO ;
193+ case "NOTICE" :
194+ return Level .CONFIG ;
195+ case "DEBUG" :
196+ return Level .FINEST ;
197+ default :
198+ break ;
251199 }
252200 }
253201 return Level .INFO ;
0 commit comments