jdk/src/share/classes/java/util/logging/FileHandler.java
author mchung
Thu, 07 Feb 2013 09:41:47 -0800
changeset 16112 fc9eb3e70734
parent 14509 4358b75583be
child 18156 edb590d448c5
permissions -rw-r--r--
8007611: logging behavior in applet changed Reviewed-by: alanb, jgish
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
     2
 * Copyright (c) 2000, 2012, 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: 3853
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: 3853
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: 3853
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3853
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 3853
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
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    28
import static java.nio.file.StandardOpenOption.CREATE_NEW;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    29
import static java.nio.file.StandardOpenOption.WRITE;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    30
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    31
import java.io.BufferedOutputStream;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    32
import java.io.File;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    33
import java.io.FileOutputStream;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    34
import java.io.IOException;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    35
import java.io.OutputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.nio.channels.FileChannel;
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    37
import java.nio.file.FileAlreadyExistsException;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    38
import java.nio.file.Paths;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    39
import java.security.AccessController;
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
    40
import java.security.PrivilegedAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Simple file logging <tt>Handler</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * The <tt>FileHandler</tt> can either write to a specified file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * or it can write to a rotating set of files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * For a rotating set of files, as each file reaches a given size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * limit, it is closed, rotated out, and a new file opened.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * Successively older files are named by adding "0", "1", "2",
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2
diff changeset
    51
 * etc. into the base filename.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * By default buffering is enabled in the IO libraries but each log
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * record is flushed out when it is complete.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * By default the <tt>XMLFormatter</tt> class is used for formatting.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <b>Configuration:</b>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * By default each <tt>FileHandler</tt> is initialized using the following
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    60
 * <tt>LogManager</tt> configuration properties where <tt>&lt;handler-name&gt;</tt>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    61
 * refers to the fully-qualified class name of the handler.
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    62
 * If properties are not defined
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * (or have invalid values) then the specified default values are used.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <ul>
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    65
 * <li>   &lt;handler-name&gt;.level
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *        specifies the default level for the <tt>Handler</tt>
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    67
 *        (defaults to <tt>Level.ALL</tt>). </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    68
 * <li>   &lt;handler-name&gt;.filter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *        specifies the name of a <tt>Filter</tt> class to use
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    70
 *        (defaults to no <tt>Filter</tt>). </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    71
 * <li>   &lt;handler-name&gt;.formatter
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *        specifies the name of a <tt>Formatter</tt> class to use
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    73
 *        (defaults to <tt>java.util.logging.XMLFormatter</tt>) </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    74
 * <li>   &lt;handler-name&gt;.encoding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *        the name of the character set encoding to use (defaults to
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    76
 *        the default platform encoding). </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    77
 * <li>   &lt;handler-name&gt;.limit
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *        specifies an approximate maximum amount to write (in bytes)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *        to any one file.  If this is zero, then there is no limit.
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    80
 *        (Defaults to no limit). </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    81
 * <li>   &lt;handler-name&gt;.count
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    82
 *        specifies how many output files to cycle through (defaults to 1). </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    83
 * <li>   &lt;handler-name&gt;.pattern
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *        specifies a pattern for generating the output file name.  See
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    85
 *        below for details. (Defaults to "%h/java%u.log"). </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    86
 * <li>   &lt;handler-name&gt;.append
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *        specifies whether the FileHandler should append onto
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    88
 *        any existing files (defaults to false). </li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * <p>
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    91
 * For example, the properties for {@code FileHandler} would be:
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    92
 * <ul>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    93
 * <li>   java.util.logging.FileHandler.level=INFO </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    94
 * <li>   java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    95
 * </ul>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    96
 * <p>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    97
 * For a custom handler, e.g. com.foo.MyHandler, the properties would be:
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    98
 * <ul>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
    99
 * <li>   com.foo.MyHandler.level=INFO </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
   100
 * <li>   com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
   101
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * A pattern consists of a string that includes the following special
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * components that will be replaced at runtime:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <ul>
14321
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
   106
 * <li>    "/"    the local pathname separator </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
   107
 * <li>     "%t"   the system temporary directory </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
   108
 * <li>     "%h"   the value of the "user.home" system property </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
   109
 * <li>     "%g"   the generation number to distinguish rotated logs </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
   110
 * <li>     "%u"   a unique number to resolve conflicts </li>
