Skip to content

Commit ce55d0b

Browse files
committed
Fix logger issues in AsyncWriter
1 parent cb2922d commit ce55d0b

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/main/java/net/modfest/fireblanket/util/AsyncWriter.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
* @author Ampflower
3232
**/
3333
public final class AsyncWriter extends Writer implements Thread.UncaughtExceptionHandler {
34-
private static final Logger logger = LogUtils.getLogger();
34+
private static final Logger LOGGER = LogUtils.getLogger();
3535

3636
private static final VarHandle exception;
3737
private static final IOException closedSentinel = new IOException("closed");
@@ -46,7 +46,7 @@ public final class AsyncWriter extends Writer implements Thread.UncaughtExceptio
4646
final MethodHandles.Lookup lookup = MethodHandles.lookup();
4747
exception = lookup.findVarHandle(AsyncWriter.class, "$exception", IOException.class);
4848
} catch (ReflectiveOperationException e) {
49-
logger.error("Cannot load VarHandles", e);
49+
LOGGER.error("Cannot load VarHandles", e);
5050
throw new LinkageError("Cannot load VarHandles", e);
5151
}
5252

@@ -97,7 +97,7 @@ public static AsyncWriter bufferedWriter(final Path path) throws IOException {
9797
}
9898

9999
if (!Files.isWritable(path)) {
100-
throw new IOException("unwritable: " + path);
100+
throw new IOException("Unable to write to " + path);
101101
}
102102

103103
return new AsyncWriter(() -> Files.newBufferedWriter(
@@ -252,7 +252,7 @@ private void stop(final PrintStream err) throws Throwable {
252252
@Override
253253
public void uncaughtException(final Thread t, final Throwable e) {
254254
if (this.thread != t) {
255-
logger.warn("We don't own {}, but it threw an exception; please don't use {} for arbitrary threads", t, this, e);
255+
LOGGER.warn("We don't own {}, but it threw an exception; please don't use {} for arbitrary threads", t, this, e);
256256
return;
257257
}
258258

@@ -270,11 +270,11 @@ public void uncaughtException(final Thread t, final Throwable e) {
270270
witness.addSuppressed(toSet);
271271
}
272272

273-
logger.error("{} of {} threw an uncaught exception", t, this, e);
273+
LOGGER.error("{} of {} threw an uncaught exception", t, this, e);
274274

275275
Message message;
276276
while ((message = this.messages.poll()) != null) {
277-
logger.error("Unfinished write: {}", message);
277+
LOGGER.error("Unfinished write: {}", message);
278278
}
279279

280280
knownWriters.remove(this);
@@ -313,11 +313,11 @@ public void run() {
313313
// We frankly don't care if we get interrupted.
314314
// This only exists to prevent loops from weird implementations.
315315
if (Thread.interrupted()) {
316-
logger.trace("Why did you wake me up?");
316+
LOGGER.trace("Why did you wake me up?");
317317
}
318318
}
319319

320-
logger.info("Exited.");
320+
LOGGER.trace("{} exited normally", this);
321321
knownWriters.remove(AsyncWriter.this);
322322
}
323323

@@ -368,7 +368,7 @@ private boolean processMessages() throws IOException {
368368

369369
if (message.request() == Request.CLOSE) {
370370
if (!messages.isEmpty()) {
371-
logger.warn("Unwritten messages: {}", message);
371+
LOGGER.warn("Unwritten messages: {}", message);
372372
}
373373
return true;
374374
}
@@ -422,7 +422,7 @@ private boolean processMessages() throws IOException {
422422
}
423423

424424
if (io != null) {
425-
logger.warn("{} from {} threw an exception", writer, this, io);
425+
LOGGER.warn("{} from {} threw an exception", writer, this, io);
426426
}
427427

428428
return false;
@@ -434,14 +434,12 @@ private enum Request {
434434
@Override
435435
void action(final Writer writer) throws IOException {
436436
// no-op
437-
logger.info("WRITE {}", writer);
438437
}
439438
},
440439
FLUSH {
441440
@Override
442441
void action(final Writer writer) throws IOException {
443442
writer.flush();
444-
logger.info("FLUSH {}", writer);
445443
}
446444
},
447445
CLOSE {
@@ -451,7 +449,6 @@ void action(final Writer writer) throws IOException {
451449
try (writer) {
452450
writer.flush();
453451
}
454-
logger.info("CLOSE {}", writer);
455452
}
456453
},
457454
;

0 commit comments

Comments
 (0)