jdk/src/java.base/share/classes/sun/util/logging/PlatformLogger.java
changeset 29117 7956b5dc0eac
parent 27565 729f9700483a
child 29986 97167d851fc4
equal deleted inserted replaced
29116:9918719cfcc0 29117:7956b5dc0eac
     1 /*
     1 /*
     2  * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    30 import java.io.PrintStream;
    30 import java.io.PrintStream;
    31 import java.io.PrintWriter;
    31 import java.io.PrintWriter;
    32 import java.io.StringWriter;
    32 import java.io.StringWriter;
    33 import java.security.AccessController;
    33 import java.security.AccessController;
    34 import java.security.PrivilegedAction;
    34 import java.security.PrivilegedAction;
       
    35 import java.time.Clock;
       
    36 import java.time.Instant;
       
    37 import java.time.ZoneId;
       
    38 import java.time.ZonedDateTime;
    35 import java.util.Arrays;
    39 import java.util.Arrays;
    36 import java.util.Date;
       
    37 import java.util.HashMap;
    40 import java.util.HashMap;
    38 import java.util.Map;
    41 import java.util.Map;
    39 import sun.misc.JavaLangAccess;
    42 import sun.misc.JavaLangAccess;
    40 import sun.misc.SharedSecrets;
    43 import sun.misc.SharedSecrets;
    41 
    44 
   512             }
   515             }
   513         }
   516         }
   514 
   517 
   515         private static final String formatString =
   518         private static final String formatString =
   516             LoggingSupport.getSimpleFormat(false); // don't check logging.properties
   519             LoggingSupport.getSimpleFormat(false); // don't check logging.properties
   517 
   520         private final ZoneId zoneId = ZoneId.systemDefault();
   518         // minimize memory allocation
       
   519         private Date date = new Date();
       
   520         private synchronized String format(Level level, String msg, Throwable thrown) {
   521         private synchronized String format(Level level, String msg, Throwable thrown) {
   521             date.setTime(System.currentTimeMillis());
   522             ZonedDateTime zdt = ZonedDateTime.now(zoneId);
   522             String throwable = "";
   523             String throwable = "";
   523             if (thrown != null) {
   524             if (thrown != null) {
   524                 StringWriter sw = new StringWriter();
   525                 StringWriter sw = new StringWriter();
   525                 PrintWriter pw = new PrintWriter(sw);
   526                 PrintWriter pw = new PrintWriter(sw);
   526                 pw.println();
   527                 pw.println();
   528                 pw.close();
   529                 pw.close();
   529                 throwable = sw.toString();
   530                 throwable = sw.toString();
   530             }
   531             }
   531 
   532 
   532             return String.format(formatString,
   533             return String.format(formatString,
   533                                  date,
   534                                  zdt,
   534                                  getCallerInfo(),
   535                                  getCallerInfo(),
   535                                  name,
   536                                  name,
   536                                  level.name(),
   537                                  level.name(),
   537                                  msg,
   538                                  msg,
   538                                  throwable);
   539                                  throwable);