jdk/src/java.logging/share/classes/java/util/logging/SimpleFormatter.java
author dfuchs
Thu, 06 Apr 2017 14:38:15 +0100
changeset 44538 a603c475d649
parent 38884 48a0335cdadc
child 45132 db2f2d72cd4f
permissions -rw-r--r--
8178139: Minor typo in API documentation of java.util.logging.Logger Reviewed-by: lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
36679
0e6911cee995 8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents: 35782
diff changeset
     2
 * Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
package java.util.logging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.*;
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
    30
import java.time.ZoneId;
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
    31
import java.time.ZonedDateTime;
36679
0e6911cee995 8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents: 35782
diff changeset
    32
import jdk.internal.logger.SurrogateLogger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    35
 * Print a brief summary of the {@code LogRecord} in a human readable
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * format.  The summary will typically be 1 or 2 lines.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    38
 * <p>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    39
 * <a name="formatting">
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    40
 * <b>Configuration:</b></a>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    41
 * The {@code SimpleFormatter} is initialized with the
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    42
 * <a href="../Formatter.html#syntax">format string</a>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    43
 * specified in the {@code java.util.logging.SimpleFormatter.format}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    44
 * property to {@linkplain #format format} the log messages.
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    45
 * This property can be defined
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    46
 * in the {@linkplain LogManager#getProperty logging properties}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    47
 * configuration file
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    48
 * or as a system property.  If this property is set in both
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    49
 * the logging properties and system properties,
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    50
 * the format string specified in the system property will be used.
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    51
 * If this property is not defined or the given format string
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    52
 * is {@linkplain java.util.IllegalFormatException illegal},
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    53
 * the default format is implementation-specific.
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    54
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * @since 1.4
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    56
 * @see java.util.Formatter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public class SimpleFormatter extends Formatter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    61
    // format string for printing the log record
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
    62
    static String getLoggingProperty(String name) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
    63
        return LogManager.getLogManager().getProperty(name);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
    64
    }
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
    65
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
    66
    private final String format =
36679
0e6911cee995 8150840: Add an internal system property to control the default level of System.Logger when java.logging is not present.
dfuchs
parents: 35782
diff changeset
    67
        SurrogateLogger.getSimpleFormat(SimpleFormatter::getLoggingProperty);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * Format the given LogRecord.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <p>
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    72
     * The formatting can be customized by specifying the
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    73
     * <a href="../Formatter.html#syntax">format string</a>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    74
     * in the <a href="#formatting">
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    75
     * {@code java.util.logging.SimpleFormatter.format}</a> property.
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    76
     * The given {@code LogRecord} will be formatted as if by calling:
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    77
     * <pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    78
     *    {@link String#format String.format}(format, date, source, logger, level, message, thrown);
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    79
     * </pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    80
     * where the arguments are:<br>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    81
     * <ol>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    82
     * <li>{@code format} - the {@link java.util.Formatter
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    83
     *     java.util.Formatter} format string specified in the
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    84
     *     {@code java.util.logging.SimpleFormatter.format} property
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    85
     *     or the default format.</li>
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
    86
     * <li>{@code date} - a {@link ZonedDateTime} object representing
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
    87
     *     {@linkplain LogRecord#getInstant() event time} of the log record
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
    88
     *      in the {@link ZoneId#systemDefault()} system time zone.</li>
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    89
     * <li>{@code source} - a string representing the caller, if available;
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    90
     *     otherwise, the logger's name.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    91
     * <li>{@code logger} - the logger's name.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    92
     * <li>{@code level} - the {@linkplain Level#getLocalizedName
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    93
     *     log level}.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    94
     * <li>{@code message} - the formatted log message
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    95
     *     returned from the {@link Formatter#formatMessage(LogRecord)}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    96
     *     method.  It uses {@link java.text.MessageFormat java.text}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    97
     *     formatting and does not use the {@code java.util.Formatter
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    98
     *     format} argument.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    99
     * <li>{@code thrown} - a string representing
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   100
     *     the {@linkplain LogRecord#getThrown throwable}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   101
     *     associated with the log record and its backtrace
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   102
     *     beginning with a newline character, if any;
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   103
     *     otherwise, an empty string.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   104
     * </ol>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   105
     *
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   106
     * <p>Some example formats:<br>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   107
     * <ul>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   108
     * <li> {@code java.util.logging.SimpleFormatter.format="%4$s: %5$s [%1$tc]%n"}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   109
     *     <p>This prints 1 line with the log level ({@code 4$}),
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   110
     *     the log message ({@code 5$}) and the timestamp ({@code 1$}) in
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   111
     *     a square bracket.
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   112
     *     <pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   113
     *     WARNING: warning message [Tue Mar 22 13:11:31 PDT 2011]
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   114
     *     </pre></li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   115
     * <li> {@code java.util.logging.SimpleFormatter.format="%1$tc %2$s%n%4$s: %5$s%6$s%n"}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   116
     *     <p>This prints 2 lines where the first line includes
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   117
     *     the timestamp ({@code 1$}) and the source ({@code 2$});
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   118
     *     the second line includes the log level ({@code 4$}) and
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   119
     *     the log message ({@code 5$}) followed with the throwable
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   120
     *     and its backtrace ({@code 6$}), if any:
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   121
     *     <pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   122
     *     Tue Mar 22 13:11:31 PDT 2011 MyClass fatal
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   123
     *     SEVERE: several message with an exception
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   124
     *     java.lang.IllegalArgumentException: invalid argument
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   125
     *             at MyClass.mash(MyClass.java:9)
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   126
     *             at MyClass.crunch(MyClass.java:6)
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   127
     *             at MyClass.main(MyClass.java:3)
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   128
     *     </pre></li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   129
     * <li> {@code java.util.logging.SimpleFormatter.format="%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS %1$Tp %2$s%n%4$s: %5$s%n"}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   130
     *      <p>This prints 2 lines similar to the example above
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   131
     *         with a different date/time formatting and does not print
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   132
     *         the throwable and its backtrace:
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   133
     *     <pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   134
     *     Mar 22, 2011 1:11:31 PM MyClass fatal
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   135
     *     SEVERE: several message with an exception
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   136
     *     </pre></li>
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   137
     * <li> {@code java.util.logging.SimpleFormatter.format="%1$tb %1$td, %1$tY %1$tl:%1$tM:%1$tS.%1$tN %1$Tp %2$s%n%4$s: %5$s%6$s%n"}
35782
cce69c0777dc 8149601: Update references from "1.9" to "9"
iris
parents: 33875
diff changeset
   138
     *      <p>Since JDK 9, {@code java.util.logging} uses {@link
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   139
     *         java.time.Clock#systemUTC() java.time} to create more precise time
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   140
     *         stamps.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   141
     *         The format above can be used to add a {@code .%1$tN} to the
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   142
     *         date/time formatting so that nanoseconds will also be printed:
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   143
     *     <pre>
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   144
     *     Feb 06, 2015 5:33:10.279216000 PM example.Main main
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   145
     *     INFO: This is a test
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   146
     *     </pre></li>
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   147
     * </ul>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   148
     * <p>This method can also be overridden in a subclass.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * It is recommended to use the {@link Formatter#formatMessage}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * convenience method to localize and format the message field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @param record the log record to be formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * @return a formatted log record
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     */
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   155
    @Override
38884
48a0335cdadc 8153666: Optimize Formatter.formatMessage
dfuchs
parents: 36679
diff changeset
   156
    public String format(LogRecord record) {
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   157
        ZonedDateTime zdt = ZonedDateTime.ofInstant(
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
   158
                record.getInstant(), ZoneId.systemDefault());
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   159
        String source;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        if (record.getSourceClassName() != null) {
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   161
            source = record.getSourceClassName();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   162
            if (record.getSourceMethodName() != null) {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   163
               source += " " + record.getSourceMethodName();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   164
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        } else {
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   166
            source = record.getLoggerName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        String message = formatMessage(record);
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   169
        String throwable = "";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        if (record.getThrown() != null) {
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   171
            StringWriter sw = new StringWriter();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   172
            PrintWriter pw = new PrintWriter(sw);
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   173
            pw.println();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   174
            record.getThrown().printStackTrace(pw);
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   175
            pw.close();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   176
            throwable = sw.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   178
        return String.format(format,
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   179
                             zdt,
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   180
                             source,
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   181
                             record.getLoggerName(),
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 9014
diff changeset
   182
                             record.getLevel().getLocalizedLevelName(),
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   183
                             message,
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   184
                             throwable);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
}