jdk/src/share/classes/java/util/logging/LogRecord.java
author psandoz
Fri, 20 Dec 2013 13:38:13 +0100
changeset 22078 bdec5d53e98c
parent 18565 5025d43d3731
permissions -rw-r--r--
8030851: Update code in java.util to use newer language features Reviewed-by: dfuchs, briangoetz, chegar, alanb, mduigou
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
18565
5025d43d3731 8019315: Fix doclint issues in java.util.logging
darcy
parents: 7816
diff changeset
     2
 * Copyright (c) 2000, 2013, 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: 3861
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: 3861
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: 3861
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3861
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
package java.util.logging;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.*;
2632
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    28
import java.util.concurrent.atomic.AtomicInteger;
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    29
import java.util.concurrent.atomic.AtomicLong;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
    32
import sun.misc.JavaLangAccess;
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
    33
import sun.misc.SharedSecrets;
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
    34
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * LogRecord objects are used to pass logging requests between
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * the logging framework and individual log Handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * When a LogRecord is passed into the logging framework it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * logically belongs to the framework and should no longer be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * used or updated by the client application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Note that if the client application has not specified an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * explicit source method name and source class name, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * LogRecord class will infer them automatically when they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * first accessed (due to a call on getSourceMethodName or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * getSourceClassName) by analyzing the call stack.  Therefore,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * if a logging Handler wants to pass off a LogRecord to another
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * thread, or to transmit it over RMI, and if it wishes to subsequently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * obtain method name or class name information it should call
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * one of getSourceClassName or getSourceMethodName to force
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * the values to be filled in.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <b> Serialization notes:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <li>The LogRecord class is serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <li> Because objects in the parameters array may not be serializable,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * during serialization all objects in the parameters array are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * written as the corresponding Strings (using Object.toString).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <li> The ResourceBundle is not transmitted as part of the serialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * form, but the resource bundle name is, and the recipient object's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * readObject method will attempt to locate a suitable resource bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public class LogRecord implements java.io.Serializable {
2632
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    72
    private static final AtomicLong globalSequenceNumber
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    73
        = new AtomicLong(0);
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    74
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    75
    /**
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    76
     * The default value of threadID will be the current thread's
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    77
     * thread id, for ease of correlation, unless it is greater than
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    78
     * MIN_SEQUENTIAL_THREAD_ID, in which case we try harder to keep
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    79
     * our promise to keep threadIDs unique by avoiding collisions due
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    80
     * to 32-bit wraparound.  Unfortunately, LogRecord.getThreadID()
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    81
     * returns int, while Thread.getId() returns long.
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    82
     */
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    83
    private static final int MIN_SEQUENTIAL_THREAD_ID = Integer.MAX_VALUE / 2;
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    84
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    85
    private static final AtomicInteger nextThreadId
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    86
        = new AtomicInteger(MIN_SEQUENTIAL_THREAD_ID);
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
    87
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 7026
diff changeset
    88
    private static final ThreadLocal<Integer> threadIds = new ThreadLocal<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * @serial Logging message level
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    private Level level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @serial Sequence number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private long sequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * @serial Class that issued logging call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    private String sourceClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @serial Method that issued logging call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    private String sourceMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @serial Non-localized raw message text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private String message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @serial Thread ID for thread that issued logging call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private int threadID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * @serial Event time in milliseconds since 1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private long millis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * @serial The Throwable (if any) associated with log message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private Throwable thrown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * @serial Name of the source Logger.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    private String loggerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @serial Resource bundle name to localized log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    private String resourceBundleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    private transient boolean needToInferCaller;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    private transient Object parameters[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    private transient ResourceBundle resourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
2632
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   145
     * Returns the default value for a new LogRecord's threadID.
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   146
     */
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   147
    private int defaultThreadID() {
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   148
        long tid = Thread.currentThread().getId();
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   149
        if (tid < MIN_SEQUENTIAL_THREAD_ID) {
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   150
            return (int) tid;
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   151
        } else {
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   152
            Integer id = threadIds.get();
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   153
            if (id == null) {
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   154
                id = nextThreadId.getAndIncrement();
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   155
                threadIds.set(id);
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   156
            }
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   157
            return id;
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   158
        }
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   159
    }
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   160
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   161
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * Construct a LogRecord with the given level and message values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * The sequence property will be initialized with a new unique value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * These sequence values are allocated in increasing order within a VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * The millis property will be initialized to the current time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * The thread ID property will be initialized with a unique ID for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * the current thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * All other properties will be initialized to "null".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param level  a logging level value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @param msg  the raw non-localized logging message (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    public LogRecord(Level level, String msg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        // Make sure level isn't null, by calling random method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        level.getClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        this.level = level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        message = msg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        // Assign a thread ID and a unique sequence number.
2632
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   183
        sequenceNumber = globalSequenceNumber.getAndIncrement();
9779b9cbae42 6278014: java.util.logging.LogRecord.getThreadID() should provide real thread id
martin
parents: 2
diff changeset
   184
        threadID = defaultThreadID();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        millis = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        needToInferCaller = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2947
diff changeset
   190
     * Get the source Logger's name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @return source logger name (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public String getLoggerName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        return loggerName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2947
diff changeset
   199
     * Set the source Logger's name.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * @param name   the source logger name (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    public void setLoggerName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        loggerName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * Get the localization resource bundle
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * This is the ResourceBundle that should be used to localize
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * the message string before formatting it.  The result may
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * be null if the message is not localizable, or if no suitable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * ResourceBundle is available.
18565
5025d43d3731 8019315: Fix doclint issues in java.util.logging
darcy
parents: 7816
diff changeset
   214
     * @return the localization resource bundle
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    public ResourceBundle getResourceBundle() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return resourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Set the localization resource bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @param bundle  localization bundle (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public void setResourceBundle(ResourceBundle bundle) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        resourceBundle = bundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Get the localization resource bundle name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * This is the name for the ResourceBundle that should be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * used to localize the message string before formatting it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * The result may be null if the message is not localizable.
18565
5025d43d3731 8019315: Fix doclint issues in java.util.logging
darcy
parents: 7816
diff changeset
   235
     * @return the localization resource bundle name
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    public String getResourceBundleName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return resourceBundleName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * Set the localization resource bundle name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @param name  localization bundle name (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public void setResourceBundleName(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        resourceBundleName = name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Get the logging message level, for example Level.SEVERE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @return the logging message level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    public Level getLevel() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Set the logging message level, for example Level.SEVERE.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @param level the logging message level
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public void setLevel(Level level) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        if (level == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        this.level = level;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Get the sequence number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * Sequence numbers are normally assigned in the LogRecord
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * constructor, which assigns unique sequence numbers to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * each new LogRecord in increasing order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @return the sequence number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    public long getSequenceNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        return sequenceNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * Set the sequence number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Sequence numbers are normally assigned in the LogRecord constructor,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * so it should not normally be necessary to use this method.
18565
5025d43d3731 8019315: Fix doclint issues in java.util.logging
darcy
parents: 7816
diff changeset
   286
     * @param seq the sequence number
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    public void setSequenceNumber(long seq) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        sequenceNumber = seq;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * Get the  name of the class that (allegedly) issued the logging request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * Note that this sourceClassName is not verified and may be spoofed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * This information may either have been provided as part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * logging call, or it may have been inferred automatically by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * logging framework.  In the latter case, the information may only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * be approximate and may in fact describe an earlier call on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * stack frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * May be null if no information could be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * @return the source class name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    public String getSourceClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (needToInferCaller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            inferCaller();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        return sourceClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * Set the name of the class that (allegedly) issued the logging request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * @param sourceClassName the source class name (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    public void setSourceClassName(String sourceClassName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        this.sourceClassName = sourceClassName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        needToInferCaller = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * Get the  name of the method that (allegedly) issued the logging request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Note that this sourceMethodName is not verified and may be spoofed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * This information may either have been provided as part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * logging call, or it may have been inferred automatically by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * logging framework.  In the latter case, the information may only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * be approximate and may in fact describe an earlier call on the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * stack frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * May be null if no information could be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @return the source method name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    public String getSourceMethodName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        if (needToInferCaller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            inferCaller();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return sourceMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * Set the name of the method that (allegedly) issued the logging request.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @param sourceMethodName the source method name (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    public void setSourceMethodName(String sourceMethodName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        this.sourceMethodName = sourceMethodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        needToInferCaller = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * Get the "raw" log message, before localization or formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * May be null, which is equivalent to the empty string "".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * This message may be either the final text or a localization key.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * During formatting, if the source logger has a localization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * ResourceBundle and if that ResourceBundle has an entry for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * this message string, then the message string is replaced
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * with the localized value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * @return the raw message string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    public String getMessage() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Set the "raw" log message, before localization or formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @param message the raw message string (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    public void setMessage(String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        this.message = message;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Get the parameters to the log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * @return the log message parameters.  May be null if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *                  there are no parameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public Object[] getParameters() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        return parameters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Set the parameters to the log message.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param parameters the log message parameters. (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    public void setParameters(Object parameters[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        this.parameters = parameters;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
     * Get an identifier for the thread where the message originated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * This is a thread identifier within the Java VM and may or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * may not map to any operating system ID.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * @return thread ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    public int getThreadID() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return threadID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * Set an identifier for the thread where the message originated.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @param threadID  the thread ID
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public void setThreadID(int threadID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        this.threadID = threadID;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * Get event time in milliseconds since 1970.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * @return event time in millis since 1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    public long getMillis() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        return millis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Set event time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @param millis event time in millis since 1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public void setMillis(long millis) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        this.millis = millis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * Get any throwable associated with the log record.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * If the event involved an exception, this will be the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * exception object. Otherwise null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * @return a throwable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    public Throwable getThrown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        return thrown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * Set a throwable associated with the log event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * @param thrown  a throwable (may be null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    public void setThrown(Throwable thrown) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
        this.thrown = thrown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    private static final long serialVersionUID = 5372048053134512534L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * @serialData Default fields, followed by a two byte version number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * (major byte, followed by minor byte), followed by information on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * the log record parameter array.  If there is no parameter array,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * then -1 is written.  If there is a parameter array (possible of zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * length) then the array length is written as an integer, followed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * by String values for each parameter.  If a parameter is null, then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * a null String is written.  Otherwise the output of Object.toString()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * is written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    private void writeObject(ObjectOutputStream out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        // We have to call defaultWriteObject first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        out.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        // Write our version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        out.writeByte(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        out.writeByte(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (parameters == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            out.writeInt(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        out.writeInt(parameters.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
        // Write string values for the parameters.
22078
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 18565
diff changeset
   484
        for (Object parameter : parameters) {
bdec5d53e98c 8030851: Update code in java.util to use newer language features
psandoz
parents: 18565
diff changeset
   485
            out.writeObject(Objects.toString(parameter, null));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
    private void readObject(ObjectInputStream in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                        throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        // We have to call defaultReadObject first.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        in.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        // Read version number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        byte major = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        byte minor = in.readByte();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        if (major != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            throw new IOException("LogRecord: bad version: " + major + "." + minor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        int len = in.readInt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        if (len == -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
            parameters = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            parameters = new Object[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            for (int i = 0; i < parameters.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                parameters[i] = in.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        // If necessary, try to regenerate the resource bundle.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (resourceBundleName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                resourceBundle = ResourceBundle.getBundle(resourceBundleName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            } catch (MissingResourceException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                // This is not a good place to throw an exception,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                // so we simply leave the resourceBundle null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                resourceBundle = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        needToInferCaller = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    // Private method to infer the caller's class and method names
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
    private void inferCaller() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        needToInferCaller = false;
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   526
        JavaLangAccess access = SharedSecrets.getJavaLangAccess();
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   527
        Throwable throwable = new Throwable();
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   528
        int depth = access.getStackTraceDepth(throwable);
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   529
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   530
        boolean lookingForLogger = true;
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   531
        for (int ix = 0; ix < depth; ix++) {
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   532
            // Calling getStackTraceElement directly prevents the VM
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   533
            // from paying the cost of building the entire stack frame.
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   534
            StackTraceElement frame =
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   535
                access.getStackTraceElement(throwable, ix);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            String cname = frame.getClassName();
7026
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   537
            boolean isLoggerImpl = isLoggerImplFrame(cname);
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   538
            if (lookingForLogger) {
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   539
                // Skip all frames until we have found the first logger frame.
7026
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   540
                if (isLoggerImpl) {
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   541
                    lookingForLogger = false;
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   542
                }
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   543
            } else {
7026
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   544
                if (!isLoggerImpl) {
3861
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 3853
diff changeset
   545
                    // skip reflection call
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 3853
diff changeset
   546
                    if (!cname.startsWith("java.lang.reflect.") && !cname.startsWith("sun.reflect.")) {
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 3853
diff changeset
   547
                       // We've found the relevant frame.
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 3853
diff changeset
   548
                       setSourceClassName(cname);
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 3853
diff changeset
   549
                       setSourceMethodName(frame.getMethodName());
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 3853
diff changeset
   550
                       return;
a98a057ec335 6882376: Add internal support for JRE implementation to eliminate the dependency on logging
mchung
parents: 3853
diff changeset
   551
                    }
2947
b0135c99348e 6511515: poor performance of LogRecord.inferCaller depending on java.lang.Throwable.getStackTraceElement
martin
parents: 2632
diff changeset
   552
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
        // We haven't found a suitable frame, so just punt.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        // OK as we are only committed to making a "best effort" here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    }
7026
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   558
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   559
    private boolean isLoggerImplFrame(String cname) {
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   560
        // the log record could be created for a platform logger
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   561
        return (cname.equals("java.util.logging.Logger") ||
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   562
                cname.startsWith("java.util.logging.LoggingProxyImpl") ||
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   563
                cname.startsWith("sun.util.logging."));
9f2ec5fad124 6985460: PlatformLogger throws ArrayStoreException when j.u.logging is initialized
mchung
parents: 5506
diff changeset
   564
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
}