Simplify logging output
This commit is contained in:
parent
eb7e393ddb
commit
83c1796cf9
|
@ -1,6 +1,7 @@
|
||||||
package net.filebot;
|
package net.filebot;
|
||||||
|
|
||||||
import static java.nio.channels.Channels.*;
|
import static java.nio.channels.Channels.*;
|
||||||
|
import static java.util.Arrays.*;
|
||||||
import static java.util.stream.Collectors.*;
|
import static java.util.stream.Collectors.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -22,7 +23,6 @@ import java.util.logging.SimpleFormatter;
|
||||||
import java.util.logging.StreamHandler;
|
import java.util.logging.StreamHandler;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Stream;
|
|
||||||
|
|
||||||
import org.codehaus.groovy.runtime.StackTraceUtils;
|
import org.codehaus.groovy.runtime.StackTraceUtils;
|
||||||
|
|
||||||
|
@ -107,6 +107,10 @@ public final class Logging {
|
||||||
return () -> getMessage(null, t);
|
return () -> getMessage(null, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Supplier<String> cause(Object... elements) {
|
||||||
|
return () -> getMessage(elements);
|
||||||
|
}
|
||||||
|
|
||||||
private static String getMessage(String m, Throwable t) {
|
private static String getMessage(String m, Throwable t) {
|
||||||
// try to unravel stacked exceptions
|
// try to unravel stacked exceptions
|
||||||
if (t instanceof RuntimeException && t.getCause() != null) {
|
if (t instanceof RuntimeException && t.getCause() != null) {
|
||||||
|
@ -114,7 +118,11 @@ public final class Logging {
|
||||||
}
|
}
|
||||||
|
|
||||||
// e.g. Failed to create file: AccessDeniedException: /path/to/file
|
// e.g. Failed to create file: AccessDeniedException: /path/to/file
|
||||||
return Stream.of(m, t.getClass().getSimpleName(), t.getMessage()).filter(Objects::nonNull).map(Objects::toString).collect(joining(": "));
|
return getMessage(m, t.getClass().getSimpleName(), t.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getMessage(Object... elements) {
|
||||||
|
return stream(elements).filter(Objects::nonNull).map(Objects::toString).collect(joining(": "));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ConsoleFormatter extends Formatter {
|
public static class ConsoleFormatter extends Formatter {
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.NoSuchFileException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.attribute.UserDefinedFileAttributeView;
|
import java.nio.file.attribute.UserDefinedFileAttributeView;
|
||||||
import java.util.AbstractMap;
|
import java.util.AbstractMap;
|
||||||
|
@ -48,15 +49,15 @@ public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
try {
|
try {
|
||||||
if (xattr instanceof UserDefinedFileAttributeView) {
|
if (xattr instanceof UserDefinedFileAttributeView) {
|
||||||
UserDefinedFileAttributeView attributeView = (UserDefinedFileAttributeView) xattr;
|
UserDefinedFileAttributeView attributeView = (UserDefinedFileAttributeView) xattr;
|
||||||
int size = attributeView.size(key);
|
try {
|
||||||
if (size > 0) {
|
ByteBuffer buffer = ByteBuffer.allocate(attributeView.size(key));
|
||||||
ByteBuffer buffer = ByteBuffer.allocate(size);
|
|
||||||
attributeView.read(key, buffer);
|
attributeView.read(key, buffer);
|
||||||
buffer.flip();
|
buffer.flip();
|
||||||
|
|
||||||
return UTF_8.decode(buffer).toString();
|
return UTF_8.decode(buffer).toString();
|
||||||
} else {
|
} catch (NoSuchFileException e) {
|
||||||
return null; // attribute does not exist
|
// attribute does not exist
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ public class MetaAttributes {
|
||||||
public long getCreationDate(long time) {
|
public long getCreationDate(long time) {
|
||||||
try {
|
try {
|
||||||
return fileAttributeView.readAttributes().creationTime().toMillis();
|
return fileAttributeView.readAttributes().creationTime().toMillis();
|
||||||
} catch (Exception e) {
|
} catch (IOException e) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -59,21 +59,13 @@ public class MetaAttributes {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setObject(Object object) {
|
public void setObject(Object object) {
|
||||||
try {
|
metaAttributeView.put(METADATA_KEY, toJson(object));
|
||||||
metaAttributeView.put(METADATA_KEY, toJson(object));
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getObject() {
|
public Object getObject() {
|
||||||
try {
|
String json = metaAttributeView.get(METADATA_KEY);
|
||||||
String json = metaAttributeView.get(METADATA_KEY);
|
if (json != null && json.length() > 0) {
|
||||||
if (json != null && json.length() > 0) {
|
return toObject(json);
|
||||||
return toObject(json);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,9 +78,9 @@ public class XattrMetaInfo {
|
||||||
// make file writable if necessary
|
// make file writable if necessary
|
||||||
if (!f.canWrite()) {
|
if (!f.canWrite()) {
|
||||||
if (f.setWritable(true)) {
|
if (f.setWritable(true)) {
|
||||||
debug.finest("Grant write permissions: " + f);
|
debug.fine(cause("Grant write permissions", f));
|
||||||
} else {
|
} else {
|
||||||
debug.warning("Failed to grant write permissions: " + f);
|
debug.warning(cause("Failed to grant write permissions", f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return f;
|
return f;
|
||||||
|
|
Loading…
Reference in New Issue