Add configurable log level, Add more debug logging
All checks were successful
Build and push container / Build-Docker-Container (push) Successful in 4m28s

This commit is contained in:
MrLetsplay 2025-02-22 18:43:03 +01:00
parent 9f07cecc51
commit e41e0abec8
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
3 changed files with 31 additions and 4 deletions

View File

@ -3,6 +3,7 @@ package me.mrletsplay.videobase;
import java.util.List;
import java.util.Objects;
import ch.qos.logback.classic.Level;
import me.mrletsplay.mrcore.json.JSONType;
import me.mrletsplay.mrcore.json.converter.JSONConstructor;
import me.mrletsplay.mrcore.json.converter.JSONConvertible;
@ -26,6 +27,9 @@ public class Config implements JSONConvertible {
@JSONListType(JSONType.STRING)
private List<String> includeFileTypes;
@JSONValue
private String logLevel;
@JSONConstructor
private Config() {}
@ -45,6 +49,10 @@ public class Config implements JSONConvertible {
return includeFileTypes == null ? DEFAULT_FILE_TYPES : includeFileTypes;
}
public String getLogLevel() {
return logLevel == null ? Level.INFO.toString() : logLevel;
}
public void validate() {
Objects.requireNonNull(libraryPath, "libraryPath");
}
@ -55,6 +63,7 @@ public class Config implements JSONConvertible {
config.readOnly = false;
config.cachePath = "cache";
config.includeFileTypes = DEFAULT_FILE_TYPES;
config.logLevel = Level.INFO.toString();
return config;
}

View File

@ -54,11 +54,18 @@ public class VideoBase {
System.exit(1);
}
Level logLevel = Level.toLevel(config.getLogLevel(), null);
if(logLevel == null) {
LOGGER.warn("Invalid log level '" + config.getLogLevel() + "' configured, falling back to INFO");
logLevel = Level.INFO;
}
LOGGER.info("Using log level " + logLevel);
((ch.qos.logback.classic.Logger) LOGGER).setLevel(logLevel);
loadLibrary();
executor.scheduleWithFixedDelay(VideoBase::loadLibrary, 10, 10, TimeUnit.MINUTES);
((ch.qos.logback.classic.Logger) LOGGER).setLevel(Level.INFO);
HttpServer server = new HttpServer(HttpServer.newConfigurationBuilder()
.hostBindAll()
.port(6969)
@ -72,6 +79,7 @@ public class VideoBase {
new LibraryAPI().register(server.getDocumentProvider());
server.start();
LOGGER.info("Server is running");
}
public static Config getConfig() {
@ -83,9 +91,12 @@ public class VideoBase {
}
private static void loadLibrary() {
library = Library.load(Path.of(config.getLibraryPath()), config.isReadOnly());
Path libraryPath = Path.of(config.getLibraryPath());
LOGGER.debug("Loading library from path: " + libraryPath);
library = Library.load(libraryPath, config.isReadOnly());
ThumbnailCreator.clearCache();
ThumbnailCreator.createThumbnails();
LOGGER.debug("Loaded " + library.getVideos().size() + " videos");
}
}

View File

@ -112,7 +112,14 @@ public class Library {
}
private static void load(Path rootPath, Path path, List<Video> videos, VideoMetadata parentDefaultMetadata) {
if(!Files.isDirectory(path)) return;
if(!Files.isDirectory(path)) {
if(path.equals(rootPath)) {
VideoBase.LOGGER.warn("Ignoring root path: Not a directory");
}
return;
}
if(Files.isRegularFile(path.resolve(".nomedia"))) {
VideoBase.LOGGER.debug("Ignoring folder at " + path + ": .nomedia file exists");
return;