author | dfuchs |
Thu, 06 Apr 2017 14:38:15 +0100 | |
changeset 44538 | a603c475d649 |
parent 39307 | 35eab41d2df1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23010
6dadb192ad81
8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents:
22951
diff
changeset
|
2 |
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package java.util.logging; |
|
27 |
||
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
28 |
import static java.nio.file.StandardOpenOption.APPEND; |
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
29 |
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
|
30 |
import static java.nio.file.StandardOpenOption.WRITE; |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
31 |
|
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
32 |
import java.io.BufferedOutputStream; |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
33 |
import java.io.File; |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
34 |
import java.io.FileOutputStream; |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
35 |
import java.io.IOException; |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
36 |
import java.io.OutputStream; |
2 | 37 |
import java.nio.channels.FileChannel; |
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
38 |
import java.nio.channels.OverlappingFileLockException; |
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
39 |
import java.nio.file.FileAlreadyExistsException; |
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
40 |
import java.nio.file.Files; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
41 |
import java.nio.file.LinkOption; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
42 |
import java.nio.file.NoSuchFileException; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
43 |
import java.nio.file.Path; |
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
44 |
import java.nio.file.Paths; |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
45 |
import java.security.AccessController; |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
46 |
import java.security.PrivilegedAction; |
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
47 |
import java.util.HashSet; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
48 |
import java.util.Set; |
2 | 49 |
|
50 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
51 |
* Simple file logging {@code Handler}. |
2 | 52 |
* <p> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
53 |
* The {@code FileHandler} can either write to a specified file, |
2 | 54 |
* or it can write to a rotating set of files. |
55 |
* <p> |
|
56 |
* For a rotating set of files, as each file reaches a given size |
|
57 |
* limit, it is closed, rotated out, and a new file opened. |
|
58 |
* Successively older files are named by adding "0", "1", "2", |
|
3853 | 59 |
* etc. into the base filename. |
2 | 60 |
* <p> |
61 |
* By default buffering is enabled in the IO libraries but each log |
|
62 |
* record is flushed out when it is complete. |
|
63 |
* <p> |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
64 |
* By default the {@code XMLFormatter} class is used for formatting. |
2 | 65 |
* <p> |
66 |
* <b>Configuration:</b> |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
67 |
* By default each {@code FileHandler} is initialized using the following |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
68 |
* {@code LogManager} configuration properties where {@code <handler-name>} |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
69 |
* refers to the fully-qualified class name of the handler. |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
70 |
* If properties are not defined |
2 | 71 |
* (or have invalid values) then the specified default values are used. |
72 |
* <ul> |
|
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
73 |
* <li> <handler-name>.level |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
74 |
* specifies the default level for the {@code Handler} |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
75 |
* (defaults to {@code Level.ALL}). </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
76 |
* <li> <handler-name>.filter |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
77 |
* specifies the name of a {@code Filter} class to use |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
78 |
* (defaults to no {@code Filter}). </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
79 |
* <li> <handler-name>.formatter |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
80 |
* specifies the name of a {@code Formatter} class to use |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
81 |
* (defaults to {@code java.util.logging.XMLFormatter}) </li> |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
82 |
* <li> <handler-name>.encoding |
2 | 83 |
* the name of the character set encoding to use (defaults to |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
84 |
* the default platform encoding). </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
85 |
* <li> <handler-name>.limit |
2 | 86 |
* specifies an approximate maximum amount to write (in bytes) |
87 |
* 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
|
88 |
* (Defaults to no limit). </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
89 |
* <li> <handler-name>.count |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
90 |
* specifies how many output files to cycle through (defaults to 1). </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
91 |
* <li> <handler-name>.pattern |
2 | 92 |
* specifies a pattern for generating the output file name. See |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
93 |
* below for details. (Defaults to "%h/java%u.log"). </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
94 |
* <li> <handler-name>.append |
2 | 95 |
* specifies whether the FileHandler should append onto |
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
96 |
* any existing files (defaults to false). </li> |
39307
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
97 |
* <li> <handler-name>.maxLocks |
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
98 |
* specifies the maximum number of concurrent locks held by |
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
99 |
* FileHandler (defaults to 100). </li> |
2 | 100 |
* </ul> |
101 |
* <p> |
|
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
102 |
* For example, the properties for {@code FileHandler} would be: |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
103 |
* <ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
104 |
* <li> java.util.logging.FileHandler.level=INFO </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
105 |
* <li> java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
106 |
* </ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
107 |
* <p> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
108 |
* For a custom handler, e.g. com.foo.MyHandler, the properties would be: |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
109 |
* <ul> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
110 |
* <li> com.foo.MyHandler.level=INFO </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
111 |
* <li> com.foo.MyHandler.formatter=java.util.logging.SimpleFormatter </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
112 |
* </ul> |
2 | 113 |
* <p> |
114 |
* A pattern consists of a string that includes the following special |
|
115 |
* components that will be replaced at runtime: |
|
116 |
* <ul> |
|
14321
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
117 |
* <li> "/" the local pathname separator </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
118 |
* <li> "%t" the system temporary directory </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
119 |
* <li> "%h" the value of the "user.home" system property </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
120 |
* <li> "%g" the generation number to distinguish rotated logs </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
121 |
* <li> "%u" a unique number to resolve conflicts </li> |
7f9f265ac11e
7159567: inconsistent configuration of MemoryHandler
jgish
parents:
9275
diff
changeset
|
122 |
* <li> "%%" translates to a single percent sign "%" </li> |
2 | 123 |
* </ul> |
124 |
* If no "%g" field has been specified and the file count is greater |
|
125 |
* than one, then the generation number will be added to the end of |
|
126 |
* the generated filename, after a dot. |
|
127 |
* <p> |
|
128 |
* Thus for example a pattern of "%t/java%g.log" with a count of 2 |
|
129 |
* would typically cause log files to be written on Solaris to |
|
130 |
* /var/tmp/java0.log and /var/tmp/java1.log whereas on Windows 95 they |
|
131 |
* would be typically written to C:\TEMP\java0.log and C:\TEMP\java1.log |
|
132 |
* <p> |
|
133 |
* Generation numbers follow the sequence 0, 1, 2, etc. |
|
134 |
* <p> |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
135 |
* Normally the "%u" unique field is set to 0. However, if the {@code FileHandler} |
2 | 136 |
* tries to open the filename and finds the file is currently in use by |
137 |
* another process it will increment the unique number field and try |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
138 |
* again. This will be repeated until {@code FileHandler} finds a file name that |
2 | 139 |
* is not currently in use. If there is a conflict and no "%u" field has |
140 |
* been specified, it will be added at the end of the filename after a dot. |
|
141 |
* (This will be after any automatically added generation number.) |
|
142 |
* <p> |
|
143 |
* Thus if three processes were all trying to log to fred%u.%g.txt then |
|
144 |
* they might end up using fred0.0.txt, fred1.0.txt, fred2.0.txt as |
|
145 |
* the first file in their rotating sequences. |
|
146 |
* <p> |
|
147 |
* Note that the use of unique ids to avoid conflicts is only guaranteed |
|
148 |
* to work reliably when using a local disk file system. |
|
149 |
* |
|
150 |
* @since 1.4 |
|
151 |
*/ |
|
152 |
||
153 |
public class FileHandler extends StreamHandler { |
|
154 |
private MeteredStream meter; |
|
155 |
private boolean append; |
|
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
156 |
private long limit; // zero => no limit. |
2 | 157 |
private int count; |
158 |
private String pattern; |
|
159 |
private String lockFileName; |
|
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
160 |
private FileChannel lockFileChannel; |
2 | 161 |
private File files[]; |
162 |
private static final int MAX_LOCKS = 100; |
|
39307
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
163 |
private int maxLocks = MAX_LOCKS; |
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
164 |
private static final Set<String> locks = new HashSet<>(); |
2 | 165 |
|
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
166 |
/** |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
167 |
* 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
|
168 |
* (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
|
169 |
* (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
|
170 |
*/ |
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
171 |
private static final class MeteredStream extends OutputStream { |
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
172 |
final OutputStream out; |
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
173 |
long written; |
2 | 174 |
|
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
175 |
MeteredStream(OutputStream out, long written) { |
2 | 176 |
this.out = out; |
177 |
this.written = written; |
|
178 |
} |
|
179 |
||
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
180 |
@Override |
2 | 181 |
public void write(int b) throws IOException { |
182 |
out.write(b); |
|
183 |
written++; |
|
184 |
} |
|
185 |
||
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
186 |
@Override |
2 | 187 |
public void write(byte buff[]) throws IOException { |
188 |
out.write(buff); |
|
189 |
written += buff.length; |
|
190 |
} |
|
191 |
||
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
192 |
@Override |
2 | 193 |
public void write(byte buff[], int off, int len) throws IOException { |
194 |
out.write(buff,off,len); |
|
195 |
written += len; |
|
196 |
} |
|
197 |
||
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
198 |
@Override |
2 | 199 |
public void flush() throws IOException { |
200 |
out.flush(); |
|
201 |
} |
|
202 |
||
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
203 |
@Override |
2 | 204 |
public void close() throws IOException { |
205 |
out.close(); |
|
206 |
} |
|
207 |
} |
|
208 |
||
209 |
private void open(File fname, boolean append) throws IOException { |
|
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
210 |
long len = 0; |
2 | 211 |
if (append) { |
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
212 |
len = fname.length(); |
2 | 213 |
} |
214 |
FileOutputStream fout = new FileOutputStream(fname.toString(), append); |
|
215 |
BufferedOutputStream bout = new BufferedOutputStream(fout); |
|
216 |
meter = new MeteredStream(bout, len); |
|
217 |
setOutputStream(meter); |
|
218 |
} |
|
219 |
||
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
220 |
/** |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
221 |
* 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
|
222 |
* as specified in the class javadoc. |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
223 |
*/ |
2 | 224 |
private void configure() { |
225 |
LogManager manager = LogManager.getLogManager(); |
|
226 |
||
227 |
String cname = getClass().getName(); |
|
228 |
||
229 |
pattern = manager.getStringProperty(cname + ".pattern", "%h/java%u.log"); |
|
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
230 |
limit = manager.getLongProperty(cname + ".limit", 0); |
2 | 231 |
if (limit < 0) { |
232 |
limit = 0; |
|
233 |
} |
|
234 |
count = manager.getIntProperty(cname + ".count", 1); |
|
235 |
if (count <= 0) { |
|
236 |
count = 1; |
|
237 |
} |
|
238 |
append = manager.getBooleanProperty(cname + ".append", false); |
|
239 |
setLevel(manager.getLevelProperty(cname + ".level", Level.ALL)); |
|
240 |
setFilter(manager.getFilterProperty(cname + ".filter", null)); |
|
241 |
setFormatter(manager.getFormatterProperty(cname + ".formatter", new XMLFormatter())); |
|
39307
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
242 |
// Initialize maxLocks from the logging.properties file. |
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
243 |
// If invalid/no property is provided 100 will be used as a default value. |
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
244 |
maxLocks = manager.getIntProperty(cname + ".maxLocks", MAX_LOCKS); |
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
245 |
if(maxLocks <= 0) { |
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
246 |
maxLocks = MAX_LOCKS; |
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
247 |
} |
2 | 248 |
try { |
249 |
setEncoding(manager.getStringProperty(cname +".encoding", null)); |
|
250 |
} catch (Exception ex) { |
|
251 |
try { |
|
252 |
setEncoding(null); |
|
253 |
} catch (Exception ex2) { |
|
254 |
// doing a setEncoding with null should always work. |
|
255 |
// assert false; |
|
256 |
} |
|
257 |
} |
|
258 |
} |
|
259 |
||
260 |
||
261 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
262 |
* Construct a default {@code FileHandler}. This will be configured |
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
263 |
* entirely from {@code LogManager} properties (or their default values). |
24196
61c9885d76e2
8029451: Tidy warnings cleanup for java.util package; minor changes in java.nio, java.sql
yan
parents:
23010
diff
changeset
|
264 |
* |
2 | 265 |
* @exception IOException if there are IO problems opening the files. |
266 |
* @exception SecurityException if a security manager exists and if |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
267 |
* the caller does not have {@code LoggingPermission("control"))}. |
2 | 268 |
* @exception NullPointerException if pattern property is an empty String. |
269 |
*/ |
|
270 |
public FileHandler() throws IOException, SecurityException { |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
9275
diff
changeset
|
271 |
checkPermission(); |
2 | 272 |
configure(); |
26874
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
273 |
// pattern will have been set by configure. check that it's not |
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
274 |
// empty. |
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
275 |
if (pattern.isEmpty()) { |
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
276 |
throw new NullPointerException(); |
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
277 |
} |
2 | 278 |
openFiles(); |
279 |
} |
|
280 |
||
281 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
282 |
* Initialize a {@code FileHandler} to write to the given filename. |
2 | 283 |
* <p> |
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
284 |
* The {@code FileHandler} is configured based on {@code LogManager} |
2 | 285 |
* properties (or their default values) except that the given pattern |
286 |
* argument is used as the filename pattern, the file limit is |
|
287 |
* set to no limit, and the file count is set to one. |
|
288 |
* <p> |
|
289 |
* There is no limit on the amount of data that may be written, |
|
290 |
* so use this with care. |
|
291 |
* |
|
292 |
* @param pattern the name of the output file |
|
293 |
* @exception IOException if there are IO problems opening the files. |
|
294 |
* @exception SecurityException if a security manager exists and if |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
295 |
* the caller does not have {@code LoggingPermission("control")}. |
2 | 296 |
* @exception IllegalArgumentException if pattern is an empty string |
297 |
*/ |
|
298 |
public FileHandler(String pattern) throws IOException, SecurityException { |
|
299 |
if (pattern.length() < 1 ) { |
|
300 |
throw new IllegalArgumentException(); |
|
301 |
} |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
9275
diff
changeset
|
302 |
checkPermission(); |
2 | 303 |
configure(); |
304 |
this.pattern = pattern; |
|
305 |
this.limit = 0; |
|
306 |
this.count = 1; |
|
307 |
openFiles(); |
|
308 |
} |
|
309 |
||
310 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
311 |
* Initialize a {@code FileHandler} to write to the given filename, |
2 | 312 |
* with optional append. |
313 |
* <p> |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
314 |
* The {@code FileHandler} is configured based on {@code LogManager} |
2 | 315 |
* properties (or their default values) except that the given pattern |
316 |
* argument is used as the filename pattern, the file limit is |
|
317 |
* set to no limit, the file count is set to one, and the append |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
318 |
* mode is set to the given {@code append} argument. |
2 | 319 |
* <p> |
320 |
* There is no limit on the amount of data that may be written, |
|
321 |
* so use this with care. |
|
322 |
* |
|
323 |
* @param pattern the name of the output file |
|
324 |
* @param append specifies append mode |
|
325 |
* @exception IOException if there are IO problems opening the files. |
|
326 |
* @exception SecurityException if a security manager exists and if |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
327 |
* the caller does not have {@code LoggingPermission("control")}. |
2 | 328 |
* @exception IllegalArgumentException if pattern is an empty string |
329 |
*/ |
|
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
330 |
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
|
331 |
SecurityException { |
2 | 332 |
if (pattern.length() < 1 ) { |
333 |
throw new IllegalArgumentException(); |
|
334 |
} |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
9275
diff
changeset
|
335 |
checkPermission(); |
2 | 336 |
configure(); |
337 |
this.pattern = pattern; |
|
338 |
this.limit = 0; |
|
339 |
this.count = 1; |
|
340 |
this.append = append; |
|
341 |
openFiles(); |
|
342 |
} |
|
343 |
||
344 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
345 |
* Initialize a {@code FileHandler} to write to a set of files. When |
2 | 346 |
* (approximately) the given limit has been written to one file, |
347 |
* another file will be opened. The output will cycle through a set |
|
348 |
* of count files. |
|
349 |
* <p> |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
350 |
* The {@code FileHandler} is configured based on {@code LogManager} |
2 | 351 |
* properties (or their default values) except that the given pattern |
352 |
* argument is used as the filename pattern, the file limit is |
|
353 |
* set to the limit argument, and the file count is set to the |
|
354 |
* given count argument. |
|
355 |
* <p> |
|
356 |
* The count must be at least 1. |
|
357 |
* |
|
358 |
* @param pattern the pattern for naming the output file |
|
359 |
* @param limit the maximum number of bytes to write to any one file |
|
360 |
* @param count the number of files to use |
|
361 |
* @exception IOException if there are IO problems opening the files. |
|
362 |
* @exception SecurityException if a security manager exists and if |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
363 |
* the caller does not have {@code LoggingPermission("control")}. |
18156 | 364 |
* @exception IllegalArgumentException if {@code limit < 0}, or {@code count < 1}. |
2 | 365 |
* @exception IllegalArgumentException if pattern is an empty string |
366 |
*/ |
|
367 |
public FileHandler(String pattern, int limit, int count) |
|
368 |
throws IOException, SecurityException { |
|
369 |
if (limit < 0 || count < 1 || pattern.length() < 1) { |
|
370 |
throw new IllegalArgumentException(); |
|
371 |
} |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
9275
diff
changeset
|
372 |
checkPermission(); |
2 | 373 |
configure(); |
374 |
this.pattern = pattern; |
|
375 |
this.limit = limit; |
|
376 |
this.count = count; |
|
377 |
openFiles(); |
|
378 |
} |
|
379 |
||
380 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
381 |
* Initialize a {@code FileHandler} to write to a set of files |
2 | 382 |
* with optional append. When (approximately) the given limit has |
383 |
* been written to one file, another file will be opened. The |
|
384 |
* output will cycle through a set of count files. |
|
385 |
* <p> |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
386 |
* The {@code FileHandler} is configured based on {@code LogManager} |
2 | 387 |
* properties (or their default values) except that the given pattern |
388 |
* argument is used as the filename pattern, the file limit is |
|
389 |
* set to the limit argument, and the file count is set to the |
|
390 |
* given count argument, and the append mode is set to the given |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
391 |
* {@code append} argument. |
2 | 392 |
* <p> |
393 |
* The count must be at least 1. |
|
394 |
* |
|
395 |
* @param pattern the pattern for naming the output file |
|
396 |
* @param limit the maximum number of bytes to write to any one file |
|
397 |
* @param count the number of files to use |
|
398 |
* @param append specifies append mode |
|
399 |
* @exception IOException if there are IO problems opening the files. |
|
400 |
* @exception SecurityException if a security manager exists and if |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
401 |
* the caller does not have {@code LoggingPermission("control")}. |
18156 | 402 |
* @exception IllegalArgumentException if {@code limit < 0}, or {@code count < 1}. |
2 | 403 |
* @exception IllegalArgumentException if pattern is an empty string |
404 |
* |
|
405 |
*/ |
|
406 |
public FileHandler(String pattern, int limit, int count, boolean append) |
|
407 |
throws IOException, SecurityException { |
|
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
408 |
this(pattern, (long)limit, count, append); |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
409 |
} |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
410 |
|
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
411 |
/** |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
412 |
* Initialize a {@code FileHandler} to write to a set of files |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
413 |
* with optional append. When (approximately) the given limit has |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
414 |
* been written to one file, another file will be opened. The |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
415 |
* output will cycle through a set of count files. |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
416 |
* <p> |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
417 |
* The {@code FileHandler} is configured based on {@code LogManager} |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
418 |
* properties (or their default values) except that the given pattern |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
419 |
* argument is used as the filename pattern, the file limit is |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
420 |
* set to the limit argument, and the file count is set to the |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
421 |
* given count argument, and the append mode is set to the given |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
422 |
* {@code append} argument. |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
423 |
* <p> |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
424 |
* The count must be at least 1. |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
425 |
* |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
426 |
* @param pattern the pattern for naming the output file |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
427 |
* @param limit the maximum number of bytes to write to any one file |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
428 |
* @param count the number of files to use |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
429 |
* @param append specifies append mode |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
430 |
* @exception IOException if there are IO problems opening the files. |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
431 |
* @exception SecurityException if a security manager exists and if |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
432 |
* the caller does not have {@code LoggingPermission("control")}. |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
433 |
* @exception IllegalArgumentException if {@code limit < 0}, or {@code count < 1}. |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
434 |
* @exception IllegalArgumentException if pattern is an empty string |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
435 |
* |
35302
e4d2275861c3
8136494: Update "@since 1.9" to "@since 9" to match java.version.specification
iris
parents:
34882
diff
changeset
|
436 |
* @since 9 |
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
437 |
* |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
438 |
*/ |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
439 |
public FileHandler(String pattern, long limit, int count, boolean append) |
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
440 |
throws IOException { |
2 | 441 |
if (limit < 0 || count < 1 || pattern.length() < 1) { |
442 |
throw new IllegalArgumentException(); |
|
443 |
} |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
9275
diff
changeset
|
444 |
checkPermission(); |
2 | 445 |
configure(); |
446 |
this.pattern = pattern; |
|
447 |
this.limit = limit; |
|
448 |
this.count = count; |
|
449 |
this.append = append; |
|
450 |
openFiles(); |
|
451 |
} |
|
452 |
||
26864
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
453 |
private boolean isParentWritable(Path path) { |
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
454 |
Path parent = path.getParent(); |
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
455 |
if (parent == null) { |
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
456 |
parent = path.toAbsolutePath().getParent(); |
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
457 |
} |
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
458 |
return parent != null && Files.isWritable(parent); |
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
459 |
} |
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
460 |
|
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
461 |
/** |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
462 |
* 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
|
463 |
* instance variables. |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
464 |
*/ |
2 | 465 |
private void openFiles() throws IOException { |
466 |
LogManager manager = LogManager.getLogManager(); |
|
14216
23714b376286
7169884: LogManager checks do not work correctly for sub-types
alanb
parents:
9275
diff
changeset
|
467 |
manager.checkPermission(); |
2 | 468 |
if (count < 1) { |
469 |
throw new IllegalArgumentException("file count = " + count); |
|
470 |
} |
|
471 |
if (limit < 0) { |
|
472 |
limit = 0; |
|
473 |
} |
|
474 |
||
26874
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
475 |
// All constructors check that pattern is neither null nor empty. |
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
476 |
assert pattern != null : "pattern should not be null"; |
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
477 |
assert !pattern.isEmpty() : "pattern should not be empty"; |
5ff3fbb88d3c
8025690: Default FileHandler constructor doesn't throw NullPointerException if pattern is empty and count > 1
dfuchs
parents:
26864
diff
changeset
|
478 |
|
2 | 479 |
// We register our own ErrorManager during initialization |
480 |
// so we can record exceptions. |
|
481 |
InitializationErrorManager em = new InitializationErrorManager(); |
|
482 |
setErrorManager(em); |
|
483 |
||
484 |
// Create a lock file. This grants us exclusive access |
|
485 |
// to our set of output files, as long as we are alive. |
|
486 |
int unique = -1; |
|
487 |
for (;;) { |
|
488 |
unique++; |
|
39307
35eab41d2df1
8153955: increase java.util.logging.FileHandler MAX_LOCKS limit
rpatil
parents:
35302
diff
changeset
|
489 |
if (unique > maxLocks) { |
2 | 490 |
throw new IOException("Couldn't get lock for " + pattern); |
491 |
} |
|
492 |
// Generate a lock file name from the "unique" int. |
|
493 |
lockFileName = generate(pattern, 0, unique).toString() + ".lck"; |
|
494 |
// Now try to lock that filename. |
|
3853 | 495 |
// Because some systems (e.g., Solaris) can only do file locks |
2 | 496 |
// between processes (and not within a process), we first check |
497 |
// if we ourself already have the file locked. |
|
498 |
synchronized(locks) { |
|
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
499 |
if (locks.contains(lockFileName)) { |
2 | 500 |
// We already own this lock, for a different FileHandler |
501 |
// object. Try again. |
|
502 |
continue; |
|
503 |
} |
|
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
504 |
|
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
505 |
final Path lockFilePath = Paths.get(lockFileName); |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
506 |
FileChannel channel = null; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
507 |
int retries = -1; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
508 |
boolean fileCreated = false; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
509 |
while (channel == null && retries++ < 1) { |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
510 |
try { |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
511 |
channel = FileChannel.open(lockFilePath, |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
512 |
CREATE_NEW, WRITE); |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
513 |
fileCreated = true; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
514 |
} catch (FileAlreadyExistsException ix) { |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
515 |
// This may be a zombie file left over by a previous |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
516 |
// execution. Reuse it - but only if we can actually |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
517 |
// write to its directory. |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
518 |
// Note that this is a situation that may happen, |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
519 |
// but not too frequently. |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
520 |
if (Files.isRegularFile(lockFilePath, LinkOption.NOFOLLOW_LINKS) |
26864
3383e655118e
8059269: FileHandler may throw NPE if pattern is a simple name and the lock file already exists
dfuchs
parents:
25859
diff
changeset
|
521 |
&& isParentWritable(lockFilePath)) { |
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
522 |
try { |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
523 |
channel = FileChannel.open(lockFilePath, |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
524 |
WRITE, APPEND); |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
525 |
} catch (NoSuchFileException x) { |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
526 |
// Race condition - retry once, and if that |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
527 |
// fails again just try the next name in |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
528 |
// the sequence. |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
529 |
continue; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
530 |
} catch(IOException x) { |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
531 |
// the file may not be writable for us. |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
532 |
// try the next name in the sequence |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
533 |
break; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
534 |
} |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
535 |
} else { |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
536 |
// at this point channel should still be null. |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
537 |
// break and try the next name in the sequence. |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
538 |
break; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
539 |
} |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
540 |
} |
2 | 541 |
} |
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
542 |
|
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
543 |
if (channel == null) continue; // try the next name; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
544 |
lockFileChannel = channel; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
545 |
|
9271
2d7e19ff03d1
7032589: FileHandler leaking file descriptor of the file lock
mchung
parents:
7803
diff
changeset
|
546 |
boolean available; |
2 | 547 |
try { |
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
548 |
available = lockFileChannel.tryLock() != null; |
2 | 549 |
// We got the lock OK. |
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
550 |
// At this point we could call File.deleteOnExit(). |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
551 |
// However, this could have undesirable side effects |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
552 |
// as indicated by JDK-4872014. So we will instead |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
553 |
// rely on the fact that close() will remove the lock |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
554 |
// file and that whoever is creating FileHandlers should |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
555 |
// be responsible for closing them. |
2 | 556 |
} catch (IOException ix) { |
557 |
// We got an IOException while trying to get the lock. |
|
558 |
// This normally indicates that locking is not supported |
|
559 |
// on the target directory. We have to proceed without |
|
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
560 |
// getting a lock. Drop through, but only if we did |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
561 |
// create the file... |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
562 |
available = fileCreated; |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
563 |
} catch (OverlappingFileLockException x) { |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
564 |
// someone already locked this file in this VM, through |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
565 |
// some other channel - that is - using something else |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
566 |
// than new FileHandler(...); |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
567 |
// continue searching for an available lock. |
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
568 |
available = false; |
2 | 569 |
} |
9271
2d7e19ff03d1
7032589: FileHandler leaking file descriptor of the file lock
mchung
parents:
7803
diff
changeset
|
570 |
if (available) { |
2d7e19ff03d1
7032589: FileHandler leaking file descriptor of the file lock
mchung
parents:
7803
diff
changeset
|
571 |
// We got the lock. Remember it. |
25389
6f994d9e1b57
8048020: Regression on java.util.logging.FileHandler
dfuchs
parents:
24196
diff
changeset
|
572 |
locks.add(lockFileName); |
9271
2d7e19ff03d1
7032589: FileHandler leaking file descriptor of the file lock
mchung
parents:
7803
diff
changeset
|
573 |
break; |
2d7e19ff03d1
7032589: FileHandler leaking file descriptor of the file lock
mchung
parents:
7803
diff
changeset
|
574 |
} |
2d7e19ff03d1
7032589: FileHandler leaking file descriptor of the file lock
mchung
parents:
7803
diff
changeset
|
575 |
|
2d7e19ff03d1
7032589: FileHandler leaking file descriptor of the file lock
mchung
parents:
7803
diff
changeset
|
576 |
// 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
|
577 |
lockFileChannel.close(); |
2 | 578 |
} |
579 |
} |
|
580 |
||
581 |
files = new File[count]; |
|
582 |
for (int i = 0; i < count; i++) { |
|
583 |
files[i] = generate(pattern, i, unique); |
|
584 |
} |
|
585 |
||
586 |
// Create the initial log file. |
|
587 |
if (append) { |
|
588 |
open(files[0], true); |
|
589 |
} else { |
|
590 |
rotate(); |
|
591 |
} |
|
592 |
||
593 |
// Did we detect any exceptions during initialization? |
|
594 |
Exception ex = em.lastException; |
|
595 |
if (ex != null) { |
|
596 |
if (ex instanceof IOException) { |
|
597 |
throw (IOException) ex; |
|
598 |
} else if (ex instanceof SecurityException) { |
|
599 |
throw (SecurityException) ex; |
|
600 |
} else { |
|
601 |
throw new IOException("Exception: " + ex); |
|
602 |
} |
|
603 |
} |
|
604 |
||
605 |
// Install the normal default ErrorManager. |
|
606 |
setErrorManager(new ErrorManager()); |
|
607 |
} |
|
608 |
||
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
609 |
/** |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
610 |
* 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
|
611 |
* and an integer uniqueness suffix |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
612 |
* @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
|
613 |
* @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
|
614 |
* @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
|
615 |
* @return the generated File |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
616 |
* @throws IOException |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
617 |
*/ |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
618 |
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
|
619 |
throws IOException { |
2 | 620 |
File file = null; |
621 |
String word = ""; |
|
622 |
int ix = 0; |
|
623 |
boolean sawg = false; |
|
624 |
boolean sawu = false; |
|
625 |
while (ix < pattern.length()) { |
|
626 |
char ch = pattern.charAt(ix); |
|
627 |
ix++; |
|
628 |
char ch2 = 0; |
|
629 |
if (ix < pattern.length()) { |
|
630 |
ch2 = Character.toLowerCase(pattern.charAt(ix)); |
|
631 |
} |
|
632 |
if (ch == '/') { |
|
633 |
if (file == null) { |
|
634 |
file = new File(word); |
|
635 |
} else { |
|
636 |
file = new File(file, word); |
|
637 |
} |
|
638 |
word = ""; |
|
639 |
continue; |
|
640 |
} else if (ch == '%') { |
|
641 |
if (ch2 == 't') { |
|
642 |
String tmpDir = System.getProperty("java.io.tmpdir"); |
|
643 |
if (tmpDir == null) { |
|
644 |
tmpDir = System.getProperty("user.home"); |
|
645 |
} |
|
646 |
file = new File(tmpDir); |
|
647 |
ix++; |
|
648 |
word = ""; |
|
649 |
continue; |
|
650 |
} else if (ch2 == 'h') { |
|
651 |
file = new File(System.getProperty("user.home")); |
|
34882 | 652 |
if (jdk.internal.misc.VM.isSetUID()) { |
2 | 653 |
// Ok, we are in a set UID program. For safety's sake |
654 |
// we disallow attempts to open files relative to %h. |
|
655 |
throw new IOException("can't use %h in set UID program"); |
|
656 |
} |
|
657 |
ix++; |
|
658 |
word = ""; |
|
659 |
continue; |
|
660 |
} else if (ch2 == 'g') { |
|
661 |
word = word + generation; |
|
662 |
sawg = true; |
|
663 |
ix++; |
|
664 |
continue; |
|
665 |
} else if (ch2 == 'u') { |
|
666 |
word = word + unique; |
|
667 |
sawu = true; |
|
668 |
ix++; |
|
669 |
continue; |
|
670 |
} else if (ch2 == '%') { |
|
671 |
word = word + "%"; |
|
672 |
ix++; |
|
673 |
continue; |
|
674 |
} |
|
675 |
} |
|
676 |
word = word + ch; |
|
677 |
} |
|
678 |
if (count > 1 && !sawg) { |
|
679 |
word = word + "." + generation; |
|
680 |
} |
|
681 |
if (unique > 0 && !sawu) { |
|
682 |
word = word + "." + unique; |
|
683 |
} |
|
684 |
if (word.length() > 0) { |
|
685 |
if (file == null) { |
|
686 |
file = new File(word); |
|
687 |
} else { |
|
688 |
file = new File(file, word); |
|
689 |
} |
|
690 |
} |
|
691 |
return file; |
|
692 |
} |
|
693 |
||
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
694 |
/** |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
695 |
* Rotate the set of output files |
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
696 |
*/ |
2 | 697 |
private synchronized void rotate() { |
698 |
Level oldLevel = getLevel(); |
|
699 |
setLevel(Level.OFF); |
|
700 |
||
701 |
super.close(); |
|
702 |
for (int i = count-2; i >= 0; i--) { |
|
703 |
File f1 = files[i]; |
|
704 |
File f2 = files[i+1]; |
|
705 |
if (f1.exists()) { |
|
706 |
if (f2.exists()) { |
|
707 |
f2.delete(); |
|
708 |
} |
|
709 |
f1.renameTo(f2); |
|
710 |
} |
|
711 |
} |
|
712 |
try { |
|
713 |
open(files[0], false); |
|
714 |
} catch (IOException ix) { |
|
715 |
// We don't want to throw an exception here, but we |
|
716 |
// report the exception to any registered ErrorManager. |
|
717 |
reportError(null, ix, ErrorManager.OPEN_FAILURE); |
|
718 |
||
719 |
} |
|
720 |
setLevel(oldLevel); |
|
721 |
} |
|
722 |
||
723 |
/** |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
724 |
* Format and publish a {@code LogRecord}. |
2 | 725 |
* |
726 |
* @param record description of the log event. A null record is |
|
727 |
* silently ignored and is not published |
|
728 |
*/ |
|
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
729 |
@Override |
2 | 730 |
public synchronized void publish(LogRecord record) { |
731 |
if (!isLoggable(record)) { |
|
732 |
return; |
|
733 |
} |
|
734 |
super.publish(record); |
|
735 |
flush(); |
|
27191
45a3002de56f
8059767: FileHandler should allow 'long' limits and handle overflow of MeteredStream.written.
dfuchs
parents:
26874
diff
changeset
|
736 |
if (limit > 0 && (meter.written >= limit || meter.written < 0)) { |
2 | 737 |
// We performed access checks in the "init" method to make sure |
738 |
// we are only initialized from trusted code. So we assume |
|
739 |
// it is OK to write the target files, even if we are |
|
740 |
// currently being called from untrusted code. |
|
741 |
// So it is safe to raise privilege here. |
|
742 |
AccessController.doPrivileged(new PrivilegedAction<Object>() { |
|
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
743 |
@Override |
2 | 744 |
public Object run() { |
745 |
rotate(); |
|
746 |
return null; |
|
747 |
} |
|
748 |
}); |
|
749 |
} |
|
750 |
} |
|
751 |
||
752 |
/** |
|
753 |
* Close all the files. |
|
754 |
* |
|
755 |
* @exception SecurityException if a security manager exists and if |
|
32037
ab4526f4ac10
8133115: docs: replace <tt> tags (obsolete in html5) for java.util.logging, java.util.prefs, java.util.zip, java.util.jar
avstepan
parents:
27191
diff
changeset
|
756 |
* the caller does not have {@code LoggingPermission("control")}. |
2 | 757 |
*/ |
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
758 |
@Override |
2 | 759 |
public synchronized void close() throws SecurityException { |
760 |
super.close(); |
|
761 |
// Unlock any lock file. |
|
762 |
if (lockFileName == null) { |
|
763 |
return; |
|
764 |
} |
|
765 |
try { |
|
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
766 |
// 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
|
767 |
lockFileChannel.close(); |
2 | 768 |
} catch (Exception ex) { |
769 |
// Problems closing the stream. Punt. |
|
770 |
} |
|
771 |
synchronized(locks) { |
|
772 |
locks.remove(lockFileName); |
|
773 |
} |
|
774 |
new File(lockFileName).delete(); |
|
775 |
lockFileName = null; |
|
14509
4358b75583be
6244047: impossible to specify directories to logging FileHandler unless they exist
jgish
parents:
14333
diff
changeset
|
776 |
lockFileChannel = null; |
2 | 777 |
} |
778 |
||
779 |
private static class InitializationErrorManager extends ErrorManager { |
|
780 |
Exception lastException; |
|
19808
39cb79123ab2
6823527: java.util.logging.Handler has thread safety issues
dfuchs
parents:
18156
diff
changeset
|
781 |
@Override |
2 | 782 |
public void error(String msg, Exception ex, int code) { |
783 |
lastException = ex; |
|
784 |
} |
|
785 |
} |
|
786 |
} |