src/java.logging/share/classes/java/util/logging/SimpleFormatter.java
author rpatil
Wed, 26 Dec 2018 17:09:19 +0530
changeset 53120 de9fd809bb47
parent 52138 059384474dde
permissions -rw-r--r--
8214567: Use {@systemProperty} for definitions of system properties 8214569: Use {@systemProperty} for definitions of system properties Reviewed-by: lancea, mchung, alanb, naoto Contributed-by: Deepak kejriwal <deepak.kejriwal@oracle.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
52138
059384474dde 8211960: broken links in java.util.logging
dfuchs
parents: 47216
diff changeset
     2
 * Copyright (c) 2000, 2018, 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>
45132
db2f2d72cd4f 8179697: Fix Html5 errors in java.naming, java.logging, jdk.httpserver, jdk.net, jdk.sctp
ksrini
parents: 38884
diff changeset
    39
 * <a id="formatting">
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    40
 * <b>Configuration:</b></a>
52138
059384474dde 8211960: broken links in java.util.logging
dfuchs
parents: 47216
diff changeset
    41
 * The {@code SimpleFormatter} is initialized with the format string
53120
de9fd809bb47 8214567: Use {@systemProperty} for definitions of system properties
rpatil
parents: 52138
diff changeset
    42
 * specified in the {@systemProperty java.util.logging.SimpleFormatter.format}
46144
cfb94413b9a4 8185984: fix a11y and html issues in java.logging module
jjg
parents: 45132
diff changeset
    43
 * property to {@linkplain #format(LogRecord) format} the log messages.
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    44
 * This property can be defined
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    45
 * in the {@linkplain LogManager#getProperty logging properties}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    46
 * configuration file
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    47
 * 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
    48
 * the logging properties and system properties,
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    49
 * 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
    50
 * 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
    51
 * is {@linkplain java.util.IllegalFormatException illegal},
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    52
 * the default format is implementation-specific.
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    53
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * @since 1.4
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    55
 * @see java.util.Formatter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class SimpleFormatter extends Formatter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    60
    // format string for printing the log record
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
    61
    static String getLoggingProperty(String name) {
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
    62
        return LogManager.getLogManager().getProperty(name);
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
    63
    }
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
    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
    66
        SurrogateLogger.getSimpleFormat(SimpleFormatter::getLoggingProperty);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * Format the given LogRecord.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * <p>
52138
059384474dde 8211960: broken links in java.util.logging
dfuchs
parents: 47216
diff changeset
    71
     * The formatting can be customized by specifying the format string
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    72
     * in the <a href="#formatting">
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    73
     * {@code java.util.logging.SimpleFormatter.format}</a> property.
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    74
     * 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
    75
     * <pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    76
     *    {@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
    77
     * </pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    78
     * where the arguments are:<br>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    79
     * <ol>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    80
     * <li>{@code format} - the {@link java.util.Formatter
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    81
     *     java.util.Formatter} format string specified in the
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    82
     *     {@code java.util.logging.SimpleFormatter.format} property
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    83
     *     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
    84
     * <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
    85
     *     {@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
    86
     *      in the {@link ZoneId#systemDefault()} system time zone.</li>
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    87
     * <li>{@code source} - a string representing the caller, if available;
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    88
     *     otherwise, the logger's name.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    89
     * <li>{@code logger} - the logger's name.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    90
     * <li>{@code level} - the {@linkplain Level#getLocalizedName
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    91
     *     log level}.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    92
     * <li>{@code message} - the formatted log message
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    93
     *     returned from the {@link Formatter#formatMessage(LogRecord)}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    94
     *     method.  It uses {@link java.text.MessageFormat java.text}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    95
     *     formatting and does not use the {@code java.util.Formatter
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    96
     *     format} argument.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    97
     * <li>{@code thrown} - a string representing
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    98
     *     the {@linkplain LogRecord#getThrown throwable}
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
    99
     *     associated with the log record and its backtrace
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   100
     *     beginning with a newline character, if any;
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   101
     *     otherwise, an empty string.</li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   102
     * </ol>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   103
     *
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   104
     * <p>Some example formats:<br>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   105
     * <ul>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   106
     * <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
   107
     *     <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
   108
     *     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
   109
     *     a square bracket.
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   110
     *     <pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   111
     *     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
   112
     *     </pre></li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   113
     * <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
   114
     *     <p>This prints 2 lines where the first line includes
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   115
     *     the timestamp ({@code 1$}) and the source ({@code 2$});
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   116
     *     the second line includes the log level ({@code 4$}) and
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   117
     *     the log message ({@code 5$}) followed with the throwable
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   118
     *     and its backtrace ({@code 6$}), if any:
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   119
     *     <pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   120
     *     Tue Mar 22 13:11:31 PDT 2011 MyClass fatal
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   121
     *     SEVERE: several message with an exception
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   122
     *     java.lang.IllegalArgumentException: invalid argument
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   123
     *             at MyClass.mash(MyClass.java:9)
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   124
     *             at MyClass.crunch(MyClass.java:6)
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   125
     *             at MyClass.main(MyClass.java:3)
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   126
     *     </pre></li>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   127
     * <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
   128
     *      <p>This prints 2 lines similar to the example above
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   129
     *         with a different date/time formatting and does not print
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   130
     *         the throwable and its backtrace:
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   131
     *     <pre>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   132
     *     Mar 22, 2011 1:11:31 PM MyClass fatal
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   133
     *     SEVERE: several message with an exception
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   134
     *     </pre></li>
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   135
     * <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
   136
     *      <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
   137
     *         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
   138
     *         stamps.
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   139
     *         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
   140
     *         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
   141
     *     <pre>
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   142
     *     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
   143
     *     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
   144
     *     </pre></li>
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   145
     * </ul>
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   146
     * <p>This method can also be overridden in a subclass.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * It is recommended to use the {@link Formatter#formatMessage}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * convenience method to localize and format the message field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * @param record the log record to be formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @return a formatted log record
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     */
29117
7956b5dc0eac 8072645: java.util.logging should use java.time to get more precise time stamps
dfuchs
parents: 25859
diff changeset
   153
    @Override
38884
48a0335cdadc 8153666: Optimize Formatter.formatMessage
dfuchs
parents: 36679
diff changeset
   154
    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
   155
        ZonedDateTime zdt = ZonedDateTime.ofInstant(
33875
c1c71107d45f 8140364: JEP 264 Platform Logger API and Service Implementation
dfuchs
parents: 29117
diff changeset
   156
                record.getInstant(), ZoneId.systemDefault());
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   157
        String source;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (record.getSourceClassName() != null) {
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   159
            source = record.getSourceClassName();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   160
            if (record.getSourceMethodName() != null) {
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   161
               source += " " + record.getSourceMethodName();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   162
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } else {
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   164
            source = record.getLoggerName();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        String message = formatMessage(record);
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   167
        String throwable = "";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (record.getThrown() != null) {
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   169
            StringWriter sw = new StringWriter();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   170
            PrintWriter pw = new PrintWriter(sw);
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   171
            pw.println();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   172
            record.getThrown().printStackTrace(pw);
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   173
            pw.close();
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   174
            throwable = sw.toString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   176
        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
   177
                             zdt,
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   178
                             source,
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   179
                             record.getLoggerName(),
16098
9001e536ab4e 6664509: Add logging context
mchung
parents: 9014
diff changeset
   180
                             record.getLevel().getLocalizedLevelName(),
9014
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   181
                             message,
117374ccf1b7 6381464: SimpleFormatter should use one single line format
mchung
parents: 5506
diff changeset
   182
                             throwable);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
}