Skip to content

Commit

Permalink
Import Files, add IgnoreJRERequirement add internal log on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
pabl0rg committed Jun 15, 2020
1 parent 40d8d85 commit 2911616
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion tinylog-impl/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@
<groupId>org.tinylog</groupId>
<artifactId>tinylog-api</artifactId>
</dependency>
</dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-annotations</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>

<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement;
import org.tinylog.Level;
import org.tinylog.configuration.ServiceLoader;
import org.tinylog.core.LogEntry;
Expand Down Expand Up @@ -103,11 +105,12 @@ public RollingFileWriter(final Map<String, String> properties) throws FileNotFou
writer = createByteArrayWriterAndLinkLatest(fileName, append, buffered, false, false);
}

@IgnoreJRERequirement
private static List<File> filterOutSymlinks(final List<File> files) {
if (!RuntimeProvider.isAndroid()) {
List<File> symlinks = new ArrayList<File>();
for (File file : files) {
if (java.nio.file.Files.isSymbolicLink(file.toPath())) {
if (Files.isSymbolicLink(file.toPath())) {
symlinks.add(file);
}
}
Expand All @@ -116,20 +119,23 @@ private static List<File> filterOutSymlinks(final List<File> files) {
return files;
}

@IgnoreJRERequirement
private ByteArrayWriter createByteArrayWriterAndLinkLatest(final String fileName, final boolean append, final boolean buffered,
final boolean threadSafe, final boolean shared) throws FileNotFoundException {
ByteArrayWriter writer = AbstractFormatPatternWriter.createByteArrayWriter(fileName, append, buffered, threadSafe, shared);
ByteArrayWriter writer = createByteArrayWriter(fileName, append, buffered, threadSafe, shared);
if (linkToLatest != null) {
File logFile = new File(fileName);
File linkFile = new File(linkToLatest.resolve());
if (!RuntimeProvider.isAndroid()) {
try {
Path linkPath = linkFile.toPath();
java.nio.file.Files.delete(linkPath);
java.nio.file.Files.createSymbolicLink(linkPath, logFile.toPath());
Files.delete(linkPath);
Files.createSymbolicLink(linkPath, logFile.toPath());
} catch (IOException exception) {
InternalLogger.log(Level.ERROR, exception, "Failed to create symlink '" + linkFile + "'");
}
} else {
InternalLogger.log(Level.WARN, "Cannot create symlink to latest log segment on Android");
}
}
return writer;
Expand Down

0 comments on commit 2911616

Please sign in to comment.