7f9f265ac11e 7159567: inconsistent configuration of MemoryHandler
jgish
parents: 9275
diff changeset
   111
 * <li>     "%%"   translates to a single percent sign "%" </li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * If no "%g" field has been specified and the file count is greater
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * than one, then the generation number will be added to the end of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * the generated filename, after a dot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * Thus for example a pattern of "%t/java%g.log" with a count of 2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * would typically cause log files to be written on Solaris to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * /var/tmp/java0.log and /var/tmp/java1.log whereas on Windows 95 they
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * would be typically written to C:\TEMP\java0.log and C:\TEMP\java1.log
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * Generation numbers follow the sequence 0, 1, 2, etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * Normally the "%u" unique field is set to 0.  However, if the <tt>FileHandler</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * tries to open the filename and finds the file is currently in use by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * another process it will increment the unique number field and try
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * again.  This will be repeated until <tt>FileHandler</tt> finds a file name that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * is  not currently in use. If there is a conflict and no "%u" field has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * been specified, it will be added at the end of the filename after a dot.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * (This will be after any automatically added generation number.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * Thus if three processes were all trying to log to fred%u.%g.txt then
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * they  might end up using fred0.0.txt, fred1.0.txt, fred2.0.txt as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * the first file in their rotating sequences.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * Note that the use of unique ids to avoid conflicts is only guaranteed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * to work reliably when using a local disk file system.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
public class FileHandler extends StreamHandler {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    private MeteredStream meter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private boolean append;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private int limit;       // zero => no limit.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    private int count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    private String pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private String lockFileName;
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   149
    private FileChannel lockFileChannel;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    private File files[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    private static final int MAX_LOCKS = 100;
7803
56bc97d69d93 6880112: Project Coin: Port JDK core library code to use diamond operator
smarks
parents: 5506
diff changeset
   152
    private static java.util.HashMap<String, String> locks = new java.util.HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   154
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   155
     * A metered stream is a subclass of OutputStream that
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   156
     * (a) forwards all its output to a target stream
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   157
     * (b) keeps track of how many bytes have been written
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   158
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    private class MeteredStream extends OutputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        OutputStream out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        int written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        MeteredStream(OutputStream out, int written) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            this.out = out;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            this.written = written;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        public void write(int b) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            out.write(b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            written++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        public void write(byte buff[]) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            out.write(buff);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            written += buff.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        public void write(byte buff[], int off, int len) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            out.write(buff,off,len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            written += len;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        public void flush() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            out.flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        public void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            out.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    private void open(File fname, boolean append) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        int len = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (append) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            len = (int)fname.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        FileOutputStream fout = new FileOutputStream(fname.toString(), append);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        BufferedOutputStream bout = new BufferedOutputStream(fout);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        meter = new MeteredStream(bout, len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
        setOutputStream(meter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   203
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   204
     * Configure a FileHandler from LogManager properties and/or default values
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   205
     * as specified in the class javadoc.
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   206
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    private void configure() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        LogManager manager = LogManager.getLogManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        String cname = getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        pattern = manager.getStringProperty(cname + ".pattern", "%h/java%u.log");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        limit = manager.getIntProperty(cname + ".limit", 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        if (limit < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            limit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        count = manager.getIntProperty(cname + ".count", 1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (count <= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        append = manager.getBooleanProperty(cname + ".append", false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        setLevel(manager.getLevelProperty(cname + ".level", Level.ALL));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        setFilter(manager.getFilterProperty(cname + ".filter", null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        setFormatter(manager.getFormatterProperty(cname + ".formatter", new XMLFormatter()));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            setEncoding(manager.getStringProperty(cname +".encoding", null));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                setEncoding(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            } catch (Exception ex2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                // doing a setEncoding with null should always work.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                // assert false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * Construct a default <tt>FileHandler</tt>.  This will be configured
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * entirely from <tt>LogManager</tt> properties (or their default values).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * @exception  IOException if there are IO problems opening the files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     *             the caller does not have <tt>LoggingPermission("control"))</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * @exception  NullPointerException if pattern property is an empty String.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
    public FileHandler() throws IOException, SecurityException {
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 9275
diff changeset
   248
        checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        configure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        openFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * Initialize a <tt>FileHandler</tt> to write to the given filename.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * The <tt>FileHandler</tt> is configured based on <tt>LogManager</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * properties (or their default values) except that the given pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * argument is used as the filename pattern, the file limit is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * set to no limit, and the file count is set to one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * There is no limit on the amount of data that may be written,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * so use this with care.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param pattern  the name of the output file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @exception  IOException if there are IO problems opening the files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *             the caller does not have <tt>LoggingPermission("control")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @exception  IllegalArgumentException if pattern is an empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    public FileHandler(String pattern) throws IOException, SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (pattern.length() < 1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 9275
diff changeset
   274
        checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        configure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        this.pattern = pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        this.limit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        this.count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        openFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * Initialize a <tt>FileHandler</tt> to write to the given filename,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * with optional append.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * The <tt>FileHandler</tt> is configured based on <tt>LogManager</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * properties (or their default values) except that the given pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * argument is used as the filename pattern, the file limit is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * set to no limit, the file count is set to one, and the append
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * mode is set to the given <tt>append</tt> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * There is no limit on the amount of data that may be written,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * so use this with care.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param pattern  the name of the output file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @param append  specifies append mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @exception  IOException if there are IO problems opening the files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     *             the caller does not have <tt>LoggingPermission("control")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * @exception  IllegalArgumentException if pattern is an empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     */
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   302
    public FileHandler(String pattern, boolean append) throws IOException,
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   303
            SecurityException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
        if (pattern.length() < 1 ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 9275
diff changeset
   307
        checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
        configure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        this.pattern = pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        this.limit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        this.count = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        this.append = append;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        openFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Initialize a <tt>FileHandler</tt> to write to a set of files.  When
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * (approximately) the given limit has been written to one file,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * another file will be opened.  The output will cycle through a set
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * of count files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * The <tt>FileHandler</tt> is configured based on <tt>LogManager</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * properties (or their default values) except that the given pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * argument is used as the filename pattern, the file limit is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * set to the limit argument, and the file count is set to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * given count argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * The count must be at least 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param pattern  the pattern for naming the output file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @param limit  the maximum number of bytes to write to any one file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @param count  the number of files to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * @exception  IOException if there are IO problems opening the files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     *             the caller does not have <tt>LoggingPermission("control")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @exception IllegalArgumentException if limit < 0, or count < 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @exception  IllegalArgumentException if pattern is an empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
    public FileHandler(String pattern, int limit, int count)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
                                        throws IOException, SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        if (limit < 0 || count < 1 || pattern.length() < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 9275
diff changeset
   344
        checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        configure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        this.pattern = pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        this.limit = limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        this.count = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        openFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * Initialize a <tt>FileHandler</tt> to write to a set of files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * with optional append.  When (approximately) the given limit has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * been written to one file, another file will be opened.  The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * output will cycle through a set of count files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * The <tt>FileHandler</tt> is configured based on <tt>LogManager</tt>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * properties (or their default values) except that the given pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * argument is used as the filename pattern, the file limit is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * set to the limit argument, and the file count is set to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * given count argument, and the append mode is set to the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <tt>append</tt> argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * The count must be at least 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * @param pattern  the pattern for naming the output file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * @param limit  the maximum number of bytes to write to any one file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param count  the number of files to use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @param append  specifies append mode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * @exception  IOException if there are IO problems opening the files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *             the caller does not have <tt>LoggingPermission("control")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @exception IllegalArgumentException if limit < 0, or count < 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * @exception  IllegalArgumentException if pattern is an empty string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    public FileHandler(String pattern, int limit, int count, boolean append)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                                        throws IOException, SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        if (limit < 0 || count < 1 || pattern.length() < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            throw new IllegalArgumentException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 9275
diff changeset
   383
        checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        configure();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
        this.pattern = pattern;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
        this.limit = limit;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        this.count = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
        this.append = append;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        openFiles();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   392
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   393
     * Open the set of output files, based on the configured
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   394
     * instance variables.
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   395
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    private void openFiles() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        LogManager manager = LogManager.getLogManager();
14216
23714b376286 7169884: LogManager checks do not work correctly for sub-types
alanb
parents: 9275
diff changeset
   398
        manager.checkPermission();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        if (count < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
           throw new IllegalArgumentException("file count = " + count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (limit < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            limit = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        // We register our own ErrorManager during initialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // so we can record exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        InitializationErrorManager em = new InitializationErrorManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        setErrorManager(em);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        // Create a lock file.  This grants us exclusive access
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        // to our set of output files, as long as we are alive.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        int unique = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        for (;;) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            unique++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            if (unique > MAX_LOCKS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                throw new IOException("Couldn't get lock for " + pattern);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
            // Generate a lock file name from the "unique" int.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            lockFileName = generate(pattern, 0, unique).toString() + ".lck";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            // Now try to lock that filename.
3853
9d2382b74894 6882363: 4/4 typos in java.util.logging javadocs
dcubed
parents: 2
diff changeset
   422
            // Because some systems (e.g., Solaris) can only do file locks
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            // between processes (and not within a process), we first check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            // if we ourself already have the file locked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            synchronized(locks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                if (locks.get(lockFileName) != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                    // We already own this lock, for a different FileHandler
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                    // object.  Try again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                }
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   431
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                try {
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   433
                    lockFileChannel = FileChannel.open(Paths.get(lockFileName),
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   434
                            CREATE_NEW, WRITE);
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   435
                } catch (FileAlreadyExistsException ix) {
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   436
                    // try the next lock file name in the sequence
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                }
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   439
9271
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   440
                boolean available;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                try {
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   442
                    available = lockFileChannel.tryLock() != null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                    // We got the lock OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
                } catch (IOException ix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
                    // We got an IOException while trying to get the lock.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
                    // This normally indicates that locking is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
                    // on the target directory.  We have to proceed without
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
                    // getting a lock.   Drop through.
9271
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   449
                    available = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                }
9271
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   451
                if (available) {
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   452
                    // We got the lock.  Remember it.
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   453
                    locks.put(lockFileName, lockFileName);
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   454
                    break;
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   455
                }
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   456
2d7e19ff03d1 7032589: FileHandler leaking file descriptor of the file lock
mchung
parents: 7803
diff changeset
   457
                // We failed to get the lock.  Try next file.
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   458
                lockFileChannel.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        files = new File[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
            files[i] = generate(pattern, i, unique);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        // Create the initial log file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (append) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            open(files[0], true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            rotate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        // Did we detect any exceptions during initialization?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        Exception ex = em.lastException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        if (ex != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            if (ex instanceof IOException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                throw (IOException) ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            } else if (ex instanceof SecurityException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                throw (SecurityException) ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                throw new IOException("Exception: " + ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        // Install the normal default ErrorManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        setErrorManager(new ErrorManager());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   490
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   491
     * Generate a file based on a user-supplied pattern, generation number,
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   492
     * and an integer uniqueness suffix
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   493
     * @param pattern the pattern for naming the output file
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   494
     * @param generation the generation number to distinguish rotated logs
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   495
     * @param unique a unique number to resolve conflicts
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   496
     * @return the generated File
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   497
     * @throws IOException
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   498
     */
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   499
    private File generate(String pattern, int generation, int unique)
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   500
            throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        File file = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
        String word = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        int ix = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        boolean sawg = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        boolean sawu = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        while (ix < pattern.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            char ch = pattern.charAt(ix);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            ix++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            char ch2 = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            if (ix < pattern.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                ch2 = Character.toLowerCase(pattern.charAt(ix));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            if (ch == '/') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                    file = new File(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    file = new File(file, word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                word = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
            } else  if (ch == '%') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                if (ch2 == 't') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    String tmpDir = System.getProperty("java.io.tmpdir");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                    if (tmpDir == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                        tmpDir = System.getProperty("user.home");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    file = new File(tmpDir);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                    ix++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
                    word = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
                } else if (ch2 == 'h') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                    file = new File(System.getProperty("user.home"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                    if (isSetUID()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
                        // Ok, we are in a set UID program.  For safety's sake
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                        // we disallow attempts to open files relative to %h.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
                        throw new IOException("can't use %h in set UID program");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
                    ix++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
                    word = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
                } else if (ch2 == 'g') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    word = word + generation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
                    sawg = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                    ix++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                } else if (ch2 == 'u') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
                    word = word + unique;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
                    sawu = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
                    ix++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
                } else if (ch2 == '%') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
                    word = word + "%";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                    ix++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            word = word + ch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (count > 1 && !sawg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            word = word + "." + generation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        if (unique > 0 && !sawu) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
            word = word + "." + unique;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        if (word.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            if (file == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                file = new File(word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
                file = new File(file, word);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return file;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   575
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   576
     * Rotate the set of output files
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   577
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
    private synchronized void rotate() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
        Level oldLevel = getLevel();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
        setLevel(Level.OFF);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
        for (int i = count-2; i >= 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            File f1 = files[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            File f2 = files[i+1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
            if (f1.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                if (f2.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    f2.delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                f1.renameTo(f2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            open(files[0], false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
        } catch (IOException ix) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
            // We don't want to throw an exception here, but we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
            // report the exception to any registered ErrorManager.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
            reportError(null, ix, ErrorManager.OPEN_FAILURE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
        setLevel(oldLevel);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * Format and publish a <tt>LogRecord</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
     * @param  record  description of the log event. A null record is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     *                 silently ignored and is not published
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
    public synchronized void publish(LogRecord record) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        if (!isLoggable(record)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        super.publish(record);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
        flush();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (limit > 0 && meter.written >= limit) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            // We performed access checks in the "init" method to make sure
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            // we are only initialized from trusted code.  So we assume
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            // it is OK to write the target files, even if we are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            // currently being called from untrusted code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            // So it is safe to raise privilege here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            AccessController.doPrivileged(new PrivilegedAction<Object>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
                public Object run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
                    rotate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * Close all the files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
     * @exception  SecurityException  if a security manager exists and if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
     *             the caller does not have <tt>LoggingPermission("control")</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
    public synchronized void close() throws SecurityException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        super.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
        // Unlock any lock file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        if (lockFileName == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
        try {
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   644
            // Close the lock file channel (which also will free any locks)
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   645
            lockFileChannel.close();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
        } catch (Exception ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
            // Problems closing the stream.  Punt.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        synchronized(locks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            locks.remove(lockFileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        new File(lockFileName).delete();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
        lockFileName = null;
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   654
        lockFileChannel = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
    private static class InitializationErrorManager extends ErrorManager {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        Exception lastException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        public void error(String msg, Exception ex, int code) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            lastException = ex;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
14509
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   664
    /**
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   665
     * check if we are in a set UID program.
4358b75583be 6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents: 14333
diff changeset
   666
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    private static native boolean isSetUID();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
}